NeoMutt  2020-08-21-74-g346364
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_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...
 
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_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:152
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:152
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:152
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 1652 of file notmuch.c.

1653 {
1654  struct NmEmailData *edata = nm_edata_get(e);
1655  if (!edata)
1656  return NULL;
1657 
1658  return edata->folder;
1659 }
struct NmEmailData * nm_edata_get(struct Email *e)
Get the Notmuch Email data.
Definition: notmuch.c:264
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_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 2101 of file notmuch.c.

2102 {
2103  struct NmMboxData *mdata = nm_mdata_get(m);
2104  if (!mdata)
2105  return -1;
2106 
2107  notmuch_database_t *db = NULL;
2108  notmuch_tags_t *tags = NULL;
2109  const char *tag = NULL;
2110  int rc = -1;
2111 
2112  if (!(db = nm_db_get(m, false)) || !(tags = notmuch_database_get_all_tags(db)))
2113  goto done;
2114 
2115  *tag_count = 0;
2116  mutt_debug(LL_DEBUG1, "nm: get all tags\n");
2117 
2118  while (notmuch_tags_valid(tags))
2119  {
2120  tag = notmuch_tags_get(tags);
2121  /* Skip empty string */
2122  if (*tag)
2123  {
2124  if (tag_list)
2125  tag_list[*tag_count] = mutt_str_dup(tag);
2126  (*tag_count)++;
2127  }
2128  notmuch_tags_move_to_next(tags);
2129  }
2130 
2131  rc = 0;
2132 done:
2133  if (tags)
2134  notmuch_tags_destroy(tags);
2135 
2136  nm_db_release(m);
2137 
2138  mutt_debug(LL_DEBUG1, "nm: get all tags done [rc=%d tag_count=%u]\n", rc, *tag_count);
2139  return rc;
2140 }
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:219
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 1856 of file notmuch.c.

1857 {
1858  struct NmMboxData *mdata = nm_mdata_get(m);
1859  notmuch_database_t *db = nm_db_get(m, false);
1860  char *orig_str = get_query_string(mdata, true);
1861 
1862  if (!db || !orig_str)
1863  return false;
1864 
1865  char *new_str = NULL;
1866  bool rc = false;
1867  if (mutt_str_asprintf(&new_str, "id:%s and (%s)", email_get_id(e), orig_str) < 0)
1868  return false;
1869 
1870  mutt_debug(LL_DEBUG2, "nm: checking if message is still queried: %s\n", new_str);
1871 
1872  notmuch_query_t *q = notmuch_query_create(db, new_str);
1873 
1874  switch (mdata->query_type)
1875  {
1876  case NM_QUERY_TYPE_MESGS:
1877  {
1878  notmuch_messages_t *messages = get_messages(q);
1879 
1880  if (!messages)
1881  return false;
1882 
1883  rc = notmuch_messages_valid(messages);
1884  notmuch_messages_destroy(messages);
1885  break;
1886  }
1887  case NM_QUERY_TYPE_THREADS:
1888  {
1889  notmuch_threads_t *threads = get_threads(q);
1890 
1891  if (!threads)
1892  return false;
1893 
1894  rc = notmuch_threads_valid(threads);
1895  notmuch_threads_destroy(threads);
1896  break;
1897  }
1898  }
1899 
1900  notmuch_query_destroy(q);
1901 
1902  mutt_debug(LL_DEBUG2, "nm: checking if message is still queried: %s = %s\n",
1903  new_str, rc ? "true" : "false");
1904 
1905  return rc;
1906 }
static notmuch_threads_t * get_threads(notmuch_query_t *query)
load threads for a query
Definition: notmuch.c:1145
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:326
static notmuch_messages_t * get_messages(notmuch_query_t *query)
load messages for a query
Definition: notmuch.c:1075
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:496
Default: Messages only.
Definition: private.h:62
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition: notmuch.c:219
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 1736 of file notmuch.c.

1737 {
1738  if (!buf)
1739  return;
1740 
1741  // The six variations of how type= could appear.
1742  const char *variants[6] = { "&type=threads", "&type=messages",
1743  "type=threads&", "type=messages&",
1744  "type=threads", "type=messages" };
1745 
1746  int variants_size = mutt_array_size(variants);
1747  for (int i = 0; i < variants_size; i++)
1748  {
1749  if (strcasestr(buf, variants[i]) != NULL)
1750  {
1751  // variants[] is setup such that type can be determined via modulo 2.
1752  mdata->query_type = ((i % 2) == 0) ? NM_QUERY_TYPE_THREADS : NM_QUERY_TYPE_MESGS;
1753 
1754  mutt_istr_remall(buf, variants[i]);
1755  }
1756  }
1757 }
#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 2594 of file notmuch.c.

2595 {
2596  if (!path || !mutt_istr_startswith(path, NmUrlProtocol))
2597  return MUTT_UNKNOWN;
2598 
2599  return MUTT_NOTMUCH;
2600 }
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:73
+ 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 1844 of file notmuch.c.

1845 {
1848 }
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 1828 of file notmuch.c.

1829 {
1832 
1834 }
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 1668 of file notmuch.c.

1669 {
1670  if (!m)
1671  return -1;
1672 
1673  struct NmMboxData *mdata = nm_mdata_get(m);
1674  if (!mdata)
1675  return -1;
1676 
1677  notmuch_query_t *q = NULL;
1678  notmuch_database_t *db = NULL;
1679  notmuch_message_t *msg = NULL;
1680  int rc = -1;
1681 
1682  if (!(db = nm_db_get(m, false)) || !(msg = get_nm_message(db, e)))
1683  goto done;
1684 
1685  mutt_debug(LL_DEBUG1, "nm: reading entire-thread messages...[current count=%d]\n",
1686  m->msg_count);
1687 
1688  progress_reset(m);
1689  const char *id = notmuch_message_get_thread_id(msg);
1690  if (!id)
1691  goto done;
1692 
1693  char *qstr = NULL;
1694  mutt_str_append_item(&qstr, "thread:", '\0');
1695  mutt_str_append_item(&qstr, id, '\0');
1696 
1697  q = notmuch_query_create(db, qstr);
1698  FREE(&qstr);
1699  if (!q)
1700  goto done;
1701  apply_exclude_tags(q);
1702  notmuch_query_set_sort(q, NOTMUCH_SORT_NEWEST_FIRST);
1703 
1704  read_threads_query(m, q, true, 0);
1705  m->mtime.tv_sec = mutt_date_epoch();
1706  m->mtime.tv_nsec = 0;
1707  rc = 0;
1708 
1709  if (m->msg_count > mdata->oldmsgcount)
1711 done:
1712  if (q)
1713  notmuch_query_destroy(q);
1714 
1715  nm_db_release(m);
1716 
1717  if (m->msg_count == mdata->oldmsgcount)
1718  mutt_message(_("No more messages in the thread"));
1719 
1720  mdata->oldmsgcount = 0;
1721  mutt_debug(LL_DEBUG1, "nm: reading entire-thread messages... done [rc=%d, count=%d]\n",
1722  rc, m->msg_count);
1723  return rc;
1724 }
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:831
#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:171
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:1209
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition: notmuch.c:219
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:563
void mailbox_changed(struct Mailbox *m, enum NotifyMailbox action)
Notify observers of a change to a Mailbox.
Definition: mailbox.c:174
static bool read_threads_query(struct Mailbox *m, notmuch_query_t *q, bool dedup, int limit)
Perform a query with threads.
Definition: notmuch.c:1173
+ 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 2036 of file notmuch.c.

2037 {
2038  notmuch_database_t *db = NULL;
2039  notmuch_status_t st;
2040  notmuch_message_t *msg = NULL;
2041  int rc = -1;
2042  struct NmMboxData *mdata = nm_mdata_get(m);
2043 
2044  if (!path || !mdata || (access(path, F_OK) != 0))
2045  return 0;
2046  db = nm_db_get(m, true);
2047  if (!db)
2048  return -1;
2049 
2050  mutt_debug(LL_DEBUG1, "nm: record message: %s\n", path);
2051  int trans = nm_db_trans_begin(m);
2052  if (trans < 0)
2053  goto done;
2054 
2055 #ifdef HAVE_NOTMUCH_DATABASE_INDEX_FILE
2056  st = notmuch_database_index_file(db, path, NULL, &msg);
2057 #else
2058  st = notmuch_database_add_message(db, path, &msg);
2059 #endif
2060 
2061  if ((st != NOTMUCH_STATUS_SUCCESS) && (st != NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID))
2062  {
2063  mutt_debug(LL_DEBUG1, "nm: failed to add '%s' [st=%d]\n", path, (int) st);
2064  goto done;
2065  }
2066 
2067  if ((st == NOTMUCH_STATUS_SUCCESS) && msg)
2068  {
2069  notmuch_message_maildir_flags_to_tags(msg);
2070  if (e)
2071  {
2072  char *tags = driver_tags_get(&e->tags);
2073  update_tags(msg, tags);
2074  FREE(&tags);
2075  }
2076  if (C_NmRecordTags)
2078  }
2079 
2080  rc = 0;
2081 done:
2082  if (msg)
2083  notmuch_message_destroy(msg);
2084  if (trans == 1)
2085  nm_db_trans_end(m);
2086 
2087  nm_db_release(m);
2088  return rc;
2089 }
static int update_tags(notmuch_message_t *msg, const char *tags)
Update the tags on a message.
Definition: notmuch.c:1267
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:219
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 1917 of file notmuch.c.

1919 {
1920  char buf[PATH_MAX];
1921  struct NmMboxData *mdata = nm_mdata_get(m);
1922  if (!mdata || !new_file)
1923  return -1;
1924 
1925  if (!old_file && nm_edata_get(e))
1926  {
1927  email_get_fullpath(e, buf, sizeof(buf));
1928  old_file = buf;
1929  }
1930 
1931  int rc = rename_filename(m, old_file, new_file, e);
1932 
1933  nm_db_release(m);
1934  m->mtime.tv_sec = mutt_date_epoch();
1935  m->mtime.tv_nsec = 0;
1936  return rc;
1937 }
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:264
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:1515
#define PATH_MAX
Definition: mutt.h:44
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition: notmuch.c:219
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:342
+ 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 1767 of file notmuch.c.

1768 {
1769  mutt_debug(LL_DEBUG2, "(%s)\n", buf);
1770  struct NmMboxData *mdata = nm_mdata_get(m);
1771  char url[PATH_MAX + 1024 + 32]; /* path to DB + query + URL "decoration" */
1772  int added;
1773  bool using_default_data = false;
1774 
1775  // No existing data. Try to get a default NmMboxData.
1776  if (!mdata)
1777  {
1778  mdata = nm_get_default_data();
1779 
1780  // Failed to get default data.
1781  if (!mdata)
1782  return NULL;
1783 
1784  using_default_data = true;
1785  }
1786 
1787  nm_parse_type_from_query(mdata, buf);
1788 
1789  if (get_limit(mdata) == C_NmDbLimit)
1790  {
1791  added = snprintf(url, sizeof(url), "%s%s?type=%s&query=", NmUrlProtocol,
1793  }
1794  else
1795  {
1796  added = snprintf(url, sizeof(url), "%s%s?type=%s&limit=%d&query=", NmUrlProtocol,
1797  nm_db_get_filename(m),
1798  query_type_to_string(mdata->query_type), get_limit(mdata));
1799  }
1800 
1801  if (added >= sizeof(url))
1802  {
1803  // snprintf output was truncated, so can't create URL
1804  return NULL;
1805  }
1806 
1807  url_pct_encode(&url[added], sizeof(url) - added, buf);
1808 
1809  mutt_str_copy(buf, url, buflen);
1810  buf[buflen - 1] = '\0';
1811 
1812  if (using_default_data)
1813  nm_mdata_free((void **) &mdata);
1814 
1815  mutt_debug(LL_DEBUG1, "nm: url from query '%s'\n", buf);
1816  return buf;
1817 }
Log at debug level 2.
Definition: logging.h:41
static int get_limit(struct NmMboxData *mdata)
Get the database limit.
Definition: notmuch.c:554
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:355
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:1736
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:73
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition: notmuch.c:219
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:171
static struct NmMboxData * nm_get_default_data(void)
Create a Mailbox with default Notmuch settings.
Definition: notmuch.c:277
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 2635 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.