NeoMutt  2020-11-20
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 "mx.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...
 
void nm_parse_type_from_query (struct NmMboxData *mdata, char *buf)
 Parse a query type out of a query. More...
 
enum MailboxType nm_path_probe (const char *path, const struct stat *st)
 Is this a Notmuch Mailbox? - Implements MxOps::path_probe() 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...
 
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...
 
bool config_init_notmuch (struct ConfigSet *cs)
 Register notmuch config variables - Implements module_init_config_t. More...
 

Variables

struct MxOps MxNotmuchOps
 Notmuch Mailbox - Implements MxOps. More...
 
char * C_NmQueryWindowCurrentSearch
 Config: (notmuch) Current search parameters. More...
 
int C_NmQueryWindowDuration
 Config: (notmuch) Time duration of the current search window. More...
 
char * C_VfolderFormat
 Config: (notmuch) printf-like format string for the browser's display of virtual folders. More...
 
bool C_VirtualSpoolfile
 Config: (notmuch) Use the first virtual mailbox as a spool file. 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 88 of file notmuch.c.

89 {
91 }
#define COMMANDS_REGISTER(cmds)
Definition: mutt_commands.h:77
static const struct Command nm_commands[]
Definition: notmuch.c:75
+ 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 322 of file db.c.

323 {
324  struct NmAccountData *adata = nm_adata_get(m);
325  if (!adata || !adata->db)
326  return;
327 
328  mutt_debug(LL_DEBUG1, "nm: ERROR: db is open, closing\n");
329  nm_db_release(m);
330 }
notmuch_database_t * db
Definition: private.h:50
struct NmAccountData * nm_adata_get(struct Mailbox *m)
Get the Notmuch Account data.
Definition: notmuch.c:169
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
Log at debug level 1.
Definition: logging.h:40
int nm_db_release(struct Mailbox *m)
Close the Notmuch database.
Definition: db.c:171
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
Notmuch-specific Account data -.
Definition: private.h:48
+ 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 304 of file db.c.

305 {
306  struct NmAccountData *adata = nm_adata_get(m);
307 
308  if (adata)
309  {
310  adata->longrun = false; /* to force nm_db_release() released DB */
311  if (nm_db_release(m) == 0)
312  mutt_debug(LL_DEBUG2, "nm: long run deinitialized\n");
313  else
314  adata->longrun = true;
315  }
316 }
bool longrun
A long-lived action is in progress.
Definition: private.h:51
struct NmAccountData * nm_adata_get(struct Mailbox *m)
Get the Notmuch Account data.
Definition: notmuch.c:169
Log at debug level 2.
Definition: logging.h:41
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
int nm_db_release(struct Mailbox *m)
Close the Notmuch database.
Definition: db.c:171
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
Notmuch-specific Account data -.
Definition: private.h:48
+ 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 289 of file db.c.

290 {
291  struct NmAccountData *adata = nm_adata_get(m);
292 
293  if (!(adata && nm_db_get(m, writable)))
294  return;
295 
296  adata->longrun = true;
297  mutt_debug(LL_DEBUG2, "nm: long run initialized\n");
298 }
bool longrun
A long-lived action is in progress.
Definition: private.h:51
notmuch_database_t * nm_db_get(struct Mailbox *m, bool writable)
Get the Notmuch database.
Definition: db.c:147
struct NmAccountData * nm_adata_get(struct Mailbox *m)
Get the Notmuch Account data.
Definition: notmuch.c:169
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:81
Notmuch-specific Account data -.
Definition: private.h:48
+ 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 1669 of file notmuch.c.

1670 {
1671  struct NmEmailData *edata = nm_edata_get(e);
1672  if (!edata)
1673  return NULL;
1674 
1675  return edata->folder;
1676 }
struct NmEmailData * nm_edata_get(struct Email *e)
Get the Notmuch Email data.
Definition: notmuch.c:281
char * folder
Location of the Email.
Definition: private.h:89
Notmuch-specific Email data -.
Definition: private.h:87
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 1688 of file notmuch.c.

1689 {
1690  char *full_folder = nm_email_get_folder(e);
1691  if (!full_folder)
1692  return NULL;
1693 
1694  const char *db_path = nm_db_get_filename(m);
1695  if (!db_path)
1696  return NULL;
1697 
1698  return full_folder + strlen(db_path);
1699 }
char * nm_email_get_folder(struct Email *e)
Get the folder for a Email.
Definition: notmuch.c:1669
const char * nm_db_get_filename(struct Mailbox *m)
Get the filename of the Notmuch database.
Definition: db.c:53
+ 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 2141 of file notmuch.c.

2142 {
2143  struct NmMboxData *mdata = nm_mdata_get(m);
2144  if (!mdata)
2145  return -1;
2146 
2147  notmuch_database_t *db = NULL;
2148  notmuch_tags_t *tags = NULL;
2149  const char *tag = NULL;
2150  int rc = -1;
2151 
2152  if (!(db = nm_db_get(m, false)) || !(tags = notmuch_database_get_all_tags(db)))
2153  goto done;
2154 
2155  *tag_count = 0;
2156  mutt_debug(LL_DEBUG1, "nm: get all tags\n");
2157 
2158  while (notmuch_tags_valid(tags))
2159  {
2160  tag = notmuch_tags_get(tags);
2161  /* Skip empty string */
2162  if (*tag)
2163  {
2164  if (tag_list)
2165  tag_list[*tag_count] = mutt_str_dup(tag);
2166  (*tag_count)++;
2167  }
2168  notmuch_tags_move_to_next(tags);
2169  }
2170 
2171  rc = 0;
2172 done:
2173  if (tags)
2174  notmuch_tags_destroy(tags);
2175 
2176  nm_db_release(m);
2177 
2178  mutt_debug(LL_DEBUG1, "nm: get all tags done [rc=%d tag_count=%u]\n", rc, *tag_count);
2179  return rc;
2180 }
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:147
Notmuch-specific Mailbox data -.
Definition: private.h:69
void * mdata
Driver specific data.
Definition: mailbox.h:136
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition: notmuch.c:236
Log at debug level 1.
Definition: logging.h:40
int nm_db_release(struct Mailbox *m)
Close the Notmuch database.
Definition: db.c:171
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
+ 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 1896 of file notmuch.c.

1897 {
1898  struct NmMboxData *mdata = nm_mdata_get(m);
1899  notmuch_database_t *db = nm_db_get(m, false);
1900  char *orig_str = get_query_string(mdata, true);
1901 
1902  if (!db || !orig_str)
1903  return false;
1904 
1905  char *new_str = NULL;
1906  bool rc = false;
1907  if (mutt_str_asprintf(&new_str, "id:%s and (%s)", email_get_id(e), orig_str) < 0)
1908  return false;
1909 
1910  mutt_debug(LL_DEBUG2, "nm: checking if message is still queried: %s\n", new_str);
1911 
1912  notmuch_query_t *q = notmuch_query_create(db, new_str);
1913 
1914  switch (mdata->query_type)
1915  {
1916  case NM_QUERY_TYPE_MESGS:
1917  {
1918  notmuch_messages_t *messages = get_messages(q);
1919 
1920  if (!messages)
1921  return false;
1922 
1923  rc = notmuch_messages_valid(messages);
1924  notmuch_messages_destroy(messages);
1925  break;
1926  }
1927  case NM_QUERY_TYPE_THREADS:
1928  {
1929  notmuch_threads_t *threads = get_threads(q);
1930 
1931  if (!threads)
1932  return false;
1933 
1934  rc = notmuch_threads_valid(threads);
1935  notmuch_threads_destroy(threads);
1936  break;
1937  }
1938  }
1939 
1940  notmuch_query_destroy(q);
1941 
1942  mutt_debug(LL_DEBUG2, "nm: checking if message is still queried: %s = %s\n",
1943  new_str, rc ? "true" : "false");
1944 
1945  return rc;
1946 }
static notmuch_threads_t * get_threads(notmuch_query_t *query)
load threads for a query
Definition: notmuch.c:1162
notmuch_database_t * nm_db_get(struct Mailbox *m, bool writable)
Get the Notmuch database.
Definition: db.c:147
Log at debug level 2.
Definition: logging.h:41
Notmuch-specific Mailbox data -.
Definition: private.h:69
static char * email_get_id(struct Email *e)
Get the unique Notmuch Id.
Definition: notmuch.c:343
static notmuch_messages_t * get_messages(notmuch_query_t *query)
load messages for a query
Definition: notmuch.c:1092
void * mdata
Driver specific data.
Definition: mailbox.h:136
static char * get_query_string(struct NmMboxData *mdata, bool window)
builds the notmuch vfolder search string
Definition: notmuch.c:513
Default: Messages only.
Definition: private.h:62
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition: notmuch.c:236
Whole threads.
Definition: private.h:63
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
int mutt_str_asprintf(char **strp, const char *fmt,...)
Definition: string.c:1095
enum NmQueryType query_type
Messages or Threads.
Definition: private.h:74
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nm_parse_type_from_query()

void nm_parse_type_from_query ( struct NmMboxData mdata,
char *  buf 
)

Parse a query type out of a query.

Parameters
mdataMailbox, used for the query_type
bufBuffer for URL

If a user writes a query for a vfolder and includes a type= statement, that type= will be encoded, which Notmuch will treat as part of the query= statement. This method will remove the type= and set it within the Mailbox struct.

Definition at line 1776 of file notmuch.c.

1777 {
1778  if (!buf)
1779  return;
1780 
1781  // The six variations of how type= could appear.
1782  const char *variants[6] = { "&type=threads", "&type=messages",
1783  "type=threads&", "type=messages&",
1784  "type=threads", "type=messages" };
1785 
1786  int variants_size = mutt_array_size(variants);
1787  for (int i = 0; i < variants_size; i++)
1788  {
1789  if (strcasestr(buf, variants[i]) != NULL)
1790  {
1791  // variants[] is setup such that type can be determined via modulo 2.
1792  mdata->query_type = ((i % 2) == 0) ? NM_QUERY_TYPE_THREADS : NM_QUERY_TYPE_MESGS;
1793 
1794  mutt_istr_remall(buf, variants[i]);
1795  }
1796  }
1797 }
#define mutt_array_size(x)
Definition: memory.h:33
int mutt_istr_remall(char *str, const char *target)
Remove all occurrences of substring, ignoring case.
Definition: string.c:1037
Default: Messages only.
Definition: private.h:62
Whole threads.
Definition: private.h:63
enum NmQueryType query_type
Messages or Threads.
Definition: private.h:74
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nm_path_probe()

enum MailboxType nm_path_probe ( const char *  path,
const struct stat *  st 
)

Is this a Notmuch Mailbox? - Implements MxOps::path_probe()

Definition at line 2617 of file notmuch.c.

2618 {
2619  if (!mutt_istr_startswith(path, NmUrlProtocol))
2620  return MUTT_UNKNOWN;
2621 
2622  return MUTT_NOTMUCH;
2623 }
Mailbox wasn&#39;t recognised.
Definition: mailbox.h:47
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:172
&#39;Notmuch&#39; (virtual) Mailbox type
Definition: mailbox.h:54
const char NmUrlProtocol[]
Definition: notmuch.c:82
+ 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 1884 of file notmuch.c.

1885 {
1888 }
Log at debug level 2.
Definition: logging.h:41
int C_NmQueryWindowCurrentPosition
Config: (notmuch) Position of current search window.
Definition: config.c:43
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
+ 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 1868 of file notmuch.c.

1869 {
1872 
1874 }
Log at debug level 2.
Definition: logging.h:41
int C_NmQueryWindowCurrentPosition
Config: (notmuch) Position of current search window.
Definition: config.c:43
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
+ 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 1708 of file notmuch.c.

1709 {
1710  if (!m)
1711  return -1;
1712 
1713  struct NmMboxData *mdata = nm_mdata_get(m);
1714  if (!mdata)
1715  return -1;
1716 
1717  notmuch_query_t *q = NULL;
1718  notmuch_database_t *db = NULL;
1719  notmuch_message_t *msg = NULL;
1720  int rc = -1;
1721 
1722  if (!(db = nm_db_get(m, false)) || !(msg = get_nm_message(db, e)))
1723  goto done;
1724 
1725  mutt_debug(LL_DEBUG1, "nm: reading entire-thread messages...[current count=%d]\n",
1726  m->msg_count);
1727 
1728  progress_reset(m);
1729  const char *id = notmuch_message_get_thread_id(msg);
1730  if (!id)
1731  goto done;
1732 
1733  char *qstr = NULL;
1734  mutt_str_append_item(&qstr, "thread:", '\0');
1735  mutt_str_append_item(&qstr, id, '\0');
1736 
1737  q = notmuch_query_create(db, qstr);
1738  FREE(&qstr);
1739  if (!q)
1740  goto done;
1741  apply_exclude_tags(q);
1742  notmuch_query_set_sort(q, NOTMUCH_SORT_NEWEST_FIRST);
1743 
1744  read_threads_query(m, q, true, 0);
1745  m->mtime.tv_sec = mutt_date_epoch();
1746  m->mtime.tv_nsec = 0;
1747  rc = 0;
1748 
1749  if (m->msg_count > mdata->oldmsgcount)
1751 done:
1752  if (q)
1753  notmuch_query_destroy(q);
1754 
1755  nm_db_release(m);
1756 
1757  if (m->msg_count == mdata->oldmsgcount)
1758  mutt_message(_("No more messages in the thread"));
1759 
1760  mdata->oldmsgcount = 0;
1761  mutt_debug(LL_DEBUG1, "nm: reading entire-thread messages... done [rc=%d, count=%d]\n",
1762  rc, m->msg_count);
1763  return rc;
1764 }
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:416
int msg_count
Total number of messages.
Definition: mailbox.h:91
static void progress_reset(struct Mailbox *m)
Reset the progress counter.
Definition: notmuch.c:848
#define mutt_message(...)
Definition: logging.h:83
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:173
notmuch_database_t * nm_db_get(struct Mailbox *m, bool writable)
Get the Notmuch database.
Definition: db.c:147
time_t tv_sec
Definition: file.h:48
int oldmsgcount
Definition: private.h:77
Notmuch-specific Mailbox data -.
Definition: private.h:69
long tv_nsec
Definition: file.h:49
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:1226
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition: notmuch.c:236
Log at debug level 1.
Definition: logging.h:40
int nm_db_release(struct Mailbox *m)
Close the Notmuch database.
Definition: db.c:171
#define FREE(x)
Definition: memory.h:40
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
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:580
void mailbox_changed(struct Mailbox *m, enum NotifyMailbox action)
Notify observers of a change to a Mailbox.
Definition: mailbox.c:177
static bool read_threads_query(struct Mailbox *m, notmuch_query_t *q, bool dedup, int limit)
Perform a query with threads.
Definition: notmuch.c:1190
+ 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 2076 of file notmuch.c.

2077 {
2078  notmuch_database_t *db = NULL;
2079  notmuch_status_t st;
2080  notmuch_message_t *msg = NULL;
2081  int rc = -1;
2082  struct NmMboxData *mdata = nm_mdata_get(m);
2083 
2084  if (!path || !mdata || (access(path, F_OK) != 0))
2085  return 0;
2086  db = nm_db_get(m, true);
2087  if (!db)
2088  return -1;
2089 
2090  mutt_debug(LL_DEBUG1, "nm: record message: %s\n", path);
2091  int trans = nm_db_trans_begin(m);
2092  if (trans < 0)
2093  goto done;
2094 
2095 #ifdef HAVE_NOTMUCH_DATABASE_INDEX_FILE
2096  st = notmuch_database_index_file(db, path, NULL, &msg);
2097 #else
2098  st = notmuch_database_add_message(db, path, &msg);
2099 #endif
2100 
2101  if ((st != NOTMUCH_STATUS_SUCCESS) && (st != NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID))
2102  {
2103  mutt_debug(LL_DEBUG1, "nm: failed to add '%s' [st=%d]\n", path, (int) st);
2104  goto done;
2105  }
2106 
2107  if ((st == NOTMUCH_STATUS_SUCCESS) && msg)
2108  {
2109  notmuch_message_maildir_flags_to_tags(msg);
2110  if (e)
2111  {
2112  char *tags = driver_tags_get(&e->tags);
2113  update_tags(msg, tags);
2114  FREE(&tags);
2115  }
2116  if (C_NmRecordTags)
2118  }
2119 
2120  rc = 0;
2121 done:
2122  if (msg)
2123  notmuch_message_destroy(msg);
2124  if (trans == 1)
2125  nm_db_trans_end(m);
2126 
2127  nm_db_release(m);
2128  return rc;
2129 }
static int update_tags(notmuch_message_t *msg, const char *tags)
Update the tags on a message.
Definition: notmuch.c:1284
int nm_db_trans_begin(struct Mailbox *m)
Start a Notmuch database transaction.
Definition: db.c:204
notmuch_database_t * nm_db_get(struct Mailbox *m, bool writable)
Get the Notmuch database.
Definition: db.c:147
Notmuch-specific Mailbox data -.
Definition: private.h:69
void * mdata
Driver specific data.
Definition: mailbox.h:136
struct TagList tags
For drivers that support server tagging.
Definition: email.h:109
int nm_db_trans_end(struct Mailbox *m)
End a database transaction.
Definition: db.c:226
char * driver_tags_get(struct TagList *list)
Get tags.
Definition: tags.c:142
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition: notmuch.c:236
Log at debug level 1.
Definition: logging.h:40
int nm_db_release(struct Mailbox *m)
Close the Notmuch database.
Definition: db.c:171
#define FREE(x)
Definition: memory.h:40
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
char * C_NmRecordTags
Config: (notmuch) Tags to apply to the &#39;record&#39; mailbox (sent mail)
Definition: config.c:47
+ 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 1957 of file notmuch.c.

1959 {
1960  char buf[PATH_MAX];
1961  struct NmMboxData *mdata = nm_mdata_get(m);
1962  if (!mdata || !new_file)
1963  return -1;
1964 
1965  if (!old_file && nm_edata_get(e))
1966  {
1967  email_get_fullpath(e, buf, sizeof(buf));
1968  old_file = buf;
1969  }
1970 
1971  int rc = rename_filename(m, old_file, new_file, e);
1972 
1973  nm_db_release(m);
1974  m->mtime.tv_sec = mutt_date_epoch();
1975  m->mtime.tv_nsec = 0;
1976  return rc;
1977 }
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:416
struct timespec mtime
Time Mailbox was last changed.
Definition: mailbox.h:107
time_t tv_sec
Definition: file.h:48
struct NmEmailData * nm_edata_get(struct Email *e)
Get the Notmuch Email data.
Definition: notmuch.c:281
Notmuch-specific Mailbox data -.
Definition: private.h:69
long tv_nsec
Definition: file.h:49
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:1532
#define PATH_MAX
Definition: mutt.h:44
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition: notmuch.c:236
int nm_db_release(struct Mailbox *m)
Close the Notmuch database.
Definition: db.c:171
static char * email_get_fullpath(struct Email *e, char *buf, size_t buflen)
Get the full path of an email.
Definition: notmuch.c:359
+ 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 1807 of file notmuch.c.

1808 {
1809  mutt_debug(LL_DEBUG2, "(%s)\n", buf);
1810  struct NmMboxData *mdata = nm_mdata_get(m);
1811  char url[PATH_MAX + 1024 + 32]; /* path to DB + query + URL "decoration" */
1812  int added;
1813  bool using_default_data = false;
1814 
1815  // No existing data. Try to get a default NmMboxData.
1816  if (!mdata)
1817  {
1818  mdata = nm_get_default_data();
1819 
1820  // Failed to get default data.
1821  if (!mdata)
1822  return NULL;
1823 
1824  using_default_data = true;
1825  }
1826 
1827  nm_parse_type_from_query(mdata, buf);
1828 
1829  if (get_limit(mdata) == C_NmDbLimit)
1830  {
1831  added = snprintf(url, sizeof(url), "%s%s?type=%s&query=", NmUrlProtocol,
1833  }
1834  else
1835  {
1836  added = snprintf(url, sizeof(url), "%s%s?type=%s&limit=%d&query=", NmUrlProtocol,
1837  nm_db_get_filename(m),
1838  query_type_to_string(mdata->query_type), get_limit(mdata));
1839  }
1840 
1841  if (added >= sizeof(url))
1842  {
1843  // snprintf output was truncated, so can't create URL
1844  return NULL;
1845  }
1846 
1847  url_pct_encode(&url[added], sizeof(url) - added, buf);
1848 
1849  mutt_str_copy(buf, url, buflen);
1850  buf[buflen - 1] = '\0';
1851 
1852  if (using_default_data)
1853  nm_mdata_free((void **) &mdata);
1854 
1855  mutt_debug(LL_DEBUG1, "nm: url from query '%s'\n", buf);
1856  return buf;
1857 }
Log at debug level 2.
Definition: logging.h:41
static int get_limit(struct NmMboxData *mdata)
Get the database limit.
Definition: notmuch.c:571
Notmuch-specific Mailbox data -.
Definition: private.h:69
static const char * query_type_to_string(enum NmQueryType query_type)
Turn a query type into a string.
Definition: notmuch.c:372
void * mdata
Driver specific data.
Definition: mailbox.h:136
void nm_parse_type_from_query(struct NmMboxData *mdata, char *buf)
Parse a query type out of a query.
Definition: notmuch.c:1776
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:44
int C_NmDbLimit
Config: (notmuch) Default limit for Notmuch queries.
Definition: config.c:37
const char NmUrlProtocol[]
Definition: notmuch.c:82
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition: notmuch.c:236
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:716
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
void nm_mdata_free(void **ptr)
Free the private Mailbox data - Implements Mailbox::mdata_free()
Definition: notmuch.c:188
static struct NmMboxData * nm_get_default_data(void)
Create a Mailbox with default Notmuch settings.
Definition: notmuch.c:294
enum NmQueryType query_type
Messages or Threads.
Definition: private.h:74
const char * nm_db_get_filename(struct Mailbox *m)
Get the filename of the Notmuch database.
Definition: db.c:53
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ config_init_notmuch()

bool config_init_notmuch ( struct ConfigSet cs)

Register notmuch config variables - Implements module_init_config_t.

Definition at line 110 of file config.c.

111 {
112  return cs_register_variables(cs, NotmuchVars, 0);
113 }
struct ConfigDef NotmuchVars[]
Definition: config.c:54
bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[], int flags)
Register a set of config items.
Definition: set.c:286
+ Here is the call graph for this function:

Variable Documentation

◆ MxNotmuchOps

struct MxOps MxNotmuchOps

Notmuch Mailbox - Implements MxOps.

Definition at line 2655 of file notmuch.c.

◆ C_NmQueryWindowCurrentSearch

char* C_NmQueryWindowCurrentSearch

Config: (notmuch) Current search parameters.

Definition at line 44 of file config.c.

◆ C_NmQueryWindowDuration

int C_NmQueryWindowDuration

Config: (notmuch) Time duration of the current search window.

Definition at line 45 of file config.c.

◆ C_VfolderFormat

char* C_VfolderFormat

Config: (notmuch) printf-like format string for the browser's display of virtual folders.

Definition at line 50 of file config.c.

◆ C_VirtualSpoolfile

bool C_VirtualSpoolfile

Config: (notmuch) Use the first virtual mailbox as a spool file.

Definition at line 51 of file config.c.