NeoMutt  2023-11-03-85-g512e01
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
lib.h File Reference

Notmuch virtual mailbox type. More...

#include <stddef.h>
#include <stdbool.h>
#include "core/lib.h"
#include "complete/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_init (void)
 Setup feature commands.
 
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? - Implements MxOps::path_probe() -.
 
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

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_init()

void nm_init ( void  )

Setup feature commands.

Definition at line 100 of file notmuch.c.

101{
103}
void commands_register(const struct Command *cmds, const size_t num_cmds)
Add commands to Commands array.
Definition: command.c:53
#define mutt_array_size(x)
Definition: memory.h:38
static const struct Command NmCommands[]
Notmuch Commands.
Definition: notmuch.c:85
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nm_db_debug_check()

void nm_db_debug_check ( struct Mailbox m)

Check if the database is open.

Parameters
mMailbox

Definition at line 388 of file db.c.

389{
390 struct NmAccountData *adata = nm_adata_get(m);
391 if (!adata || !adata->db)
392 return;
393
394 mutt_debug(LL_DEBUG1, "nm: ERROR: db is open, closing\n");
395 nm_db_release(m);
396}
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
struct NmAccountData * nm_adata_get(struct Mailbox *m)
Get the Notmuch Account data.
Definition: adata.c:71
int nm_db_release(struct Mailbox *m)
Close the Notmuch database.
Definition: db.c:224
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
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 370 of file db.c.

371{
372 struct NmAccountData *adata = nm_adata_get(m);
373
374 if (adata)
375 {
376 adata->longrun = false; /* to force nm_db_release() released DB */
377 if (nm_db_release(m) == 0)
378 mutt_debug(LL_DEBUG2, "nm: long run deinitialized\n");
379 else
380 adata->longrun = true;
381 }
382}
@ LL_DEBUG2
Log at debug level 2.
Definition: logging2.h:44
+ 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 355 of file db.c.

356{
357 struct NmAccountData *adata = nm_adata_get(m);
358
359 if (!(adata && nm_db_get(m, writable)))
360 return;
361
362 adata->longrun = true;
363 mutt_debug(LL_DEBUG2, "nm: long run initialized\n");
364}
notmuch_database_t * nm_db_get(struct Mailbox *m, bool writable)
Get the Notmuch database.
Definition: db.c:200
+ 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 1459 of file notmuch.c.

1460{
1461 struct NmEmailData *edata = nm_edata_get(e);
1462 if (!edata)
1463 return NULL;
1464
1465 return edata->folder;
1466}
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:72
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 1478 of file notmuch.c.

1479{
1480 char *full_folder = nm_email_get_folder(e);
1481 if (!full_folder)
1482 return NULL;
1483
1484 const char *db_path = nm_db_get_filename(m);
1485 if (!db_path)
1486 return NULL;
1487
1488 return full_folder + strlen(db_path);
1489}
const char * nm_db_get_filename(struct Mailbox *m)
Get the filename of the Notmuch database.
Definition: db.c:54
char * nm_email_get_folder(struct Email *e)
Get the folder for a Email.
Definition: notmuch.c:1459
+ 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 1964 of file notmuch.c.

1965{
1966 struct NmMboxData *mdata = nm_mdata_get(m);
1967 if (!mdata)
1968 return -1;
1969
1970 notmuch_database_t *db = NULL;
1971 notmuch_tags_t *tags = NULL;
1972 const char *tag = NULL;
1973 int rc = -1;
1974
1975 if (!(db = nm_db_get(m, false)) || !(tags = notmuch_database_get_all_tags(db)))
1976 goto done;
1977
1978 *tag_count = 0;
1979 mutt_debug(LL_DEBUG1, "nm: get all tags\n");
1980
1981 while (notmuch_tags_valid(tags))
1982 {
1983 tag = notmuch_tags_get(tags);
1984 /* Skip empty string */
1985 if (*tag)
1986 {
1987 if (tag_list)
1988 tag_list[*tag_count] = mutt_str_dup(tag);
1989 (*tag_count)++;
1990 }
1991 notmuch_tags_move_to_next(tags);
1992 }
1993
1994 rc = 0;
1995done:
1996 if (tags)
1997 notmuch_tags_destroy(tags);
1998
1999 nm_db_release(m);
2000
2001 mutt_debug(LL_DEBUG1, "nm: get all tags done [rc=%d tag_count=%u]\n", rc, *tag_count);
2002 return rc;
2003}
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:251
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:131
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 1684 of file notmuch.c.

1685{
1686 struct NmMboxData *mdata = nm_mdata_get(m);
1687 if (!mdata)
1688 return false;
1689
1690 notmuch_database_t *db = nm_db_get(m, false);
1691 char *orig_str = get_query_string(mdata, true);
1692
1693 if (!db || !orig_str)
1694 return false;
1695
1696 char *new_str = NULL;
1697 bool rc = false;
1698 if (mutt_str_asprintf(&new_str, "id:%s and (%s)", email_get_id(e), orig_str) < 0)
1699 return false;
1700
1701 mutt_debug(LL_DEBUG2, "nm: checking if message is still queried: %s\n", new_str);
1702
1703 notmuch_query_t *q = notmuch_query_create(db, new_str);
1704
1705 switch (mdata->query_type)
1706 {
1707 case NM_QUERY_TYPE_UNKNOWN: // UNKNOWN should never occur, but MESGS is default
1709 {
1710 notmuch_messages_t *messages = get_messages(q);
1711
1712 if (!messages)
1713 return false;
1714
1715 rc = notmuch_messages_valid(messages);
1716 notmuch_messages_destroy(messages);
1717 break;
1718 }
1720 {
1721 notmuch_threads_t *threads = get_threads(q);
1722
1723 if (!threads)
1724 return false;
1725
1726 rc = notmuch_threads_valid(threads);
1727 notmuch_threads_destroy(threads);
1728 break;
1729 }
1730 }
1731
1732 notmuch_query_destroy(q);
1733
1734 mutt_debug(LL_DEBUG2, "nm: checking if message is still queried: %s = %s\n",
1735 new_str, rc ? "true" : "false");
1736
1737 return rc;
1738}
int mutt_str_asprintf(char **strp, const char *fmt,...)
Definition: string.c:1022
static notmuch_threads_t * get_threads(notmuch_query_t *query)
Load threads for a query.
Definition: notmuch.c:973
static char * get_query_string(struct NmMboxData *mdata, bool window)
Builds the notmuch vfolder search string.
Definition: notmuch.c:338
static char * email_get_id(struct Email *e)
Get the unique Notmuch Id.
Definition: notmuch.c:213
static notmuch_messages_t * get_messages(notmuch_query_t *query)
Load messages for a query.
Definition: notmuch.c:903
@ NM_QUERY_TYPE_UNKNOWN
Unknown query type. Error in notmuch query.
Definition: query.h:38
@ NM_QUERY_TYPE_THREADS
Whole threads.
Definition: query.h:37
@ NM_QUERY_TYPE_MESGS
Default: Messages only.
Definition: query.h:36
+ 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 1624 of file notmuch.c.

1625{
1626 const short c_nm_query_window_duration = cs_subset_number(NeoMutt->sub, "nm_query_window_duration");
1627 const bool c_nm_query_window_enable = cs_subset_bool(NeoMutt->sub, "nm_query_window_enable");
1628
1629 return c_nm_query_window_enable || (c_nm_query_window_duration > 0);
1630}
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:144
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:48
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
+ 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 1661 of file notmuch.c.

1662{
1663 const short c_nm_query_window_current_position = cs_subset_number(NeoMutt->sub, "nm_query_window_current_position");
1664 cs_subset_str_native_set(NeoMutt->sub, "nm_query_window_current_position",
1665 c_nm_query_window_current_position + 1, NULL);
1666 mutt_debug(LL_DEBUG2, "(%d)\n", c_nm_query_window_current_position + 1);
1667}
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:304
+ 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 1641 of file notmuch.c.

1642{
1643 const short c_nm_query_window_current_position = cs_subset_number(NeoMutt->sub, "nm_query_window_current_position");
1644 if (c_nm_query_window_current_position != 0)
1645 {
1646 cs_subset_str_native_set(NeoMutt->sub, "nm_query_window_current_position",
1647 c_nm_query_window_current_position - 1, NULL);
1648 }
1649
1650 mutt_debug(LL_DEBUG2, "(%d)\n", c_nm_query_window_current_position - 1);
1651}
+ 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 1672 of file notmuch.c.

1673{
1674 cs_subset_str_native_set(NeoMutt->sub, "nm_query_window_current_position", 0, NULL);
1675 mutt_debug(LL_DEBUG2, "Reset nm_query_window_current_position to 0\n");
1676}
+ 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 1498 of file notmuch.c.

1499{
1500 if (!m)
1501 return -1;
1502
1503 struct NmMboxData *mdata = nm_mdata_get(m);
1504 if (!mdata)
1505 return -1;
1506
1507 notmuch_query_t *q = NULL;
1508 notmuch_database_t *db = NULL;
1509 notmuch_message_t *msg = NULL;
1510 int rc = -1;
1511
1512 if (!(db = nm_db_get(m, false)) || !(msg = get_nm_message(db, e)))
1513 goto done;
1514
1515 mutt_debug(LL_DEBUG1, "nm: reading entire-thread messages...[current count=%d]\n",
1516 m->msg_count);
1517
1518 progress_setup(m);
1519 const char *id = notmuch_message_get_thread_id(msg);
1520 if (!id)
1521 goto done;
1522
1523 char *qstr = NULL;
1524 mutt_str_append_item(&qstr, "thread:", '\0');
1525 mutt_str_append_item(&qstr, id, '\0');
1526
1527 q = notmuch_query_create(db, qstr);
1528 FREE(&qstr);
1529 if (!q)
1530 goto done;
1532 notmuch_query_set_sort(q, NOTMUCH_SORT_NEWEST_FIRST);
1533
1534 read_threads_query(m, q, true, 0);
1535 mdata->mtime.tv_sec = mutt_date_now();
1536 mdata->mtime.tv_nsec = 0;
1537 rc = 0;
1538
1539 if (m->msg_count > mdata->oldmsgcount)
1541done:
1542 if (q)
1543 notmuch_query_destroy(q);
1544
1545 nm_db_release(m);
1546
1547 if (m->msg_count == mdata->oldmsgcount)
1548 mutt_message(_("No more messages in the thread"));
1549
1550 mdata->oldmsgcount = 0;
1551 mutt_debug(LL_DEBUG1, "nm: reading entire-thread messages... done [rc=%d, count=%d]\n",
1552 rc, m->msg_count);
1553 progress_free(&mdata->progress);
1554 return rc;
1555}
#define mutt_message(...)
Definition: logging2.h:91
void mailbox_changed(struct Mailbox *m, enum NotifyMailbox action)
Notify observers of a change to a Mailbox.
Definition: mailbox.c:226
@ NT_MAILBOX_INVALID
Email list was changed.
Definition: mailbox.h:176
#define FREE(x)
Definition: memory.h:45
time_t mutt_date_now(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:446
#define _(a)
Definition: message.h:28
void mutt_str_append_item(char **str, const char *item, char sep)
Add string to another separated by sep.
Definition: string.c:347
static void apply_exclude_tags(notmuch_query_t *query)
Exclude the configured tags.
Definition: notmuch.c:415
static notmuch_message_t * get_nm_message(notmuch_database_t *db, struct Email *e)
Find a Notmuch message.
Definition: notmuch.c:1038
static bool read_threads_query(struct Mailbox *m, notmuch_query_t *q, bool dedup, int limit)
Perform a query with threads.
Definition: notmuch.c:1001
static void progress_setup(struct Mailbox *m)
Set up the Progress Bar.
Definition: notmuch.c:669
void progress_free(struct Progress **ptr)
Free a Progress Bar.
Definition: progress.c:111
int msg_count
Total number of messages.
Definition: mailbox.h:88
+ 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 1882 of file notmuch.c.

1883{
1884 notmuch_database_t *db = NULL;
1885 notmuch_status_t st;
1886 notmuch_message_t *msg = NULL;
1887 int rc = -1;
1888
1889 struct NmMboxData *mdata = nm_mdata_get(m);
1890
1891 // If no notmuch data, fall back to the default mailbox.
1892 //
1893 // IMPORTANT: DO NOT FREE THIS MAILBOX. Two reasons:
1894 // 1) If user has default mailbox in config, we'll be removing it. That's not
1895 // good program behavior!
1896 // 2) If not in user's config, keep mailbox around for future nm_record calls.
1897 // It saves NeoMutt from allocating/deallocating repeatedly.
1898 if (!mdata)
1899 {
1900 mutt_debug(LL_DEBUG1, "nm: non-nm mailbox. trying the default nm mailbox.");
1901 m = get_default_mailbox();
1902 mdata = nm_mdata_get(m);
1903 }
1904
1905 if (!path || !mdata || (access(path, F_OK) != 0))
1906 return 0;
1907 db = nm_db_get(m, true);
1908 if (!db)
1909 return -1;
1910
1911 mutt_debug(LL_DEBUG1, "nm: record message: %s\n", path);
1912 int trans = nm_db_trans_begin(m);
1913 if (trans < 0)
1914 goto done;
1915
1916#if LIBNOTMUCH_CHECK_VERSION(5, 1, 0)
1917 st = notmuch_database_index_file(db, path, NULL, &msg);
1918#else
1919 st = notmuch_database_add_message(db, path, &msg);
1920#endif
1921
1922 if ((st != NOTMUCH_STATUS_SUCCESS) && (st != NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID))
1923 {
1924 mutt_debug(LL_DEBUG1, "nm: failed to add '%s' [st=%d]\n", path, (int) st);
1925 goto done;
1926 }
1927
1928 if ((st == NOTMUCH_STATUS_SUCCESS) && msg)
1929 {
1930 notmuch_message_maildir_flags_to_tags(msg);
1931 if (e)
1932 {
1933 char *tags = driver_tags_get(&e->tags);
1934 update_tags(msg, tags);
1935 FREE(&tags);
1936 }
1937 const char *const c_nm_record_tags = cs_subset_string(NeoMutt->sub, "nm_record_tags");
1938 if (c_nm_record_tags)
1939 update_tags(msg, c_nm_record_tags);
1940 }
1941
1942 rc = 0;
1943done:
1944 if (msg)
1945 notmuch_message_destroy(msg);
1946 if (trans == 1)
1947 nm_db_trans_end(m);
1948
1949 nm_db_release(m);
1950
1951 return rc;
1952}
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:292
int nm_db_trans_begin(struct Mailbox *m)
Start a Notmuch database transaction.
Definition: db.c:257
int nm_db_trans_end(struct Mailbox *m)
End a database transaction.
Definition: db.c:279
static struct Mailbox * get_default_mailbox(void)
Get Mailbox for notmuch without any parameters.
Definition: notmuch.c:1859
static int update_tags(notmuch_message_t *msg, const char *tag_str)
Update the tags on a message.
Definition: notmuch.c:1096
struct TagList tags
For drivers that support server tagging.
Definition: email.h:70
char * driver_tags_get(struct TagList *list)
Get tags.
Definition: tags.c:145
+ 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 1749 of file notmuch.c.

1751{
1752 char buf[PATH_MAX] = { 0 };
1753 struct NmMboxData *mdata = nm_mdata_get(m);
1754 if (!mdata || !new_file)
1755 return -1;
1756
1757 if (!old_file && nm_edata_get(e))
1758 {
1759 email_get_fullpath(e, buf, sizeof(buf));
1760 old_file = buf;
1761 }
1762
1763 int rc = rename_filename(m, old_file, new_file, e);
1764
1765 nm_db_release(m);
1766 mdata->mtime.tv_sec = mutt_date_now();
1767 mdata->mtime.tv_nsec = 0;
1768 return rc;
1769}
#define PATH_MAX
Definition: mutt.h:41
static char * email_get_fullpath(struct Email *e, char *buf, size_t buflen)
Get the full path of an email.
Definition: notmuch.c:229
static int rename_filename(struct Mailbox *m, const char *old_file, const char *new_file, struct Email *e)
Rename the file.
Definition: notmuch.c:1322
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 1565 of file notmuch.c.

1566{
1567 mutt_debug(LL_DEBUG2, "(%s)\n", buf);
1568 struct NmMboxData *mdata = nm_mdata_get(m);
1569 char url[PATH_MAX + 1024 + 32]; /* path to DB + query + URL "decoration" */
1570 int added;
1571 bool using_default_data = false;
1572
1573 // No existing data. Try to get a default NmMboxData.
1574 if (!mdata)
1575 {
1577
1578 // Failed to get default data.
1579 if (!mdata)
1580 return NULL;
1581
1582 using_default_data = true;
1583 }
1584
1586 cs_subset_string(NeoMutt->sub, "nm_query_type"));
1587 mdata->query_type = nm_parse_type_from_query(buf, query_type);
1588
1589 const short c_nm_db_limit = cs_subset_number(NeoMutt->sub, "nm_db_limit");
1590 if (get_limit(mdata) == c_nm_db_limit)
1591 {
1592 added = snprintf(url, sizeof(url), "%s%s?type=%s&query=", NmUrlProtocol,
1594 }
1595 else
1596 {
1597 added = snprintf(url, sizeof(url), "%s%s?type=%s&limit=%d&query=", NmUrlProtocol,
1600 }
1601
1602 if (added >= sizeof(url))
1603 {
1604 // snprintf output was truncated, so can't create URL
1605 return NULL;
1606 }
1607
1608 url_pct_encode(&url[added], sizeof(url) - added, buf);
1609
1610 mutt_str_copy(buf, url, buflen);
1611 buf[buflen - 1] = '\0';
1612
1613 if (using_default_data)
1614 nm_mdata_free((void **) &mdata);
1615
1616 mutt_debug(LL_DEBUG1, "nm: url from query '%s'\n", buf);
1617 return buf;
1618}
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:653
static int get_limit(struct NmMboxData *mdata)
Get the database limit.
Definition: notmuch.c:406
static struct NmMboxData * nm_get_default_data(void)
Create a Mailbox with default Notmuch settings.
Definition: notmuch.c:168
const char NmUrlProtocol[]
Protocol string for Notmuch URLs.
Definition: notmuch.c:93
enum NmQueryType nm_string_to_query_type(const char *str)
Lookup a query type.
Definition: query.c:109
enum NmQueryType nm_parse_type_from_query(char *buf, enum NmQueryType fallback)
Parse a query type out of a query.
Definition: query.c:48
const char * nm_query_type_to_string(enum NmQueryType query_type)
Turn a query type into a string.
Definition: query.c:95
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:151
+ 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 249 of file complete.c.

◆ CompleteNmTagOps

const struct CompleteOps CompleteNmTagOps
extern

Auto-Completion of NmTags.

Definition at line 256 of file complete.c.