NeoMutt  2019-12-07-60-g0cfa53
Teaching an old dog new tricks
DOXYGEN
mutt_notmuch.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 mutt_notmuch.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_uri_from_query (struct Mailbox *m, char *buf, size_t buflen)
 Turn a query into a URI. More...
 

Variables

int C_NmDbLimit
 Config: (notmuch) Default limit for Notmuch queries. More...
 
char * C_NmDefaultUri
 Config: (notmuch) Path to the Notmuch database. More...
 
char * C_NmExcludeTags
 Config: (notmuch) Exclude messages with these tags. More...
 
int C_NmOpenTimeout
 Config: (notmuch) Database timeout. More...
 
char * C_NmQueryType
 Config: (notmuch) Default query type: 'threads' or 'messages'. More...
 
int C_NmQueryWindowCurrentPosition
 Config: (notmuch) Position of current search window. More...
 
char * C_NmQueryWindowTimebase
 Config: (notmuch) Units for the time duration. More...
 
char * C_NmRecordTags
 Config: (notmuch) Tags to apply to the 'record' mailbox (sent mail) More...
 
char * C_NmUnreadTag
 Config: (notmuch) Tag to use for unread messages. More...
 
char * C_NmFlaggedTag
 Config: (notmuch) Tag to use for flagged messages. More...
 
char * C_NmRepliedTag
 Config: (notmuch) Tag to use for replied messages. More...
 
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 mutt_notmuch.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 nm_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
int nm_db_release(struct Mailbox *m)
Close the Notmuch database.
Definition: nm_db.c:171
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
struct NmAccountData * nm_adata_get(struct Mailbox *m)
Get the Notmuch Account data.
Definition: mutt_notmuch.c:164
Log at debug level 1.
Definition: logging.h:40
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
Notmuch-specific Account data -.
+ 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 nm_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.
Log at debug level 2.
Definition: logging.h:41
int nm_db_release(struct Mailbox *m)
Close the Notmuch database.
Definition: nm_db.c:171
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
struct NmAccountData * nm_adata_get(struct Mailbox *m)
Get the Notmuch Account data.
Definition: mutt_notmuch.c:164
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
Notmuch-specific Account data -.
+ 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 nm_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 }
notmuch_database_t * nm_db_get(struct Mailbox *m, bool writable)
Get the Notmuch database.
Definition: nm_db.c:147
bool longrun
A long-lived action is in progress.
Log at debug level 2.
Definition: logging.h:41
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
struct NmAccountData * nm_adata_get(struct Mailbox *m)
Get the Notmuch Account data.
Definition: mutt_notmuch.c:164
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
Notmuch-specific Account data -.
+ 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 1643 of file mutt_notmuch.c.

1644 {
1645  return (e && e->edata) ? ((struct NmEmailData *) e->edata)->folder : NULL;
1646 }
Notmuch-specific Email data -.
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 2085 of file mutt_notmuch.c.

2086 {
2087  struct NmMboxData *mdata = nm_mdata_get(m);
2088  if (!mdata)
2089  return -1;
2090 
2091  notmuch_database_t *db = NULL;
2092  notmuch_tags_t *tags = NULL;
2093  const char *tag = NULL;
2094  int rc = -1;
2095 
2096  if (!(db = nm_db_get(m, false)) || !(tags = notmuch_database_get_all_tags(db)))
2097  goto done;
2098 
2099  *tag_count = 0;
2100  mutt_debug(LL_DEBUG1, "nm: get all tags\n");
2101 
2102  while (notmuch_tags_valid(tags))
2103  {
2104  tag = notmuch_tags_get(tags);
2105  /* Skip empty string */
2106  if (*tag)
2107  {
2108  if (tag_list)
2109  tag_list[*tag_count] = mutt_str_strdup(tag);
2110  (*tag_count)++;
2111  }
2112  notmuch_tags_move_to_next(tags);
2113  }
2114 
2115  rc = 0;
2116 done:
2117  if (tags)
2118  notmuch_tags_destroy(tags);
2119 
2120  nm_db_release(m);
2121 
2122  mutt_debug(LL_DEBUG1, "nm: get all tags done [rc=%d tag_count=%u]\n", rc, *tag_count);
2123  return rc;
2124 }
notmuch_database_t * nm_db_get(struct Mailbox *m, bool writable)
Get the Notmuch database.
Definition: nm_db.c:147
Notmuch-specific Mailbox data -.
int nm_db_release(struct Mailbox *m)
Close the Notmuch database.
Definition: nm_db.c:171
void * mdata
Driver specific data.
Definition: mailbox.h:135
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition: mutt_notmuch.c:232
Log at debug level 1.
Definition: logging.h:40
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
#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 1840 of file mutt_notmuch.c.

1841 {
1842  struct NmMboxData *mdata = nm_mdata_get(m);
1843  notmuch_database_t *db = nm_db_get(m, false);
1844  char *orig_str = get_query_string(mdata, true);
1845 
1846  if (!db || !orig_str)
1847  return false;
1848 
1849  char *new_str = NULL;
1850  bool rc = false;
1851  if (mutt_str_asprintf(&new_str, "id:%s and (%s)", email_get_id(e), orig_str) < 0)
1852  return false;
1853 
1854  mutt_debug(LL_DEBUG2, "nm: checking if message is still queried: %s\n", new_str);
1855 
1856  notmuch_query_t *q = notmuch_query_create(db, new_str);
1857 
1858  switch (mdata->query_type)
1859  {
1860  case NM_QUERY_TYPE_MESGS:
1861  {
1862  notmuch_messages_t *messages = get_messages(q);
1863 
1864  if (!messages)
1865  return false;
1866 
1867  rc = notmuch_messages_valid(messages);
1868  notmuch_messages_destroy(messages);
1869  break;
1870  }
1871  case NM_QUERY_TYPE_THREADS:
1872  {
1873  notmuch_threads_t *threads = get_threads(q);
1874 
1875  if (!threads)
1876  return false;
1877 
1878  rc = notmuch_threads_valid(threads);
1879  notmuch_threads_destroy(threads);
1880  break;
1881  }
1882  }
1883 
1884  notmuch_query_destroy(q);
1885 
1886  mutt_debug(LL_DEBUG2, "nm: checking if message is still queried: %s = %s\n",
1887  new_str, rc ? "true" : "false");
1888 
1889  return rc;
1890 }
notmuch_database_t * nm_db_get(struct Mailbox *m, bool writable)
Get the Notmuch database.
Definition: nm_db.c:147
static notmuch_messages_t * get_messages(notmuch_query_t *query)
load messages for a query
static char * email_get_id(struct Email *e)
Get the unique Notmuch Id.
Definition: mutt_notmuch.c:323
Log at debug level 2.
Definition: logging.h:41
Notmuch-specific Mailbox data -.
Default: Messages only.
void * mdata
Driver specific data.
Definition: mailbox.h:135
static char * get_query_string(struct NmMboxData *mdata, bool window)
builds the notmuch vfolder search string
Definition: mutt_notmuch.c:489
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition: mutt_notmuch.c:232
static notmuch_threads_t * get_threads(notmuch_query_t *query)
load threads for a query
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
int mutt_str_asprintf(char **strp, const char *fmt,...)
Definition: string.c:1194
enum NmQueryType query_type
Messages or Threads.
+ 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 URI

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 1723 of file mutt_notmuch.c.

1724 {
1725  // The six variations of how type= could appear.
1726  const char *variants[6] = { "&type=threads", "&type=messages",
1727  "type=threads&", "type=messages&",
1728  "type=threads", "type=messages" };
1729 
1730  int variants_size = mutt_array_size(variants);
1731  for (int i = 0; i < variants_size; i++)
1732  {
1733  if (mutt_str_strcasestr(buf, variants[i]) != NULL)
1734  {
1735  // variants[] is setup such that type can be determined via modulo 2.
1736  mdata->query_type = ((i % 2) == 0) ? NM_QUERY_TYPE_THREADS : NM_QUERY_TYPE_MESGS;
1737 
1738  mutt_str_remall_strcasestr(buf, variants[i]);
1739  }
1740  }
1741 }
int mutt_str_remall_strcasestr(char *str, const char *target)
Remove all occurrences of substring, ignoring case.
Definition: string.c:1094
const char * mutt_str_strcasestr(const char *haystack, const char *needle)
Find a substring within a string without worrying about case.
Definition: string.c:1119
#define mutt_array_size(x)
Definition: memory.h:33
Default: Messages only.
enum NmQueryType query_type
Messages or Threads.
+ 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 2549 of file mutt_notmuch.c.

2550 {
2551  if (!path || !mutt_str_startswith(path, NmUriProtocol, CASE_IGNORE))
2552  return MUTT_UNKNOWN;
2553 
2554  return MUTT_NOTMUCH;
2555 }
Mailbox wasn&#39;t recognised.
Definition: mailbox.h:46
const char NmUriProtocol[]
Definition: mutt_notmuch.c:71
Ignore case when comparing strings.
Definition: string2.h:68
&#39;Notmuch&#39; (virtual) Mailbox type
Definition: mailbox.h:53
size_t mutt_str_startswith(const char *str, const char *prefix, enum CaseSensitivity cs)
Check whether a string starts with a prefix.
Definition: string.c:168
+ 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 1828 of file mutt_notmuch.c.

1829 {
1832 }
Log at debug level 2.
Definition: logging.h:41
int C_NmQueryWindowCurrentPosition
Config: (notmuch) Position of current search window.
Definition: mutt_notmuch.c:80
#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 1812 of file mutt_notmuch.c.

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

1656 {
1657  if (!m)
1658  return -1;
1659 
1660  struct NmMboxData *mdata = nm_mdata_get(m);
1661  if (!mdata)
1662  return -1;
1663 
1664  notmuch_query_t *q = NULL;
1665  notmuch_database_t *db = NULL;
1666  notmuch_message_t *msg = NULL;
1667  int rc = -1;
1668 
1669  if (!(db = nm_db_get(m, false)) || !(msg = get_nm_message(db, e)))
1670  goto done;
1671 
1672  mutt_debug(LL_DEBUG1, "nm: reading entire-thread messages...[current count=%d]\n",
1673  m->msg_count);
1674 
1675  progress_reset(m);
1676  const char *id = notmuch_message_get_thread_id(msg);
1677  if (!id)
1678  goto done;
1679 
1680  char *qstr = NULL;
1681  mutt_str_append_item(&qstr, "thread:", '\0');
1682  mutt_str_append_item(&qstr, id, '\0');
1683 
1684  q = notmuch_query_create(db, qstr);
1685  FREE(&qstr);
1686  if (!q)
1687  goto done;
1688  apply_exclude_tags(q);
1689  notmuch_query_set_sort(q, NOTMUCH_SORT_NEWEST_FIRST);
1690 
1691  read_threads_query(m, q, true, 0);
1692  m->mtime.tv_sec = mutt_date_epoch();
1693  m->mtime.tv_nsec = 0;
1694  rc = 0;
1695 
1696  if (m->msg_count > mdata->oldmsgcount)
1698 done:
1699  if (q)
1700  notmuch_query_destroy(q);
1701 
1702  nm_db_release(m);
1703 
1704  if (m->msg_count == mdata->oldmsgcount)
1705  mutt_message(_("No more messages in the thread"));
1706 
1707  mdata->oldmsgcount = 0;
1708  mutt_debug(LL_DEBUG1, "nm: reading entire-thread messages... done [rc=%d, count=%d]\n",
1709  rc, m->msg_count);
1710  return rc;
1711 }
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:411
int msg_count
Total number of messages.
Definition: mailbox.h:90
notmuch_database_t * nm_db_get(struct Mailbox *m, bool writable)
Get the Notmuch database.
Definition: nm_db.c:147
#define mutt_message(...)
Definition: logging.h:83
static void progress_reset(struct Mailbox *m)
Reset the progress counter.
Definition: mutt_notmuch.c:825
struct timespec mtime
Time Mailbox was last changed.
Definition: mailbox.h:106
#define _(a)
Definition: message.h:28
Email list was changed.
Definition: mailbox.h:170
time_t tv_sec
Definition: file.h:47
Notmuch-specific Mailbox data -.
int nm_db_release(struct Mailbox *m)
Close the Notmuch database.
Definition: nm_db.c:171
long tv_nsec
Definition: file.h:48
void * mdata
Driver specific data.
Definition: mailbox.h:135
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition: mutt_notmuch.c:232
static notmuch_message_t * get_nm_message(notmuch_database_t *db, struct Email *e)
Find a Notmuch message.
static void apply_exclude_tags(notmuch_query_t *query)
Exclude the configured tags.
Definition: mutt_notmuch.c:556
static bool read_threads_query(struct Mailbox *m, notmuch_query_t *q, bool dedup, int limit)
Perform a query with threads.
Log at debug level 1.
Definition: logging.h:40
#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
void mailbox_changed(struct Mailbox *m, enum NotifyMailbox action)
Notify observers of a change to a Mailbox.
Definition: mailbox.c:171
+ 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 2020 of file mutt_notmuch.c.

2021 {
2022  notmuch_database_t *db = NULL;
2023  notmuch_status_t st;
2024  notmuch_message_t *msg = NULL;
2025  int rc = -1;
2026  struct NmMboxData *mdata = nm_mdata_get(m);
2027 
2028  if (!path || !mdata || (access(path, F_OK) != 0))
2029  return 0;
2030  db = nm_db_get(m, true);
2031  if (!db)
2032  return -1;
2033 
2034  mutt_debug(LL_DEBUG1, "nm: record message: %s\n", path);
2035  int trans = nm_db_trans_begin(m);
2036  if (trans < 0)
2037  goto done;
2038 
2039 #ifdef HAVE_NOTMUCH_DATABASE_INDEX_FILE
2040  st = notmuch_database_index_file(db, path, NULL, &msg);
2041 #else
2042  st = notmuch_database_add_message(db, path, &msg);
2043 #endif
2044 
2045  if ((st != NOTMUCH_STATUS_SUCCESS) && (st != NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID))
2046  {
2047  mutt_debug(LL_DEBUG1, "nm: failed to add '%s' [st=%d]\n", path, (int) st);
2048  goto done;
2049  }
2050 
2051  if ((st == NOTMUCH_STATUS_SUCCESS) && msg)
2052  {
2053  notmuch_message_maildir_flags_to_tags(msg);
2054  if (e)
2055  {
2056  char *tags = driver_tags_get(&e->tags);
2057  update_tags(msg, tags);
2058  FREE(&tags);
2059  }
2060  if (C_NmRecordTags)
2062  }
2063 
2064  rc = 0;
2065 done:
2066  if (msg)
2067  notmuch_message_destroy(msg);
2068  if (trans == 1)
2069  nm_db_trans_end(m);
2070 
2071  nm_db_release(m);
2072  return rc;
2073 }
int nm_db_trans_begin(struct Mailbox *m)
Start a Notmuch database transaction.
Definition: nm_db.c:204
notmuch_database_t * nm_db_get(struct Mailbox *m, bool writable)
Get the Notmuch database.
Definition: nm_db.c:147
int nm_db_trans_end(struct Mailbox *m)
End a database transaction.
Definition: nm_db.c:226
Notmuch-specific Mailbox data -.
int nm_db_release(struct Mailbox *m)
Close the Notmuch database.
Definition: nm_db.c:171
void * mdata
Driver specific data.
Definition: mailbox.h:135
struct TagList tags
For drivers that support server tagging.
Definition: email.h:102
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: mutt_notmuch.c:232
Log at debug level 1.
Definition: logging.h:40
static int update_tags(notmuch_message_t *msg, const char *tags)
Update the tags on a message.
#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: mutt_notmuch.c:82
+ 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 1901 of file mutt_notmuch.c.

1903 {
1904  char buf[PATH_MAX];
1905  struct NmMboxData *mdata = nm_mdata_get(m);
1906  if (!mdata || !new_file)
1907  return -1;
1908 
1909  if (!old_file && e && e->edata)
1910  {
1911  email_get_fullpath(e, buf, sizeof(buf));
1912  old_file = buf;
1913  }
1914 
1915  int rc = rename_filename(m, old_file, new_file, e);
1916 
1917  nm_db_release(m);
1918  m->mtime.tv_sec = mutt_date_epoch();
1919  m->mtime.tv_nsec = 0;
1920  return rc;
1921 }
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:411
static int rename_filename(struct Mailbox *m, const char *old_file, const char *new_file, struct Email *e)
Rename the file.
struct timespec mtime
Time Mailbox was last changed.
Definition: mailbox.h:106
static char * email_get_fullpath(struct Email *e, char *buf, size_t buflen)
Get the full path of an email.
Definition: mutt_notmuch.c:335
time_t tv_sec
Definition: file.h:47
Notmuch-specific Mailbox data -.
int nm_db_release(struct Mailbox *m)
Close the Notmuch database.
Definition: nm_db.c:171
long tv_nsec
Definition: file.h:48
void * mdata
Driver specific data.
Definition: mailbox.h:135
#define PATH_MAX
Definition: mutt.h:50
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition: mutt_notmuch.c:232
void * edata
Driver-specific data.
Definition: email.h:106
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nm_uri_from_query()

char* nm_uri_from_query ( struct Mailbox m,
char *  buf,
size_t  buflen 
)

Turn a query into a URI.

Parameters
mMailbox
bufBuffer for URI
buflenLength of buffer
Return values
ptrQuery as a URI
NULLError

Definition at line 1751 of file mutt_notmuch.c.

1752 {
1753  mutt_debug(LL_DEBUG2, "(%s)\n", buf);
1754  struct NmMboxData *mdata = nm_mdata_get(m);
1755  char uri[PATH_MAX + 1024 + 32]; /* path to DB + query + URI "decoration" */
1756  int added;
1757  bool using_default_data = false;
1758 
1759  // No existing data. Try to get a default NmMboxData.
1760  if (!mdata)
1761  {
1762  mdata = nm_get_default_data();
1763 
1764  // Failed to get default data.
1765  if (!mdata)
1766  return NULL;
1767 
1768  using_default_data = true;
1769  }
1770 
1771  nm_parse_type_from_query(mdata, buf);
1772 
1773  if (get_limit(mdata) == C_NmDbLimit)
1774  {
1775  added = snprintf(uri, sizeof(uri), "%s%s?type=%s&query=", NmUriProtocol,
1777  }
1778  else
1779  {
1780  added = snprintf(uri, sizeof(uri), "%s%s?type=%s&limit=%d&query=", NmUriProtocol,
1781  nm_db_get_filename(m),
1782  query_type_to_string(mdata->query_type), get_limit(mdata));
1783  }
1784 
1785  if (added >= sizeof(uri))
1786  {
1787  // snprintf output was truncated, so can't create URI
1788  return NULL;
1789  }
1790 
1791  url_pct_encode(&uri[added], sizeof(uri) - added, buf);
1792 
1793  mutt_str_strfcpy(buf, uri, buflen);
1794  buf[buflen - 1] = '\0';
1795 
1796  if (using_default_data)
1797  nm_mdata_free((void **) &mdata);
1798 
1799  mutt_debug(LL_DEBUG1, "nm: uri from query '%s'\n", buf);
1800  return buf;
1801 }
int C_NmDbLimit
Config: (notmuch) Default limit for Notmuch queries.
Definition: mutt_notmuch.c:75
static struct NmMboxData * nm_get_default_data(void)
Create a Mailbox with default Notmuch settings.
Definition: mutt_notmuch.c:274
Log at debug level 2.
Definition: logging.h:41
Notmuch-specific Mailbox data -.
const char NmUriProtocol[]
Definition: mutt_notmuch.c:71
void * mdata
Driver specific data.
Definition: mailbox.h:135
static int get_limit(struct NmMboxData *mdata)
Get the database limit.
Definition: mutt_notmuch.c:547
void nm_mdata_free(void **ptr)
Free data attached to the Mailbox.
Definition: mutt_notmuch.c:184
void url_pct_encode(char *buf, size_t buflen, const char *src)
Percent-encode a string.
Definition: url.c:315
#define PATH_MAX
Definition: mutt.h:50
const char * nm_db_get_filename(struct Mailbox *m)
Get the filename of the Notmuch database.
Definition: nm_db.c:53
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition: mutt_notmuch.c:232
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:750
void nm_parse_type_from_query(struct NmMboxData *mdata, char *buf)
Parse a query type out of a query.
Log at debug level 1.
Definition: logging.h:40
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
static const char * query_type_to_string(enum NmQueryType query_type)
Turn a query type into a string.
Definition: mutt_notmuch.c:348
enum NmQueryType query_type
Messages or Threads.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ C_NmDbLimit

int C_NmDbLimit

Config: (notmuch) Default limit for Notmuch queries.

Definition at line 75 of file mutt_notmuch.c.

◆ C_NmDefaultUri

char* C_NmDefaultUri

Config: (notmuch) Path to the Notmuch database.

Definition at line 76 of file mutt_notmuch.c.

◆ C_NmExcludeTags

char* C_NmExcludeTags

Config: (notmuch) Exclude messages with these tags.

Definition at line 77 of file mutt_notmuch.c.

◆ C_NmOpenTimeout

int C_NmOpenTimeout

Config: (notmuch) Database timeout.

Definition at line 78 of file mutt_notmuch.c.

◆ C_NmQueryType

char* C_NmQueryType

Config: (notmuch) Default query type: 'threads' or 'messages'.

Definition at line 79 of file mutt_notmuch.c.

◆ C_NmQueryWindowCurrentPosition

int C_NmQueryWindowCurrentPosition

Config: (notmuch) Position of current search window.

Definition at line 80 of file mutt_notmuch.c.

◆ C_NmQueryWindowTimebase

char* C_NmQueryWindowTimebase

Config: (notmuch) Units for the time duration.

Definition at line 81 of file mutt_notmuch.c.

◆ C_NmRecordTags

char* C_NmRecordTags

Config: (notmuch) Tags to apply to the 'record' mailbox (sent mail)

Definition at line 82 of file mutt_notmuch.c.

◆ C_NmUnreadTag

char* C_NmUnreadTag

Config: (notmuch) Tag to use for unread messages.

Definition at line 83 of file mutt_notmuch.c.

◆ C_NmFlaggedTag

char* C_NmFlaggedTag

Config: (notmuch) Tag to use for flagged messages.

Definition at line 84 of file mutt_notmuch.c.

◆ C_NmRepliedTag

char* C_NmRepliedTag

Config: (notmuch) Tag to use for replied messages.

Definition at line 85 of file mutt_notmuch.c.

◆ MxNotmuchOps

struct MxOps MxNotmuchOps

Notmuch Mailbox - Implements MxOps.

Definition at line 2590 of file mutt_notmuch.c.