NeoMutt  2020-06-26-89-g172cd3
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. 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:153
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:153
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:153
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 1621 of file notmuch.c.

1622 {
1623  return (e && e->edata) ? ((struct NmEmailData *) e->edata)->folder : NULL;
1624 }
Notmuch-specific Email data -.
Definition: private.h:87
void * edata
Driver-specific data.
Definition: email.h:106
+ 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 2066 of file notmuch.c.

2067 {
2068  struct NmMboxData *mdata = nm_mdata_get(m);
2069  if (!mdata)
2070  return -1;
2071 
2072  notmuch_database_t *db = NULL;
2073  notmuch_tags_t *tags = NULL;
2074  const char *tag = NULL;
2075  int rc = -1;
2076 
2077  if (!(db = nm_db_get(m, false)) || !(tags = notmuch_database_get_all_tags(db)))
2078  goto done;
2079 
2080  *tag_count = 0;
2081  mutt_debug(LL_DEBUG1, "nm: get all tags\n");
2082 
2083  while (notmuch_tags_valid(tags))
2084  {
2085  tag = notmuch_tags_get(tags);
2086  /* Skip empty string */
2087  if (*tag)
2088  {
2089  if (tag_list)
2090  tag_list[*tag_count] = mutt_str_dup(tag);
2091  (*tag_count)++;
2092  }
2093  notmuch_tags_move_to_next(tags);
2094  }
2095 
2096  rc = 0;
2097 done:
2098  if (tags)
2099  notmuch_tags_destroy(tags);
2100 
2101  nm_db_release(m);
2102 
2103  mutt_debug(LL_DEBUG1, "nm: get all tags done [rc=%d tag_count=%u]\n", rc, *tag_count);
2104  return rc;
2105 }
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:375
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:221
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 1821 of file notmuch.c.

1822 {
1823  struct NmMboxData *mdata = nm_mdata_get(m);
1824  notmuch_database_t *db = nm_db_get(m, false);
1825  char *orig_str = get_query_string(mdata, true);
1826 
1827  if (!db || !orig_str)
1828  return false;
1829 
1830  char *new_str = NULL;
1831  bool rc = false;
1832  if (mutt_str_asprintf(&new_str, "id:%s and (%s)", email_get_id(e), orig_str) < 0)
1833  return false;
1834 
1835  mutt_debug(LL_DEBUG2, "nm: checking if message is still queried: %s\n", new_str);
1836 
1837  notmuch_query_t *q = notmuch_query_create(db, new_str);
1838 
1839  switch (mdata->query_type)
1840  {
1841  case NM_QUERY_TYPE_MESGS:
1842  {
1843  notmuch_messages_t *messages = get_messages(q);
1844 
1845  if (!messages)
1846  return false;
1847 
1848  rc = notmuch_messages_valid(messages);
1849  notmuch_messages_destroy(messages);
1850  break;
1851  }
1852  case NM_QUERY_TYPE_THREADS:
1853  {
1854  notmuch_threads_t *threads = get_threads(q);
1855 
1856  if (!threads)
1857  return false;
1858 
1859  rc = notmuch_threads_valid(threads);
1860  notmuch_threads_destroy(threads);
1861  break;
1862  }
1863  }
1864 
1865  notmuch_query_destroy(q);
1866 
1867  mutt_debug(LL_DEBUG2, "nm: checking if message is still queried: %s = %s\n",
1868  new_str, rc ? "true" : "false");
1869 
1870  return rc;
1871 }
static notmuch_threads_t * get_threads(notmuch_query_t *query)
load threads for a query
Definition: notmuch.c:1129
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:312
static notmuch_messages_t * get_messages(notmuch_query_t *query)
load messages for a query
Definition: notmuch.c:1059
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:478
Default: Messages only.
Definition: private.h:62
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition: notmuch.c:221
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:1100
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 1701 of file notmuch.c.

1702 {
1703  if (!buf)
1704  return;
1705 
1706  // The six variations of how type= could appear.
1707  const char *variants[6] = { "&type=threads", "&type=messages",
1708  "type=threads&", "type=messages&",
1709  "type=threads", "type=messages" };
1710 
1711  int variants_size = mutt_array_size(variants);
1712  for (int i = 0; i < variants_size; i++)
1713  {
1714  if (strcasestr(buf, variants[i]) != NULL)
1715  {
1716  // variants[] is setup such that type can be determined via modulo 2.
1717  mdata->query_type = ((i % 2) == 0) ? NM_QUERY_TYPE_THREADS : NM_QUERY_TYPE_MESGS;
1718 
1719  mutt_istr_remall(buf, variants[i]);
1720  }
1721  }
1722 }
#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:1042
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 2528 of file notmuch.c.

2529 {
2530  if (!path || !mutt_istr_startswith(path, NmUrlProtocol))
2531  return MUTT_UNKNOWN;
2532 
2533  return MUTT_NOTMUCH;
2534 }
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:177
&#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 1809 of file notmuch.c.

1810 {
1813 }
Log at debug level 2.
Definition: logging.h:41
int C_NmQueryWindowCurrentPosition
Config: (notmuch) Position of current search window.
Definition: config.c:42
#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 1793 of file notmuch.c.

1794 {
1797 
1799 }
Log at debug level 2.
Definition: logging.h:41
int C_NmQueryWindowCurrentPosition
Config: (notmuch) Position of current search window.
Definition: config.c:42
#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 1633 of file notmuch.c.

1634 {
1635  if (!m)
1636  return -1;
1637 
1638  struct NmMboxData *mdata = nm_mdata_get(m);
1639  if (!mdata)
1640  return -1;
1641 
1642  notmuch_query_t *q = NULL;
1643  notmuch_database_t *db = NULL;
1644  notmuch_message_t *msg = NULL;
1645  int rc = -1;
1646 
1647  if (!(db = nm_db_get(m, false)) || !(msg = get_nm_message(db, e)))
1648  goto done;
1649 
1650  mutt_debug(LL_DEBUG1, "nm: reading entire-thread messages...[current count=%d]\n",
1651  m->msg_count);
1652 
1653  progress_reset(m);
1654  const char *id = notmuch_message_get_thread_id(msg);
1655  if (!id)
1656  goto done;
1657 
1658  char *qstr = NULL;
1659  mutt_str_append_item(&qstr, "thread:", '\0');
1660  mutt_str_append_item(&qstr, id, '\0');
1661 
1662  q = notmuch_query_create(db, qstr);
1663  FREE(&qstr);
1664  if (!q)
1665  goto done;
1666  apply_exclude_tags(q);
1667  notmuch_query_set_sort(q, NOTMUCH_SORT_NEWEST_FIRST);
1668 
1669  read_threads_query(m, q, true, 0);
1670  m->mtime.tv_sec = mutt_date_epoch();
1671  m->mtime.tv_nsec = 0;
1672  rc = 0;
1673 
1674  if (m->msg_count > mdata->oldmsgcount)
1676 done:
1677  if (q)
1678  notmuch_query_destroy(q);
1679 
1680  nm_db_release(m);
1681 
1682  if (m->msg_count == mdata->oldmsgcount)
1683  mutt_message(_("No more messages in the thread"));
1684 
1685  mdata->oldmsgcount = 0;
1686  mutt_debug(LL_DEBUG1, "nm: reading entire-thread messages... done [rc=%d, count=%d]\n",
1687  rc, m->msg_count);
1688  return rc;
1689 }
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:414
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:814
#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:166
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:1193
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition: notmuch.c:221
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:471
static void apply_exclude_tags(notmuch_query_t *query)
Exclude the configured tags.
Definition: notmuch.c:545
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:1157
+ 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 2001 of file notmuch.c.

2002 {
2003  notmuch_database_t *db = NULL;
2004  notmuch_status_t st;
2005  notmuch_message_t *msg = NULL;
2006  int rc = -1;
2007  struct NmMboxData *mdata = nm_mdata_get(m);
2008 
2009  if (!path || !mdata || (access(path, F_OK) != 0))
2010  return 0;
2011  db = nm_db_get(m, true);
2012  if (!db)
2013  return -1;
2014 
2015  mutt_debug(LL_DEBUG1, "nm: record message: %s\n", path);
2016  int trans = nm_db_trans_begin(m);
2017  if (trans < 0)
2018  goto done;
2019 
2020 #ifdef HAVE_NOTMUCH_DATABASE_INDEX_FILE
2021  st = notmuch_database_index_file(db, path, NULL, &msg);
2022 #else
2023  st = notmuch_database_add_message(db, path, &msg);
2024 #endif
2025 
2026  if ((st != NOTMUCH_STATUS_SUCCESS) && (st != NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID))
2027  {
2028  mutt_debug(LL_DEBUG1, "nm: failed to add '%s' [st=%d]\n", path, (int) st);
2029  goto done;
2030  }
2031 
2032  if ((st == NOTMUCH_STATUS_SUCCESS) && msg)
2033  {
2034  notmuch_message_maildir_flags_to_tags(msg);
2035  if (e)
2036  {
2037  char *tags = driver_tags_get(&e->tags);
2038  update_tags(msg, tags);
2039  FREE(&tags);
2040  }
2041  if (C_NmRecordTags)
2043  }
2044 
2045  rc = 0;
2046 done:
2047  if (msg)
2048  notmuch_message_destroy(msg);
2049  if (trans == 1)
2050  nm_db_trans_end(m);
2051 
2052  nm_db_release(m);
2053  return rc;
2054 }
static int update_tags(notmuch_message_t *msg, const char *tags)
Update the tags on a message.
Definition: notmuch.c:1236
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:102
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:221
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:46
+ 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 1882 of file notmuch.c.

1884 {
1885  char buf[PATH_MAX];
1886  struct NmMboxData *mdata = nm_mdata_get(m);
1887  if (!mdata || !new_file)
1888  return -1;
1889 
1890  if (!old_file && e && e->edata)
1891  {
1892  email_get_fullpath(e, buf, sizeof(buf));
1893  old_file = buf;
1894  }
1895 
1896  int rc = rename_filename(m, old_file, new_file, e);
1897 
1898  nm_db_release(m);
1899  m->mtime.tv_sec = mutt_date_epoch();
1900  m->mtime.tv_nsec = 0;
1901  return rc;
1902 }
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:414
struct timespec mtime
Time Mailbox was last changed.
Definition: mailbox.h:107
time_t tv_sec
Definition: file.h:48
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:1484
#define PATH_MAX
Definition: mutt.h:44
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition: notmuch.c:221
int nm_db_release(struct Mailbox *m)
Close the Notmuch database.
Definition: db.c:171
void * edata
Driver-specific data.
Definition: email.h:106
static char * email_get_fullpath(struct Email *e, char *buf, size_t buflen)
Get the full path of an email.
Definition: notmuch.c:324
+ 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 1732 of file notmuch.c.

1733 {
1734  mutt_debug(LL_DEBUG2, "(%s)\n", buf);
1735  struct NmMboxData *mdata = nm_mdata_get(m);
1736  char url[PATH_MAX + 1024 + 32]; /* path to DB + query + URL "decoration" */
1737  int added;
1738  bool using_default_data = false;
1739 
1740  // No existing data. Try to get a default NmMboxData.
1741  if (!mdata)
1742  {
1743  mdata = nm_get_default_data();
1744 
1745  // Failed to get default data.
1746  if (!mdata)
1747  return NULL;
1748 
1749  using_default_data = true;
1750  }
1751 
1752  nm_parse_type_from_query(mdata, buf);
1753 
1754  if (get_limit(mdata) == C_NmDbLimit)
1755  {
1756  added = snprintf(url, sizeof(url), "%s%s?type=%s&query=", NmUrlProtocol,
1758  }
1759  else
1760  {
1761  added = snprintf(url, sizeof(url), "%s%s?type=%s&limit=%d&query=", NmUrlProtocol,
1762  nm_db_get_filename(m),
1763  query_type_to_string(mdata->query_type), get_limit(mdata));
1764  }
1765 
1766  if (added >= sizeof(url))
1767  {
1768  // snprintf output was truncated, so can't create URL
1769  return NULL;
1770  }
1771 
1772  url_pct_encode(&url[added], sizeof(url) - added, buf);
1773 
1774  mutt_str_copy(buf, url, buflen);
1775  buf[buflen - 1] = '\0';
1776 
1777  if (using_default_data)
1778  nm_mdata_free((void **) &mdata);
1779 
1780  mutt_debug(LL_DEBUG1, "nm: url from query '%s'\n", buf);
1781  return buf;
1782 }
Log at debug level 2.
Definition: logging.h:41
static int get_limit(struct NmMboxData *mdata)
Get the database limit.
Definition: notmuch.c:536
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:337
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:1701
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:36
const char NmUrlProtocol[]
Definition: notmuch.c:73
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition: notmuch.c:221
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:721
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
void nm_mdata_free(void **ptr)
Free data attached to the Mailbox.
Definition: notmuch.c:173
static struct NmMboxData * nm_get_default_data(void)
Create a Mailbox with default Notmuch settings.
Definition: notmuch.c:263
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.

Definition at line 79 of file config.c.

80 {
81  return cs_register_variables(cs, NotmuchVars, 0);
82 }
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:279
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ MxNotmuchOps

struct MxOps MxNotmuchOps

Notmuch Mailbox - Implements MxOps.

Definition at line 2569 of file notmuch.c.

◆ C_NmQueryWindowCurrentSearch

char* C_NmQueryWindowCurrentSearch

Config: (notmuch) Current search parameters.

Definition at line 43 of file config.c.

◆ C_NmQueryWindowDuration

int C_NmQueryWindowDuration

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

Definition at line 44 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 49 of file config.c.

◆ C_VirtualSpoolfile

bool C_VirtualSpoolfile

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

Definition at line 50 of file config.c.