From: Karel Zak Date: Wed, 14 Dec 2011 15:37:19 +0000 (+0100) Subject: add notmuch calls to mx_* API X-Git-Tag: neomutt-20160317~5^2~99 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=29ad85f4388aa6c18ac14caa2fafd1fe46116fa7;p=neomutt add notmuch calls to mx_* API Signed-off-by: Karel Zak --- diff --git a/mx.c b/mx.c index 3e26b8e3f..4bfc7bdff 100644 --- a/mx.c +++ b/mx.c @@ -385,6 +385,11 @@ int mx_get_magic (const char *path) return M_POP; #endif /* USE_POP */ +#ifdef USE_NOTMUCH + if (mx_is_notmuch(path)) + return M_NOTMUCH; +#endif + if (stat (path, &st) == -1) { dprint (1, (debugfile, "mx_get_magic(): unable to stat %s: %s (errno %d).\n", @@ -698,6 +703,12 @@ CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT *pctx) break; #endif /* USE_POP */ +#ifdef USE_NOTMUCH + case M_NOTMUCH: + rc = nm_read_query (ctx); + break; +#endif /* USE_IMAP */ + default: rc = -1; break; @@ -811,6 +822,13 @@ static int sync_mailbox (CONTEXT *ctx, int *index_hint) rc = pop_sync_mailbox (ctx, index_hint); break; #endif /* USE_POP */ + +#ifdef USE_NOTMUCH + case M_NOTMUCH: + rc = nm_sync (ctx, index_hint); + break; +#endif /* USE_NOTMUCH */ + } #if 0 @@ -1396,6 +1414,11 @@ int mx_check_mailbox (CONTEXT *ctx, int *index_hint, int lock) case M_POP: return (pop_check_mailbox (ctx, index_hint)); #endif /* USE_POP */ + +#ifdef USE_NOTMUTCH + case M_NOTMUCH: + return nm_check_database(cxt, index_hint); +#endif } } @@ -1407,7 +1430,7 @@ int mx_check_mailbox (CONTEXT *ctx, int *index_hint, int lock) MESSAGE *mx_open_message (CONTEXT *ctx, int msgno) { MESSAGE *msg; - + msg = safe_calloc (1, sizeof (MESSAGE)); switch (msg->magic = ctx->magic) { @@ -1418,15 +1441,24 @@ MESSAGE *mx_open_message (CONTEXT *ctx, int msgno) case M_MH: case M_MAILDIR: +#ifdef USE_NOTMUCH + case M_NOTMUCH: +#endif { HEADER *cur = ctx->hdrs[msgno]; char path[_POSIX_PATH_MAX]; - - snprintf (path, sizeof (path), "%s/%s", ctx->path, cur->path); - + char *folder = ctx->path; +#ifdef USE_NOTMUCH + if (ctx->magic == M_NOTMUCH) { + msg->magic = nm_header_get_magic(cur); + folder = nm_header_get_folder(cur); + } +#endif + snprintf (path, sizeof (path), "%s/%s", folder, cur->path); + if ((msg->fp = fopen (path, "r")) == NULL && errno == ENOENT && - ctx->magic == M_MAILDIR) - msg->fp = maildir_open_find_message (ctx->path, cur->path); + (ctx->magic == M_MAILDIR || ctx->magic == M_NOTMUCH)) + msg->fp = maildir_open_find_message (folder, cur->path); if (msg->fp == NULL) { @@ -1501,13 +1533,17 @@ int mx_commit_message (MESSAGE *msg, CONTEXT *ctx) break; } #endif - + case M_MAILDIR: { r = maildir_commit_message (ctx, msg, NULL); break; } - + + case M_NOTMUCH: + mutt_perror _("Can't write to virtual folder."); + break; + case M_MH: { r = mh_commit_message (ctx, msg, NULL); @@ -1521,7 +1557,7 @@ int mx_commit_message (MESSAGE *msg, CONTEXT *ctx) mutt_perror _("Can't write message"); r = -1; } - + return r; } @@ -1531,14 +1567,15 @@ int mx_close_message (MESSAGE **msg) int r = 0; if ((*msg)->magic == M_MH || (*msg)->magic == M_MAILDIR - || (*msg)->magic == M_IMAP || (*msg)->magic == M_POP) + || (*msg)->magic == M_IMAP || (*msg)->magic == M_POP + || (*msg)->magic == M_NOTMUCH) { r = safe_fclose (&(*msg)->fp); } else (*msg)->fp = NULL; - if ((*msg)->path) + if ((*msg)->path && (*msg)->magic != M_NOTMUCH) { dprint (1, (debugfile, "mx_close_message (): unlinking %s\n", (*msg)->path));