NeoMutt  2022-04-29-145-g9b6a0e
Teaching an old dog new tricks
DOXYGEN
lib.h File Reference

Notmuch virtual mailbox type. More...

#include <stddef.h>
#include <stdbool.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_init (void)
 Setup feature commands. More...
 
void nm_db_debug_check (struct Mailbox *m)
 Check if the database is open. More...
 
void nm_db_longrun_done (struct Mailbox *m)
 Finish a long transaction. More...
 
void nm_db_longrun_init (struct Mailbox *m, bool writable)
 Start a long transaction. More...
 
char * nm_email_get_folder (struct Email *e)
 Get the folder for a Email. More...
 
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. More...
 
int nm_get_all_tags (struct Mailbox *m, const char **tag_list, int *tag_count)
 Fill a list with all notmuch tags. More...
 
bool nm_message_is_still_queried (struct Mailbox *m, struct Email *e)
 Is a message still visible in the query? More...
 
enum MailboxType nm_path_probe (const char *path, const struct stat *st)
 Is this a Notmuch Mailbox? - Implements MxOps::path_probe() -. More...
 
bool nm_query_window_available (void)
 Are windowed queries enabled for use? More...
 
void nm_query_window_backward (void)
 Function to move the current search window backward in time. More...
 
void nm_query_window_forward (void)
 Function to move the current search window forward in time. More...
 
void nm_query_window_reset (void)
 Resets the vfolder window position to the present. More...
 
int nm_read_entire_thread (struct Mailbox *m, struct Email *e)
 Get the entire thread of an email. More...
 
int nm_record_message (struct Mailbox *m, char *path, struct Email *e)
 Add a message to the Notmuch database. More...
 
int nm_update_filename (struct Mailbox *m, const char *old_file, const char *new_file, struct Email *e)
 Change the filename. More...
 
char * nm_url_from_query (struct Mailbox *m, char *buf, size_t buflen)
 Turn a query into a URL. More...
 

Variables

struct MxOps MxNotmuchOps
 Notmuch Mailbox - Implements MxOps -. More...
 

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

100 {
102 }
#define COMMANDS_REGISTER(cmds)
Definition: mutt_commands.h:47
static const struct Command nm_commands[]
Definition: notmuch.c:86
+ 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 357 of file db.c.

358 {
359  struct NmAccountData *adata = nm_adata_get(m);
360  if (!adata || !adata->db)
361  return;
362 
363  mutt_debug(LL_DEBUG1, "nm: ERROR: db is open, closing\n");
364  nm_db_release(m);
365 }
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
@ LL_DEBUG1
Log at debug level 1.
Definition: logging.h:40
struct NmAccountData * nm_adata_get(struct Mailbox *m)
Get the Notmuch Account data.
Definition: adata.c:68
int nm_db_release(struct Mailbox *m)
Close the Notmuch database.
Definition: db.c:193
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 339 of file db.c.

340 {
341  struct NmAccountData *adata = nm_adata_get(m);
342 
343  if (adata)
344  {
345  adata->longrun = false; /* to force nm_db_release() released DB */
346  if (nm_db_release(m) == 0)
347  mutt_debug(LL_DEBUG2, "nm: long run deinitialized\n");
348  else
349  adata->longrun = true;
350  }
351 }
@ LL_DEBUG2
Log at debug level 2.
Definition: logging.h:41
+ 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 324 of file db.c.

325 {
326  struct NmAccountData *adata = nm_adata_get(m);
327 
328  if (!(adata && nm_db_get(m, writable)))
329  return;
330 
331  adata->longrun = true;
332  mutt_debug(LL_DEBUG2, "nm: long run initialized\n");
333 }
notmuch_database_t * nm_db_get(struct Mailbox *m, bool writable)
Get the Notmuch database.
Definition: db.c:169
+ 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 1449 of file notmuch.c.

1450 {
1451  struct NmEmailData *edata = nm_edata_get(e);
1452  if (!edata)
1453  return NULL;
1454 
1455  return edata->folder;
1456 }
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 1468 of file notmuch.c.

1469 {
1470  char *full_folder = nm_email_get_folder(e);
1471  if (!full_folder)
1472  return NULL;
1473 
1474  const char *db_path = nm_db_get_filename(m);
1475  if (!db_path)
1476  return NULL;
1477 
1478  return full_folder + strlen(db_path);
1479 }
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:1449
+ 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 1950 of file notmuch.c.

1951 {
1952  struct NmMboxData *mdata = nm_mdata_get(m);
1953  if (!mdata)
1954  return -1;
1955 
1956  notmuch_database_t *db = NULL;
1957  notmuch_tags_t *tags = NULL;
1958  const char *tag = NULL;
1959  int rc = -1;
1960 
1961  if (!(db = nm_db_get(m, false)) || !(tags = notmuch_database_get_all_tags(db)))
1962  goto done;
1963 
1964  *tag_count = 0;
1965  mutt_debug(LL_DEBUG1, "nm: get all tags\n");
1966 
1967  while (notmuch_tags_valid(tags))
1968  {
1969  tag = notmuch_tags_get(tags);
1970  /* Skip empty string */
1971  if (*tag)
1972  {
1973  if (tag_list)
1974  tag_list[*tag_count] = mutt_str_dup(tag);
1975  (*tag_count)++;
1976  }
1977  notmuch_tags_move_to_next(tags);
1978  }
1979 
1980  rc = 0;
1981 done:
1982  if (tags)
1983  notmuch_tags_destroy(tags);
1984 
1985  nm_db_release(m);
1986 
1987  mutt_debug(LL_DEBUG1, "nm: get all tags done [rc=%d tag_count=%u]\n", rc, *tag_count);
1988  return rc;
1989 }
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:250
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition: mdata.c:97
void * mdata
Driver specific data.
Definition: mailbox.h:133
Notmuch-specific Mailbox data -.
Definition: mdata.h:34
+ 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 1674 of file notmuch.c.

1675 {
1676  struct NmMboxData *mdata = nm_mdata_get(m);
1677  notmuch_database_t *db = nm_db_get(m, false);
1678  char *orig_str = get_query_string(mdata, true);
1679 
1680  if (!db || !orig_str)
1681  return false;
1682 
1683  char *new_str = NULL;
1684  bool rc = false;
1685  if (mutt_str_asprintf(&new_str, "id:%s and (%s)", email_get_id(e), orig_str) < 0)
1686  return false;
1687 
1688  mutt_debug(LL_DEBUG2, "nm: checking if message is still queried: %s\n", new_str);
1689 
1690  notmuch_query_t *q = notmuch_query_create(db, new_str);
1691 
1692  switch (mdata->query_type)
1693  {
1694  case NM_QUERY_TYPE_UNKNOWN: // UNKNOWN should never occur, but MESGS is default
1695  case NM_QUERY_TYPE_MESGS:
1696  {
1697  notmuch_messages_t *messages = get_messages(q);
1698 
1699  if (!messages)
1700  return false;
1701 
1702  rc = notmuch_messages_valid(messages);
1703  notmuch_messages_destroy(messages);
1704  break;
1705  }
1706  case NM_QUERY_TYPE_THREADS:
1707  {
1708  notmuch_threads_t *threads = get_threads(q);
1709 
1710  if (!threads)
1711  return false;
1712 
1713  rc = notmuch_threads_valid(threads);
1714  notmuch_threads_destroy(threads);
1715  break;
1716  }
1717  }
1718 
1719  notmuch_query_destroy(q);
1720 
1721  mutt_debug(LL_DEBUG2, "nm: checking if message is still queried: %s = %s\n",
1722  new_str, rc ? "true" : "false");
1723 
1724  return rc;
1725 }
int mutt_str_asprintf(char **strp, const char *fmt,...)
Definition: string.c:1008
static char * get_query_string(struct NmMboxData *mdata, bool window)
Builds the notmuch vfolder search string.
Definition: notmuch.c:334
static char * email_get_id(struct Email *e)
Get the unique Notmuch Id.
Definition: notmuch.c:208
static notmuch_threads_t * get_threads(notmuch_query_t *query)
Load threads for a query.
Definition: notmuch.c:967
static notmuch_messages_t * get_messages(notmuch_query_t *query)
Load messages for a query.
Definition: notmuch.c:897
@ 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 1614 of file notmuch.c.

1615 {
1616  const short c_nm_query_window_duration = cs_subset_number(NeoMutt->sub, "nm_query_window_duration");
1617  const bool c_nm_query_window_enable = cs_subset_bool(NeoMutt->sub, "nm_query_window_enable");
1618 
1619  return c_nm_query_window_enable || (c_nm_query_window_duration > 0);
1620 }
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:169
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
+ 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 1651 of file notmuch.c.

1652 {
1653  const short c_nm_query_window_current_position = cs_subset_number(NeoMutt->sub, "nm_query_window_current_position");
1654  cs_subset_str_native_set(NeoMutt->sub, "nm_query_window_current_position",
1655  c_nm_query_window_current_position + 1, NULL);
1656  mutt_debug(LL_DEBUG2, "(%d)\n", c_nm_query_window_current_position + 1);
1657 }
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:305
+ 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 1631 of file notmuch.c.

1632 {
1633  const short c_nm_query_window_current_position = cs_subset_number(NeoMutt->sub, "nm_query_window_current_position");
1634  if (c_nm_query_window_current_position != 0)
1635  {
1636  cs_subset_str_native_set(NeoMutt->sub, "nm_query_window_current_position",
1637  c_nm_query_window_current_position - 1, NULL);
1638  }
1639 
1640  mutt_debug(LL_DEBUG2, "(%d)\n", c_nm_query_window_current_position - 1);
1641 }
+ 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 1662 of file notmuch.c.

1663 {
1664  cs_subset_str_native_set(NeoMutt->sub, "nm_query_window_current_position", 0, NULL);
1665  mutt_debug(LL_DEBUG2, "Reset nm_query_window_current_position to 0\n");
1666 }
+ 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 1488 of file notmuch.c.

1489 {
1490  if (!m)
1491  return -1;
1492 
1493  struct NmMboxData *mdata = nm_mdata_get(m);
1494  if (!mdata)
1495  return -1;
1496 
1497  notmuch_query_t *q = NULL;
1498  notmuch_database_t *db = NULL;
1499  notmuch_message_t *msg = NULL;
1500  int rc = -1;
1501 
1502  if (!(db = nm_db_get(m, false)) || !(msg = get_nm_message(db, e)))
1503  goto done;
1504 
1505  mutt_debug(LL_DEBUG1, "nm: reading entire-thread messages...[current count=%d]\n",
1506  m->msg_count);
1507 
1508  progress_setup(m);
1509  const char *id = notmuch_message_get_thread_id(msg);
1510  if (!id)
1511  goto done;
1512 
1513  char *qstr = NULL;
1514  mutt_str_append_item(&qstr, "thread:", '\0');
1515  mutt_str_append_item(&qstr, id, '\0');
1516 
1517  q = notmuch_query_create(db, qstr);
1518  FREE(&qstr);
1519  if (!q)
1520  goto done;
1521  apply_exclude_tags(q);
1522  notmuch_query_set_sort(q, NOTMUCH_SORT_NEWEST_FIRST);
1523 
1524  read_threads_query(m, q, true, 0);
1525  m->mtime.tv_sec = mutt_date_epoch();
1526  m->mtime.tv_nsec = 0;
1527  rc = 0;
1528 
1529  if (m->msg_count > mdata->oldmsgcount)
1531 done:
1532  if (q)
1533  notmuch_query_destroy(q);
1534 
1535  nm_db_release(m);
1536 
1537  if (m->msg_count == mdata->oldmsgcount)
1538  mutt_message(_("No more messages in the thread"));
1539 
1540  mdata->oldmsgcount = 0;
1541  mutt_debug(LL_DEBUG1, "nm: reading entire-thread messages... done [rc=%d, count=%d]\n",
1542  rc, m->msg_count);
1543  progress_free(&mdata->progress);
1544  return rc;
1545 }
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:427
#define mutt_message(...)
Definition: logging.h:86
void mailbox_changed(struct Mailbox *m, enum NotifyMailbox action)
Notify observers of a change to a Mailbox.
Definition: mailbox.c:222
@ NT_MAILBOX_INVALID
Email list was changed.
Definition: mailbox.h:177
#define FREE(x)
Definition: memory.h:43
#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:346
static void apply_exclude_tags(notmuch_query_t *query)
Exclude the configured tags.
Definition: notmuch.c:405
static notmuch_message_t * get_nm_message(notmuch_database_t *db, struct Email *e)
Find a Notmuch message.
Definition: notmuch.c:1031
static bool read_threads_query(struct Mailbox *m, notmuch_query_t *q, bool dedup, int limit)
Perform a query with threads.
Definition: notmuch.c:995
static void progress_setup(struct Mailbox *m)
Set up the Progress Bar.
Definition: notmuch.c:663
void progress_free(struct Progress **ptr)
Free a Progress Bar.
Definition: progress.c:86
struct timespec mtime
Time Mailbox was last changed.
Definition: mailbox.h:104
int msg_count
Total number of messages.
Definition: mailbox.h:88
long tv_nsec
Number of nanosecond, on top.
Definition: file.h:51
time_t tv_sec
Number of seconds since the epoch.
Definition: file.h:50
+ 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 1868 of file notmuch.c.

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

1738 {
1739  char buf[PATH_MAX];
1740  struct NmMboxData *mdata = nm_mdata_get(m);
1741  if (!mdata || !new_file)
1742  return -1;
1743 
1744  if (!old_file && nm_edata_get(e))
1745  {
1746  email_get_fullpath(e, buf, sizeof(buf));
1747  old_file = buf;
1748  }
1749 
1750  int rc = rename_filename(m, old_file, new_file, e);
1751 
1752  nm_db_release(m);
1753  m->mtime.tv_sec = mutt_date_epoch();
1754  m->mtime.tv_nsec = 0;
1755  return rc;
1756 }
#define PATH_MAX
Definition: mutt.h:40
static int rename_filename(struct Mailbox *m, const char *old_file, const char *new_file, struct Email *e)
Rename the file.
Definition: notmuch.c:1312
static char * email_get_fullpath(struct Email *e, char *buf, size_t buflen)
Get the full path of an email.
Definition: notmuch.c:224
+ 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 1555 of file notmuch.c.

1556 {
1557  mutt_debug(LL_DEBUG2, "(%s)\n", buf);
1558  struct NmMboxData *mdata = nm_mdata_get(m);
1559  char url[PATH_MAX + 1024 + 32]; /* path to DB + query + URL "decoration" */
1560  int added;
1561  bool using_default_data = false;
1562 
1563  // No existing data. Try to get a default NmMboxData.
1564  if (!mdata)
1565  {
1567 
1568  // Failed to get default data.
1569  if (!mdata)
1570  return NULL;
1571 
1572  using_default_data = true;
1573  }
1574 
1575  enum NmQueryType c_nm_query_type = nm_string_to_query_type(
1576  cs_subset_string(NeoMutt->sub, "nm_query_type"));
1577  mdata->query_type = nm_parse_type_from_query(buf, c_nm_query_type);
1578 
1579  const short c_nm_db_limit = cs_subset_number(NeoMutt->sub, "nm_db_limit");
1580  if (get_limit(mdata) == c_nm_db_limit)
1581  {
1582  added = snprintf(url, sizeof(url), "%s%s?type=%s&query=", NmUrlProtocol,
1584  }
1585  else
1586  {
1587  added = snprintf(url, sizeof(url), "%s%s?type=%s&limit=%d&query=", NmUrlProtocol,
1588  nm_db_get_filename(m),
1589  nm_query_type_to_string(mdata->query_type), get_limit(mdata));
1590  }
1591 
1592  if (added >= sizeof(url))
1593  {
1594  // snprintf output was truncated, so can't create URL
1595  return NULL;
1596  }
1597 
1598  url_pct_encode(&url[added], sizeof(url) - added, buf);
1599 
1600  mutt_str_copy(buf, url, buflen);
1601  buf[buflen - 1] = '\0';
1602 
1603  if (using_default_data)
1604  nm_mdata_free((void **) &mdata);
1605 
1606  mutt_debug(LL_DEBUG1, "nm: url from query '%s'\n", buf);
1607  return buf;
1608 }
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:629
void nm_mdata_free(void **ptr)
Free the private Mailbox data - Implements Mailbox::mdata_free()
Definition: mdata.c:46
static int get_limit(struct NmMboxData *mdata)
Get the database limit.
Definition: notmuch.c:396
static struct NmMboxData * nm_get_default_data(void)
Create a Mailbox with default Notmuch settings.
Definition: notmuch.c:163
const char NmUrlProtocol[]
Definition: notmuch.c:93
enum NmQueryType nm_string_to_query_type(const char *str)
Lookup a query type.
Definition: query.c:110
const char * nm_query_type_to_string(enum NmQueryType query_type)
Turn a query type into a string.
Definition: query.c:96
enum NmQueryType nm_parse_type_from_query(char *buf, enum NmQueryType fallback)
Parse a query type out of a query.
Definition: query.c:49
NmQueryType
Notmuch Query Types.
Definition: query.h:35
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: