NeoMutt  2021-02-05-666-ge300cd
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, 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:82
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 347 of file db.c.

348 {
349  struct NmAccountData *adata = nm_adata_get(m);
350  if (!adata || !adata->db)
351  return;
352 
353  mutt_debug(LL_DEBUG1, "nm: ERROR: db is open, closing\n");
354  nm_db_release(m);
355 }
notmuch_database_t * db
Definition: adata.h:36
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
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:196
Notmuch-specific Account data -.
Definition: adata.h:34
+ 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 329 of file db.c.

330 {
331  struct NmAccountData *adata = nm_adata_get(m);
332 
333  if (adata)
334  {
335  adata->longrun = false; /* to force nm_db_release() released DB */
336  if (nm_db_release(m) == 0)
337  mutt_debug(LL_DEBUG2, "nm: long run deinitialized\n");
338  else
339  adata->longrun = true;
340  }
341 }
bool longrun
A long-lived action is in progress.
Definition: adata.h:37
Log at debug level 2.
Definition: logging.h:41
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
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:196
Notmuch-specific Account data -.
Definition: adata.h:34
+ 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 314 of file db.c.

315 {
316  struct NmAccountData *adata = nm_adata_get(m);
317 
318  if (!(adata && nm_db_get(m, writable)))
319  return;
320 
321  adata->longrun = true;
322  mutt_debug(LL_DEBUG2, "nm: long run initialized\n");
323 }
bool longrun
A long-lived action is in progress.
Definition: adata.h:37
notmuch_database_t * nm_db_get(struct Mailbox *m, bool writable)
Get the Notmuch database.
Definition: db.c:172
Log at debug level 2.
Definition: logging.h:41
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
struct NmAccountData * nm_adata_get(struct Mailbox *m)
Get the Notmuch Account data.
Definition: adata.c:68
Notmuch-specific Account data -.
Definition: adata.h:34
+ 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 1458 of file notmuch.c.

1459 {
1460  struct NmEmailData *edata = nm_edata_get(e);
1461  if (!edata)
1462  return NULL;
1463 
1464  return edata->folder;
1465 }
struct NmEmailData * nm_edata_get(struct Email *e)
Get the Notmuch Email data.
Definition: edata.c:72
char * folder
Location of the Email.
Definition: edata.h:35
Notmuch-specific Email data -.
Definition: edata.h:33
void * edata
Driver-specific data.
Definition: email.h:111
+ 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 1477 of file notmuch.c.

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

1978 {
1979  struct NmMboxData *mdata = nm_mdata_get(m);
1980  if (!mdata)
1981  return -1;
1982 
1983  notmuch_database_t *db = NULL;
1984  notmuch_tags_t *tags = NULL;
1985  const char *tag = NULL;
1986  int rc = -1;
1987 
1988  if (!(db = nm_db_get(m, false)) || !(tags = notmuch_database_get_all_tags(db)))
1989  goto done;
1990 
1991  *tag_count = 0;
1992  mutt_debug(LL_DEBUG1, "nm: get all tags\n");
1993 
1994  while (notmuch_tags_valid(tags))
1995  {
1996  tag = notmuch_tags_get(tags);
1997  /* Skip empty string */
1998  if (*tag)
1999  {
2000  if (tag_list)
2001  tag_list[*tag_count] = mutt_str_dup(tag);
2002  (*tag_count)++;
2003  }
2004  notmuch_tags_move_to_next(tags);
2005  }
2006 
2007  rc = 0;
2008 done:
2009  if (tags)
2010  notmuch_tags_destroy(tags);
2011 
2012  nm_db_release(m);
2013 
2014  mutt_debug(LL_DEBUG1, "nm: get all tags done [rc=%d tag_count=%u]\n", rc, *tag_count);
2015  return rc;
2016 }
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
notmuch_database_t * nm_db_get(struct Mailbox *m, bool writable)
Get the Notmuch database.
Definition: db.c:172
Notmuch-specific Mailbox data -.
Definition: mdata.h:33
void * mdata
Driver specific data.
Definition: mailbox.h:136
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition: mdata.c:98
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
Log at debug level 1.
Definition: logging.h:40
int nm_db_release(struct Mailbox *m)
Close the Notmuch database.
Definition: db.c:196
+ 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 1685 of file notmuch.c.

1686 {
1687  struct NmMboxData *mdata = nm_mdata_get(m);
1688  notmuch_database_t *db = nm_db_get(m, false);
1689  char *orig_str = get_query_string(mdata, true);
1690 
1691  if (!db || !orig_str)
1692  return false;
1693 
1694  char *new_str = NULL;
1695  bool rc = false;
1696  if (mutt_str_asprintf(&new_str, "id:%s and (%s)", email_get_id(e), orig_str) < 0)
1697  return false;
1698 
1699  mutt_debug(LL_DEBUG2, "nm: checking if message is still queried: %s\n", new_str);
1700 
1701  notmuch_query_t *q = notmuch_query_create(db, new_str);
1702 
1703  switch (mdata->query_type)
1704  {
1705  case NM_QUERY_TYPE_UNKNOWN: // UNKNOWN should never occur, but MESGS is default
1706  case NM_QUERY_TYPE_MESGS:
1707  {
1708  notmuch_messages_t *messages = get_messages(q);
1709 
1710  if (!messages)
1711  return false;
1712 
1713  rc = notmuch_messages_valid(messages);
1714  notmuch_messages_destroy(messages);
1715  break;
1716  }
1717  case NM_QUERY_TYPE_THREADS:
1718  {
1719  notmuch_threads_t *threads = get_threads(q);
1720 
1721  if (!threads)
1722  return false;
1723 
1724  rc = notmuch_threads_valid(threads);
1725  notmuch_threads_destroy(threads);
1726  break;
1727  }
1728  }
1729 
1730  notmuch_query_destroy(q);
1731 
1732  mutt_debug(LL_DEBUG2, "nm: checking if message is still queried: %s = %s\n",
1733  new_str, rc ? "true" : "false");
1734 
1735  return rc;
1736 }
static notmuch_threads_t * get_threads(notmuch_query_t *query)
load threads for a query
Definition: notmuch.c:973
notmuch_database_t * nm_db_get(struct Mailbox *m, bool writable)
Get the Notmuch database.
Definition: db.c:172
Log at debug level 2.
Definition: logging.h:41
Notmuch-specific Mailbox data -.
Definition: mdata.h:33
static char * email_get_id(struct Email *e)
Get the unique Notmuch Id.
Definition: notmuch.c:210
static notmuch_messages_t * get_messages(notmuch_query_t *query)
load messages for a query
Definition: notmuch.c:903
void * mdata
Driver specific data.
Definition: mailbox.h:136
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition: mdata.c:98
static char * get_query_string(struct NmMboxData *mdata, bool window)
builds the notmuch vfolder search string
Definition: notmuch.c:343
Default: Messages only.
Definition: query.h:36
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
Unknown query type. Error in notmuch query.
Definition: query.h:38
Whole threads.
Definition: query.h:37
int mutt_str_asprintf(char **strp, const char *fmt,...)
Definition: string.c:1128
enum NmQueryType query_type
Messages or Threads.
Definition: mdata.h:38
+ 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 1621 of file notmuch.c.

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

1662 {
1663  const short c_nm_query_window_current_position =
1664  cs_subset_number(NeoMutt->sub, "nm_query_window_current_position");
1665  cs_subset_str_native_set(NeoMutt->sub, "nm_query_window_current_position",
1666  c_nm_query_window_current_position + 1, NULL);
1667  mutt_debug(LL_DEBUG2, "(%d)\n", c_nm_query_window_current_position + 1);
1668 }
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:169
Container for Accounts, Notifications.
Definition: neomutt.h:36
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
Log at debug level 2.
Definition: logging.h:41
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
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_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 1640 of file notmuch.c.

1641 {
1642  const short c_nm_query_window_current_position =
1643  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 }
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:169
Container for Accounts, Notifications.
Definition: neomutt.h:36
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
Log at debug level 2.
Definition: logging.h:41
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
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_reset()

void nm_query_window_reset ( void  )

Resets the vfolder window position to the present.

Definition at line 1673 of file notmuch.c.

1674 {
1675  cs_subset_str_native_set(NeoMutt->sub, "nm_query_window_current_position", 0, NULL);
1676  mutt_debug(LL_DEBUG2, "Reset nm_query_window_current_position to 0\n");
1677 }
Container for Accounts, Notifications.
Definition: neomutt.h:36
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
Log at debug level 2.
Definition: logging.h:41
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
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_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 1497 of file notmuch.c.

1498 {
1499  if (!m)
1500  return -1;
1501 
1502  struct NmMboxData *mdata = nm_mdata_get(m);
1503  if (!mdata)
1504  return -1;
1505 
1506  notmuch_query_t *q = NULL;
1507  notmuch_database_t *db = NULL;
1508  notmuch_message_t *msg = NULL;
1509  int rc = -1;
1510 
1511  if (!(db = nm_db_get(m, false)) || !(msg = get_nm_message(db, e)))
1512  goto done;
1513 
1514  mutt_debug(LL_DEBUG1, "nm: reading entire-thread messages...[current count=%d]\n",
1515  m->msg_count);
1516 
1517  progress_setup(m);
1518  const char *id = notmuch_message_get_thread_id(msg);
1519  if (!id)
1520  goto done;
1521 
1522  char *qstr = NULL;
1523  mutt_str_append_item(&qstr, "thread:", '\0');
1524  mutt_str_append_item(&qstr, id, '\0');
1525 
1526  q = notmuch_query_create(db, qstr);
1527  FREE(&qstr);
1528  if (!q)
1529  goto done;
1530  apply_exclude_tags(q);
1531  notmuch_query_set_sort(q, NOTMUCH_SORT_NEWEST_FIRST);
1532 
1533  read_threads_query(m, q, true, 0);
1534  m->mtime.tv_sec = mutt_date_epoch();
1535  m->mtime.tv_nsec = 0;
1536  rc = 0;
1537 
1538  if (m->msg_count > mdata->oldmsgcount)
1540 done:
1541  if (q)
1542  notmuch_query_destroy(q);
1543 
1544  nm_db_release(m);
1545 
1546  if (m->msg_count == mdata->oldmsgcount)
1547  mutt_message(_("No more messages in the thread"));
1548 
1549  mdata->oldmsgcount = 0;
1550  mutt_debug(LL_DEBUG1, "nm: reading entire-thread messages... done [rc=%d, count=%d]\n",
1551  rc, m->msg_count);
1552  progress_free(&mdata->progress);
1553  return rc;
1554 }
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:427
int msg_count
Total number of messages.
Definition: mailbox.h:91
static void progress_setup(struct Mailbox *m)
Set up the Progress Bar.
Definition: notmuch.c:668
struct timespec mtime
Time Mailbox was last changed.
Definition: mailbox.h:107
#define _(a)
Definition: message.h:28
Email list was changed.
Definition: mailbox.h:180
notmuch_database_t * nm_db_get(struct Mailbox *m, bool writable)
Get the Notmuch database.
Definition: db.c:172
time_t tv_sec
Definition: file.h:50
int oldmsgcount
Definition: mdata.h:41
Notmuch-specific Mailbox data -.
Definition: mdata.h:33
long tv_nsec
Definition: file.h:51
struct Progress * progress
A progress bar.
Definition: mdata.h:40
void * mdata
Driver specific data.
Definition: mailbox.h:136
static notmuch_message_t * get_nm_message(notmuch_database_t *db, struct Email *e)
Find a Notmuch message.
Definition: notmuch.c:1037
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition: mdata.c:98
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void progress_free(struct Progress **ptr)
Free a Progress Bar.
Definition: progress.c:228
Log at debug level 1.
Definition: logging.h:40
int nm_db_release(struct Mailbox *m)
Close the Notmuch database.
Definition: db.c:196
#define mutt_message(...)
Definition: logging.h:87
#define FREE(x)
Definition: memory.h:40
void mutt_str_append_item(char **str, const char *item, char sep)
Add string to another separated by sep.
Definition: string.c:466
static void apply_exclude_tags(notmuch_query_t *query)
Exclude the configured tags.
Definition: notmuch.c:413
void mailbox_changed(struct Mailbox *m, enum NotifyMailbox action)
Notify observers of a change to a Mailbox.
Definition: mailbox.c:208
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
+ 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 1894 of file notmuch.c.

1895 {
1896  notmuch_database_t *db = NULL;
1897  notmuch_status_t st;
1898  notmuch_message_t *msg = NULL;
1899  int rc = -1;
1900 
1901  struct NmMboxData *mdata = nm_mdata_get(m);
1902 
1903  // If no notmuch data, fall back to the default mailbox.
1904  //
1905  // IMPORTANT: DO NOT FREE THIS MAILBOX. Two reasons:
1906  // 1) If user has default mailbox in config, we'll be removing it. That's not
1907  // good program behavior!
1908  // 2) If not in user's config, keep mailbox around for future nm_record calls.
1909  // It saves NeoMutt from allocating/deallocating repeatedly.
1910  if (!mdata)
1911  {
1912  mutt_debug(LL_DEBUG1, "nm: non-nm mailbox. trying the default nm mailbox.");
1913  m = get_default_mailbox();
1914  mdata = nm_mdata_get(m);
1915  }
1916 
1917  if (!path || !mdata || (access(path, F_OK) != 0))
1918  return 0;
1919  db = nm_db_get(m, true);
1920  if (!db)
1921  return -1;
1922 
1923  mutt_debug(LL_DEBUG1, "nm: record message: %s\n", path);
1924  int trans = nm_db_trans_begin(m);
1925  if (trans < 0)
1926  goto done;
1927 
1928 #ifdef HAVE_NOTMUCH_DATABASE_INDEX_FILE
1929  st = notmuch_database_index_file(db, path, NULL, &msg);
1930 #else
1931  st = notmuch_database_add_message(db, path, &msg);
1932 #endif
1933 
1934  if ((st != NOTMUCH_STATUS_SUCCESS) && (st != NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID))
1935  {
1936  mutt_debug(LL_DEBUG1, "nm: failed to add '%s' [st=%d]\n", path, (int) st);
1937  goto done;
1938  }
1939 
1940  if ((st == NOTMUCH_STATUS_SUCCESS) && msg)
1941  {
1942  notmuch_message_maildir_flags_to_tags(msg);
1943  if (e)
1944  {
1945  char *tags = driver_tags_get(&e->tags);
1946  update_tags(msg, tags);
1947  FREE(&tags);
1948  }
1949  const char *const c_nm_record_tags =
1950  cs_subset_string(NeoMutt->sub, "nm_record_tags");
1951  if (c_nm_record_tags)
1952  update_tags(msg, c_nm_record_tags);
1953  }
1954 
1955  rc = 0;
1956 done:
1957  if (msg)
1958  notmuch_message_destroy(msg);
1959  if (trans == 1)
1960  nm_db_trans_end(m);
1961 
1962  nm_db_release(m);
1963 
1964  return rc;
1965 }
static struct Mailbox * get_default_mailbox(void)
Get Mailbox for notmuch without any parameters.
Definition: notmuch.c:1871
int nm_db_trans_begin(struct Mailbox *m)
Start a Notmuch database transaction.
Definition: db.c:229
Container for Accounts, Notifications.
Definition: neomutt.h:36
notmuch_database_t * nm_db_get(struct Mailbox *m, bool writable)
Get the Notmuch database.
Definition: db.c:172
Notmuch-specific Mailbox data -.
Definition: mdata.h:33
static int update_tags(notmuch_message_t *msg, const char *tag_str)
Update the tags on a message.
Definition: notmuch.c:1095
void * mdata
Driver specific data.
Definition: mailbox.h:136
struct TagList tags
For drivers that support server tagging.
Definition: email.h:109
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition: mdata.c:98
int nm_db_trans_end(struct Mailbox *m)
End a database transaction.
Definition: db.c:251
char * driver_tags_get(struct TagList *list)
Get tags.
Definition: tags.c:145
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
Log at debug level 1.
Definition: logging.h:40
int nm_db_release(struct Mailbox *m)
Close the Notmuch database.
Definition: db.c:196
#define FREE(x)
Definition: memory.h:40
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_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 1747 of file notmuch.c.

1749 {
1750  char buf[PATH_MAX];
1751  struct NmMboxData *mdata = nm_mdata_get(m);
1752  if (!mdata || !new_file)
1753  return -1;
1754 
1755  if (!old_file && nm_edata_get(e))
1756  {
1757  email_get_fullpath(e, buf, sizeof(buf));
1758  old_file = buf;
1759  }
1760 
1761  int rc = rename_filename(m, old_file, new_file, e);
1762 
1763  nm_db_release(m);
1764  m->mtime.tv_sec = mutt_date_epoch();
1765  m->mtime.tv_nsec = 0;
1766  return rc;
1767 }
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:427
struct timespec mtime
Time Mailbox was last changed.
Definition: mailbox.h:107
time_t tv_sec
Definition: file.h:50
struct NmEmailData * nm_edata_get(struct Email *e)
Get the Notmuch Email data.
Definition: edata.c:72
Notmuch-specific Mailbox data -.
Definition: mdata.h:33
long tv_nsec
Definition: file.h:51
void * mdata
Driver specific data.
Definition: mailbox.h:136
static int rename_filename(struct Mailbox *m, const char *old_file, const char *new_file, struct Email *e)
Rename the file.
Definition: notmuch.c:1321
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition: mdata.c:98
#define PATH_MAX
Definition: mutt.h:40
int nm_db_release(struct Mailbox *m)
Close the Notmuch database.
Definition: db.c:196
static char * email_get_fullpath(struct Email *e, char *buf, size_t buflen)
Get the full path of an email.
Definition: notmuch.c:226
+ 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 1564 of file notmuch.c.

1565 {
1566  mutt_debug(LL_DEBUG2, "(%s)\n", buf);
1567  struct NmMboxData *mdata = nm_mdata_get(m);
1568  char url[PATH_MAX + 1024 + 32]; /* path to DB + query + URL "decoration" */
1569  int added;
1570  bool using_default_data = false;
1571 
1572  // No existing data. Try to get a default NmMboxData.
1573  if (!mdata)
1574  {
1575  mdata = nm_get_default_data();
1576 
1577  // Failed to get default data.
1578  if (!mdata)
1579  return NULL;
1580 
1581  using_default_data = true;
1582  }
1583 
1584  mdata->query_type = nm_parse_type_from_query(buf);
1585 
1586  const short c_nm_db_limit = cs_subset_number(NeoMutt->sub, "nm_db_limit");
1587  if (get_limit(mdata) == c_nm_db_limit)
1588  {
1589  added = snprintf(url, sizeof(url), "%s%s?type=%s&query=", NmUrlProtocol,
1591  }
1592  else
1593  {
1594  added = snprintf(url, sizeof(url), "%s%s?type=%s&limit=%d&query=", NmUrlProtocol,
1595  nm_db_get_filename(m),
1596  nm_query_type_to_string(mdata->query_type), get_limit(mdata));
1597  }
1598 
1599  if (added >= sizeof(url))
1600  {
1601  // snprintf output was truncated, so can't create URL
1602  return NULL;
1603  }
1604 
1605  url_pct_encode(&url[added], sizeof(url) - added, buf);
1606 
1607  mutt_str_copy(buf, url, buflen);
1608  buf[buflen - 1] = '\0';
1609 
1610  if (using_default_data)
1611  nm_mdata_free((void **) &mdata);
1612 
1613  mutt_debug(LL_DEBUG1, "nm: url from query '%s'\n", buf);
1614  return buf;
1615 }
const char * nm_query_type_to_string(enum NmQueryType query_type)
Turn a query type into a string.
Definition: query.c:95
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:169
Container for Accounts, Notifications.
Definition: neomutt.h:36
void nm_mdata_free(void **ptr)
Free the private Mailbox data - Implements Mailbox::mdata_free()
Definition: mdata.c:46
Log at debug level 2.
Definition: logging.h:41
static int get_limit(struct NmMboxData *mdata)
Get the database limit.
Definition: notmuch.c:404
Notmuch-specific Mailbox data -.
Definition: mdata.h:33
enum NmQueryType nm_parse_type_from_query(char *buf)
Parse a query type out of a query.
Definition: query.c:48
void * mdata
Driver specific data.
Definition: mailbox.h:136
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition: mdata.c:98
void url_pct_encode(char *buf, size_t buflen, const char *src)
Percent-encode a string.
Definition: url.c:151
#define PATH_MAX
Definition: mutt.h:40
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
const char NmUrlProtocol[]
Definition: notmuch.c:93
Log at debug level 1.
Definition: logging.h:40
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:749
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
static struct NmMboxData * nm_get_default_data(void)
Create a Mailbox with default Notmuch settings.
Definition: notmuch.c:165
enum NmQueryType query_type
Messages or Threads.
Definition: mdata.h:38
const char * nm_db_get_filename(struct Mailbox *m)
Get the filename of the Notmuch database.
Definition: db.c:57
+ Here is the call graph for this function:
+ Here is the caller graph for this function: