NeoMutt  2025-12-11-911-gd8d604
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
lib.h File Reference

Notmuch virtual mailbox type. More...

#include <stdbool.h>
#include <stddef.h>
#include "core/lib.h"
+ Include dependency graph for lib.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void nm_db_debug_check (struct Mailbox *m)
 Check if the database is open.
 
void nm_db_longrun_done (struct Mailbox *m)
 Finish a long transaction.
 
void nm_db_longrun_init (struct Mailbox *m, bool writable)
 Start a long transaction.
 
char * nm_email_get_folder (struct Email *e)
 Get the folder for a Email.
 
char * nm_email_get_folder_rel_db (struct Mailbox *m, struct Email *e)
 Get the folder for a Email from the same level as the notmuch database.
 
int nm_get_all_tags (struct Mailbox *m, const char **tag_list, int *tag_count)
 Fill a list with all notmuch tags.
 
bool nm_message_is_still_queried (struct Mailbox *m, struct Email *e)
 Is a message still visible in the query?
 
enum MailboxType nm_path_probe (const char *path, const struct stat *st)
 Is this a Notmuch Mailbox?
 
bool nm_query_window_available (void)
 Are windowed queries enabled for use?
 
void nm_query_window_backward (void)
 Function to move the current search window backward in time.
 
void nm_query_window_forward (void)
 Function to move the current search window forward in time.
 
void nm_query_window_reset (void)
 Resets the vfolder window position to the present.
 
int nm_read_entire_thread (struct Mailbox *m, struct Email *e)
 Get the entire thread of an email.
 
int nm_record_message (struct Mailbox *m, char *path, struct Email *e)
 Add a message to the Notmuch database.
 
int nm_update_filename (struct Mailbox *m, const char *old_file, const char *new_file, struct Email *e)
 Change the filename.
 
char * nm_url_from_query (struct Mailbox *m, char *buf, size_t buflen)
 Turn a query into a URL.
 

Variables

const struct CompleteOps CompleteNmQueryOps
 Auto-Completion of NmQuerys.
 
const struct CompleteOps CompleteNmTagOps
 Auto-Completion of NmTags.
 
const struct MxOps MxNotmuchOps
 Notmuch Mailbox - Implements MxOps -.
 

Detailed Description

Notmuch virtual mailbox type.

Authors
  • Karel Zak
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file lib.h.

Function Documentation

◆ nm_db_debug_check()

void nm_db_debug_check ( struct Mailbox * m)

Check if the database is open.

Parameters
mMailbox

Definition at line 411 of file db.c.

412{
413 struct NmAccountData *adata = nm_adata_get(m);
414 if (!adata || !adata->db)
415 return;
416
417 mutt_debug(LL_DEBUG1, "nm: ERROR: db is open, closing\n");
418 nm_db_release(m);
419}
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
struct NmAccountData * nm_adata_get(struct Mailbox *m)
Get the Notmuch Account data.
Definition adata.c:69
int nm_db_release(struct Mailbox *m)
Close the Notmuch database.
Definition db.c:245
void * adata
Private data (for Mailbox backends)
Definition account.h:42
Notmuch-specific Account data -.
Definition adata.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nm_db_longrun_done()

void nm_db_longrun_done ( struct Mailbox * m)

Finish a long transaction.

Parameters
mMailbox

Definition at line 393 of file db.c.

394{
395 struct NmAccountData *adata = nm_adata_get(m);
396
397 if (adata)
398 {
399 adata->longrun = false; /* to force nm_db_release() released DB */
400 if (nm_db_release(m) == 0)
401 mutt_debug(LL_DEBUG2, "nm: long run deinitialized\n");
402 else
403 adata->longrun = true;
404 }
405}
@ LL_DEBUG2
Log at debug level 2.
Definition logging2.h:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nm_db_longrun_init()

void nm_db_longrun_init ( struct Mailbox * m,
bool writable )

Start a long transaction.

Parameters
mMailbox
writableRead/write?

Definition at line 378 of file db.c.

379{
380 struct NmAccountData *adata = nm_adata_get(m);
381
382 if (!(adata && nm_db_get(m, writable)))
383 return;
384
385 adata->longrun = true;
386 mutt_debug(LL_DEBUG2, "nm: long run initialized\n");
387}
notmuch_database_t * nm_db_get(struct Mailbox *m, bool writable)
Get the Notmuch database.
Definition db.c:210
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nm_email_get_folder()

char * nm_email_get_folder ( struct Email * e)

Get the folder for a Email.

Parameters
eEmail
Return values
ptrFolder containing email
NULLError

Definition at line 1505 of file notmuch.c.

1506{
1507 struct NmEmailData *edata = nm_edata_get(e);
1508 if (!edata)
1509 return NULL;
1510
1511 return edata->folder;
1512}
struct NmEmailData * nm_edata_get(struct Email *e)
Get the Notmuch Email data.
Definition edata.c:72
void * edata
Driver-specific data.
Definition email.h:74
Notmuch-specific Email data -.
Definition edata.h:34
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nm_email_get_folder_rel_db()

char * nm_email_get_folder_rel_db ( struct Mailbox * m,
struct Email * e )

Get the folder for a Email from the same level as the notmuch database.

Parameters
mMailbox containing Email
eEmail
Return values
ptrFolder containing email from the same level as the notmuch db
NULLError

Instead of returning a path like /var/mail/account/Inbox, this returns account/Inbox. If wanting the full path, use nm_email_get_folder().

Definition at line 1524 of file notmuch.c.

1525{
1526 char *full_folder = nm_email_get_folder(e);
1527 if (!full_folder)
1528 return NULL;
1529
1530 const char *db_path = nm_db_get_filename(m);
1531 if (!db_path)
1532 return NULL;
1533
1534 size_t prefix = mutt_str_startswith(full_folder, db_path);
1535
1536 char *path = full_folder + prefix;
1537 if (*path == '/')
1538 path++;
1539
1540 return path;
1541}
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition string.c:234
const char * nm_db_get_filename(struct Mailbox *m)
Get the filename of the Notmuch database.
Definition db.c:63
char * nm_email_get_folder(struct Email *e)
Get the folder for a Email.
Definition notmuch.c:1505
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nm_get_all_tags()

int nm_get_all_tags ( struct Mailbox * m,
const char ** tag_list,
int * tag_count )

Fill a list with all notmuch tags.

Parameters
[in]mMailbox
[out]tag_listList of tags
[out]tag_countNumber of tags
Return values
0Success
-1Failure

If tag_list is NULL, just count the tags.

Definition at line 2039 of file notmuch.c.

2040{
2041 struct NmMboxData *mdata = nm_mdata_get(m);
2042 if (!mdata || !tag_count)
2043 return -1;
2044
2045 notmuch_database_t *db = NULL;
2046 notmuch_tags_t *tags = NULL;
2047 const char *tag = NULL;
2048 int rc = -1;
2049
2050 if (!(db = nm_db_get(m, false)) || !(tags = notmuch_database_get_all_tags(db)))
2051 goto done;
2052
2053 *tag_count = 0;
2054 mutt_debug(LL_DEBUG1, "nm: get all tags\n");
2055
2056 while (notmuch_tags_valid(tags))
2057 {
2058 tag = notmuch_tags_get(tags);
2059 /* Skip empty string */
2060 if (*tag)
2061 {
2062 if (tag_list)
2063 tag_list[*tag_count] = mutt_str_dup(tag);
2064 (*tag_count)++;
2065 }
2066 notmuch_tags_move_to_next(tags);
2067 }
2068
2069 rc = 0;
2070done:
2071 if (tags)
2072 notmuch_tags_destroy(tags);
2073
2074 nm_db_release(m);
2075
2076 mutt_debug(LL_DEBUG1, "nm: get all tags done [rc=%d tag_count=%u]\n", rc, *tag_count);
2077 return rc;
2078}
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition string.c:257
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition mdata.c:96
void * mdata
Driver specific data.
Definition mailbox.h:134
Notmuch-specific Mailbox data -.
Definition mdata.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nm_message_is_still_queried()

bool nm_message_is_still_queried ( struct Mailbox * m,
struct Email * e )

Is a message still visible in the query?

Parameters
mMailbox
eEmail
Return values
trueMessage is still in query

Definition at line 1737 of file notmuch.c.

1738{
1739 struct NmMboxData *mdata = nm_mdata_get(m);
1740 if (!mdata)
1741 return false;
1742
1743 notmuch_database_t *db = nm_db_get(m, false);
1744 char *orig_str = get_query_string(mdata, true);
1745
1746 if (!db || !orig_str)
1747 {
1748 nm_db_release(m);
1749 return false;
1750 }
1751
1752 char *new_str = NULL;
1753 bool rc = false;
1754 if (mutt_str_asprintf(&new_str, "id:%s and (%s)", email_get_id(e), orig_str) < 0)
1755 {
1756 nm_db_release(m);
1757 return false;
1758 }
1759
1760 mutt_debug(LL_DEBUG2, "nm: checking if message is still queried: %s\n", new_str);
1761
1762 notmuch_query_t *q = notmuch_query_create(db, new_str);
1763
1764 switch (mdata->query_type)
1765 {
1766 case NM_QUERY_TYPE_UNKNOWN: // UNKNOWN should never occur, but MESGS is default
1768 {
1769 notmuch_messages_t *messages = get_messages(q);
1770
1771 if (!messages)
1772 goto done;
1773
1774 rc = notmuch_messages_valid(messages);
1775 notmuch_messages_destroy(messages);
1776 break;
1777 }
1779 {
1780 notmuch_threads_t *threads = get_threads(q);
1781
1782 if (!threads)
1783 goto done;
1784
1785 rc = notmuch_threads_valid(threads);
1786 notmuch_threads_destroy(threads);
1787 break;
1788 }
1789 }
1790
1791done:
1792 notmuch_query_destroy(q);
1793
1794 mutt_debug(LL_DEBUG2, "nm: checking if message is still queried: %s = %s\n",
1795 new_str, rc ? "true" : "false");
1796
1797 FREE(&new_str);
1798 nm_db_release(m);
1799 return rc;
1800}
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
int mutt_str_asprintf(char **strp, const char *fmt,...)
Definition string.c:808
static notmuch_threads_t * get_threads(notmuch_query_t *query)
Load threads for a query.
Definition notmuch.c:1016
static char * get_query_string(struct NmMboxData *mdata, bool window)
Builds the notmuch vfolder search string.
Definition notmuch.c:346
static char * email_get_id(struct Email *e)
Get the unique Notmuch Id.
Definition notmuch.c:214
static notmuch_messages_t * get_messages(notmuch_query_t *query)
Load messages for a query.
Definition notmuch.c:946
@ NM_QUERY_TYPE_UNKNOWN
Unknown query type. Error in notmuch query.
Definition query.h:36
@ NM_QUERY_TYPE_THREADS
Whole threads.
Definition query.h:38
@ NM_QUERY_TYPE_MESSAGES
Default: Messages only.
Definition query.h:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nm_query_window_available()

bool nm_query_window_available ( void )

Are windowed queries enabled for use?

Return values
trueWindowed queries in use

Definition at line 1677 of file notmuch.c.

1678{
1679 const short c_nm_query_window_duration = cs_subset_number(NeoMutt->sub, "nm_query_window_duration");
1680 const bool c_nm_query_window_enable = cs_subset_bool(NeoMutt->sub, "nm_query_window_enable");
1681
1682 return c_nm_query_window_enable || (c_nm_query_window_duration > 0);
1683}
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition helpers.c:143
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
Container for Accounts, Notifications.
Definition neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nm_query_window_backward()

void nm_query_window_backward ( void )

Function to move the current search window backward in time.

Updates nm_query_window_current_position by incrementing it by 1

The higher the value of nm_query_window_current_position is, the less recent the result will be.

Definition at line 1714 of file notmuch.c.

1715{
1716 const short c_nm_query_window_current_position = cs_subset_number(NeoMutt->sub, "nm_query_window_current_position");
1717 cs_subset_str_native_set(NeoMutt->sub, "nm_query_window_current_position",
1718 c_nm_query_window_current_position + 1, NULL);
1719 mutt_debug(LL_DEBUG2, "(%d)\n", c_nm_query_window_current_position + 1);
1720}
int cs_subset_str_native_set(const struct ConfigSubset *sub, const char *name, intptr_t value, struct Buffer *err)
Natively set the value of a string config item.
Definition subset.c:303
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nm_query_window_forward()

void nm_query_window_forward ( void )

Function to move the current search window forward in time.

Updates nm_query_window_current_position by decrementing it by 1, or does nothing if the current window already is set to 0.

The lower the value of nm_query_window_current_position is, the more recent the result will be.

Definition at line 1694 of file notmuch.c.

1695{
1696 const short c_nm_query_window_current_position = cs_subset_number(NeoMutt->sub, "nm_query_window_current_position");
1697 if (c_nm_query_window_current_position != 0)
1698 {
1699 cs_subset_str_native_set(NeoMutt->sub, "nm_query_window_current_position",
1700 c_nm_query_window_current_position - 1, NULL);
1701 }
1702
1703 mutt_debug(LL_DEBUG2, "(%d)\n", c_nm_query_window_current_position - 1);
1704}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nm_query_window_reset()

void nm_query_window_reset ( void )

Resets the vfolder window position to the present.

Definition at line 1725 of file notmuch.c.

1726{
1727 cs_subset_str_native_set(NeoMutt->sub, "nm_query_window_current_position", 0, NULL);
1728 mutt_debug(LL_DEBUG2, "Reset nm_query_window_current_position to 0\n");
1729}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nm_read_entire_thread()

int nm_read_entire_thread ( struct Mailbox * m,
struct Email * e )

Get the entire thread of an email.

Parameters
mMailbox
eEmail
Return values
0Success
-1Failure

Definition at line 1550 of file notmuch.c.

1551{
1552 if (!m)
1553 return -1;
1554
1555 struct NmMboxData *mdata = nm_mdata_get(m);
1556 if (!mdata)
1557 return -1;
1558
1559 notmuch_query_t *q = NULL;
1560 notmuch_database_t *db = NULL;
1561 notmuch_message_t *msg = NULL;
1562 int rc = -1;
1563
1564 if (!(db = nm_db_get(m, false)) || !(msg = get_nm_message(db, e)))
1565 goto done;
1566
1567 mutt_debug(LL_DEBUG1, "nm: reading entire-thread messages...[current count=%d]\n",
1568 m->msg_count);
1569
1570 progress_setup(m);
1571 const char *id = notmuch_message_get_thread_id(msg);
1572 if (!id)
1573 goto done;
1574
1575 struct Buffer *qstr = buf_pool_get();
1576 buf_printf(qstr, "thread:%s", id);
1577 q = notmuch_query_create(db, buf_string(qstr));
1578 buf_pool_release(&qstr);
1579 if (!q)
1580 goto done;
1582 notmuch_query_set_sort(q, NOTMUCH_SORT_NEWEST_FIRST);
1583
1584 read_threads_query(m, q, true, 0);
1585 mdata->mtime.tv_sec = mutt_date_now();
1586 mdata->mtime.tv_nsec = 0;
1587 rc = 0;
1588
1589 if (m->msg_count > mdata->oldmsgcount)
1591done:
1592 if (q)
1593 notmuch_query_destroy(q);
1594
1595 nm_db_release(m);
1596
1597 if (m->msg_count == mdata->oldmsgcount)
1598 mutt_message(_("No more messages in the thread"));
1599
1600 mdata->oldmsgcount = 0;
1601 mutt_debug(LL_DEBUG1, "nm: reading entire-thread messages... done [rc=%d, count=%d]\n",
1602 rc, m->msg_count);
1603 progress_free(&mdata->progress);
1604 return rc;
1605}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition buffer.c:161
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
void mailbox_changed(struct Mailbox *m, enum NotifyMailbox action)
Notify observers of a change to a Mailbox.
Definition mailbox.c:232
@ NT_MAILBOX_INVALID
Email list was changed.
Definition mailbox.h:182
#define mutt_message(...)
Definition logging2.h:93
time_t mutt_date_now(void)
Return the number of seconds since the Unix epoch.
Definition date.c:457
#define _(a)
Definition message.h:28
static void apply_exclude_tags(notmuch_query_t *query)
Exclude the configured tags.
Definition notmuch.c:423
static notmuch_message_t * get_nm_message(notmuch_database_t *db, struct Email *e)
Find a Notmuch message.
Definition notmuch.c:1081
static bool read_threads_query(struct Mailbox *m, notmuch_query_t *q, bool dedup, int limit)
Perform a query with threads.
Definition notmuch.c:1044
static void progress_setup(struct Mailbox *m)
Set up the Progress Bar.
Definition notmuch.c:704
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
void progress_free(struct Progress **ptr)
Free a Progress Bar.
Definition progress.c:110
String manipulation buffer.
Definition buffer.h:36
int msg_count
Total number of messages.
Definition mailbox.h:90
int oldmsgcount
Old message count.
Definition mdata.h:42
struct Progress * progress
A progress bar.
Definition mdata.h:41
struct timespec mtime
Time Mailbox was last changed.
Definition mdata.h:44
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nm_record_message()

int nm_record_message ( struct Mailbox * m,
char * path,
struct Email * e )

Add a message to the Notmuch database.

Parameters
mMailbox
pathPath of the email
eEmail
Return values
0Success
-1Failure

Definition at line 1956 of file notmuch.c.

1957{
1958 notmuch_database_t *db = NULL;
1959 notmuch_status_t st;
1960 notmuch_message_t *msg = NULL;
1961 int rc = -1;
1962
1963 struct NmMboxData *mdata = nm_mdata_get(m);
1964
1965 // If no notmuch data, fall back to the default mailbox.
1966 //
1967 // IMPORTANT: DO NOT FREE THIS MAILBOX. Two reasons:
1968 // 1) If user has default mailbox in config, we'll be removing it. That's not
1969 // good program behavior!
1970 // 2) If not in user's config, keep mailbox around for future nm_record calls.
1971 // It saves NeoMutt from allocating/deallocating repeatedly.
1972 if (!mdata)
1973 {
1974 mutt_debug(LL_DEBUG1, "nm: non-nm mailbox. trying the default nm mailbox.\n");
1975 m = get_default_mailbox();
1976 mdata = nm_mdata_get(m);
1977 }
1978
1979 if (!path || !mdata || (access(path, F_OK) != 0))
1980 return 0;
1981 db = nm_db_get(m, true);
1982 if (!db)
1983 return -1;
1984
1985 mutt_debug(LL_DEBUG1, "nm: record message: %s\n", path);
1986 int trans = nm_db_trans_begin(m);
1987 if (trans < 0)
1988 goto done;
1989
1990#if LIBNOTMUCH_CHECK_VERSION(5, 1, 0)
1991 st = notmuch_database_index_file(db, path, NULL, &msg);
1992#else
1993 st = notmuch_database_add_message(db, path, &msg);
1994#endif
1995
1996 if ((st != NOTMUCH_STATUS_SUCCESS) && (st != NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID))
1997 {
1998 mutt_debug(LL_DEBUG1, "nm: failed to add '%s' [st=%d]\n", path, (int) st);
1999 goto done;
2000 }
2001
2002 if ((st == NOTMUCH_STATUS_SUCCESS) && msg)
2003 {
2004 notmuch_message_maildir_flags_to_tags(msg);
2005 if (e)
2006 {
2007 struct Buffer *tags = buf_pool_get();
2008 driver_tags_get(&e->tags, tags);
2009 update_tags(msg, buf_string(tags));
2010 buf_pool_release(&tags);
2011 }
2012 const char *const c_nm_record_tags = cs_subset_string(NeoMutt->sub, "nm_record_tags");
2013 if (c_nm_record_tags)
2014 update_tags(msg, c_nm_record_tags);
2015 }
2016
2017 rc = 0;
2018done:
2019 if (msg)
2020 notmuch_message_destroy(msg);
2021 if (trans == 1)
2022 nm_db_trans_end(m);
2023
2024 nm_db_release(m);
2025
2026 return rc;
2027}
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition helpers.c:291
int nm_db_trans_begin(struct Mailbox *m)
Start a Notmuch database transaction.
Definition db.c:278
int nm_db_trans_end(struct Mailbox *m)
End a database transaction.
Definition db.c:300
static struct Mailbox * get_default_mailbox(void)
Get Mailbox for notmuch without any parameters.
Definition notmuch.c:1933
static int update_tags(notmuch_message_t *msg, const char *tag_str)
Update the tags on a message.
Definition notmuch.c:1141
struct TagList tags
For drivers that support server tagging.
Definition email.h:72
void driver_tags_get(struct TagList *tl, struct Buffer *tags)
Get tags all tags separated by space.
Definition tags.c:165
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nm_update_filename()

int nm_update_filename ( struct Mailbox * m,
const char * old_file,
const char * new_file,
struct Email * e )

Change the filename.

Parameters
mMailbox
old_fileOld filename
new_fileNew filename
eEmail
Return values
0Success
-1Failure

Definition at line 1811 of file notmuch.c.

1813{
1814 char buf[PATH_MAX] = { 0 };
1815 struct NmMboxData *mdata = nm_mdata_get(m);
1816 if (!mdata || !new_file)
1817 return -1;
1818
1819 if (!old_file && nm_edata_get(e))
1820 {
1821 email_get_fullpath(e, buf, sizeof(buf));
1822 old_file = buf;
1823 }
1824
1825 int rc = rename_filename(m, old_file, new_file, e);
1826
1827 nm_db_release(m);
1828 mdata->mtime.tv_sec = mutt_date_now();
1829 mdata->mtime.tv_nsec = 0;
1830 return rc;
1831}
#define PATH_MAX
Definition mutt.h:49
static char * email_get_fullpath(struct Email *e, char *buf, size_t buflen)
Get the full path of an email.
Definition notmuch.c:230
static int rename_filename(struct Mailbox *m, const char *old_file, const char *new_file, struct Email *e)
Rename the file.
Definition notmuch.c:1367

◆ nm_url_from_query()

char * nm_url_from_query ( struct Mailbox * m,
char * buf,
size_t buflen )

Turn a query into a URL.

Parameters
mMailbox
bufBuffer for URL
buflenLength of buffer
Return values
ptrQuery as a URL
NULLError

Definition at line 1615 of file notmuch.c.

1616{
1617 mutt_debug(LL_DEBUG2, "(%s)\n", buf);
1618 struct NmMboxData *mdata = nm_mdata_get(m);
1619 char url[PATH_MAX + 1024 + 32]; /* path to DB + query + URL "decoration" */
1620 int added;
1621 bool using_default_data = false;
1622
1623 // No existing data. Try to get a default NmMboxData.
1624 if (!mdata)
1625 {
1627
1628 // Failed to get default data.
1629 if (!mdata)
1630 return NULL;
1631
1632 using_default_data = true;
1633 }
1634
1635 enum NmQueryType query_type = cs_subset_enum(NeoMutt->sub, "nm_query_type");
1636 mdata->query_type = nm_parse_type_from_query(buf, query_type);
1637
1638 const char *db_filename = nm_db_get_filename(m);
1639 if (!db_filename)
1640 db_filename = "";
1641
1642 const short c_nm_db_limit = cs_subset_number(NeoMutt->sub, "nm_db_limit");
1643 if (get_limit(mdata) == c_nm_db_limit)
1644 {
1645 added = snprintf(url, sizeof(url), "%s%s?type=%s&query=", NmUrlProtocol,
1646 db_filename, nm_query_type_to_string(mdata->query_type));
1647 }
1648 else
1649 {
1650 added = snprintf(url, sizeof(url),
1651 "%s%s?type=%s&limit=%d&query=", NmUrlProtocol, db_filename,
1653 }
1654
1655 if (added >= sizeof(url))
1656 {
1657 // snprintf output was truncated, so can't create URL
1658 return NULL;
1659 }
1660
1661 url_pct_encode(&url[added], sizeof(url) - added, buf);
1662
1663 mutt_str_copy(buf, url, buflen);
1664 buf[buflen - 1] = '\0';
1665
1666 if (using_default_data)
1667 nm_mdata_free((void **) &mdata);
1668
1669 mutt_debug(LL_DEBUG1, "nm: url from query '%s'\n", buf);
1670 return buf;
1671}
unsigned char cs_subset_enum(const struct ConfigSubset *sub, const char *name)
Get a enumeration config item by name.
Definition helpers.c:71
void nm_mdata_free(void **ptr)
Free the private Mailbox data - Implements Mailbox::mdata_free() -.
Definition mdata.c:45
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition string.c:586
static int get_limit(struct NmMboxData *mdata)
Get the database limit.
Definition notmuch.c:414
static struct NmMboxData * nm_get_default_data(void)
Create a Mailbox with default Notmuch settings.
Definition notmuch.c:169
const char NmUrlProtocol[]
Protocol string for Notmuch URLs.
Definition notmuch.c:102
enum NmQueryType nm_parse_type_from_query(char *buf, enum NmQueryType fallback)
Parse a query type out of a query.
Definition query.c:90
const char * nm_query_type_to_string(enum NmQueryType query_type)
Turn a query type into a string.
Definition query.c:137
NmQueryType
Notmuch Query Types.
Definition query.h:35
enum NmQueryType query_type
Messages or Threads.
Definition mdata.h:39
void url_pct_encode(char *buf, size_t buflen, const char *src)
Percent-encode a string.
Definition url.c:152
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ CompleteNmQueryOps

const struct CompleteOps CompleteNmQueryOps
extern

Auto-Completion of NmQuerys.

Definition at line 247 of file complete.c.

247 {
248 .complete = complete_nm_query,
249};
enum FunctionRetval complete_nm_query(struct EnterWindowData *wdata, int op)
Complete a Notmuch Query - Implements CompleteOps::complete() -.
Definition complete.c:213

◆ CompleteNmTagOps

const struct CompleteOps CompleteNmTagOps
extern

Auto-Completion of NmTags.

Definition at line 254 of file complete.c.

254 {
255 .complete = complete_nm_tag,
256};
enum FunctionRetval complete_nm_tag(struct EnterWindowData *wdata, int op)
Complete a Notmuch Tag - Implements CompleteOps::complete() -.
Definition complete.c:230