From: Karel Zak Date: Thu, 12 Apr 2012 10:18:06 +0000 (+0200) Subject: explicitly require notmuch context X-Git-Tag: neomutt-20160404~13^2~72 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=616ae56e64f635f2b0bff25e58c5521df53c972e;p=neomutt explicitly require notmuch context Signed-off-by: Karel Zak --- diff --git a/browser.c b/browser.c index 11f1bc9c9..99089eeb3 100644 --- a/browser.c +++ b/browser.c @@ -522,7 +522,7 @@ static int examine_vfolders (MUTTMENU *menu, struct browser_state *state) { if (mx_is_notmuch (tmp->path)) { - nm_get_count(tmp->path, &tmp->msg_count, &tmp->msg_unread); + nm_nonctx_get_count(tmp->path, &tmp->msg_count, &tmp->msg_unread); add_folder (menu, state, tmp->path, tmp->desc, NULL, tmp->msg_unread, tmp->msg_count); continue; diff --git a/buffy.c b/buffy.c index 1e8742d58..094af7256 100644 --- a/buffy.c +++ b/buffy.c @@ -668,7 +668,7 @@ static void buffy_check(BUFFY *tmp, struct stat *contex_sb) tmp->msg_count = 0; tmp->msg_unread = 0; tmp->msg_flagged = 0; - nm_get_count(tmp->path, &tmp->msg_count, &tmp->msg_unread); + nm_nonctx_get_count(tmp->path, &tmp->msg_count, &tmp->msg_unread); if (tmp->msg_unread > 0) BuffyCount++; break; diff --git a/mutt_notmuch.c b/mutt_notmuch.c index ffba8a59c..9de5079dc 100644 --- a/mutt_notmuch.c +++ b/mutt_notmuch.c @@ -2,6 +2,18 @@ * Notmuch support for mutt * * Copyright (C) 2011, 2012 Karel Zak + * + * Notes: + * + * - notmuch uses private CONTEXT->data and private HEADER->data + * + * - all exported functions are usable within notmuch context only + * + * - all functions have to be covered by "ctx->magic == M_NOTMUCH" check + * (it's implemented in get_ctxdata(), get_db() and another basic functions). + * + * - exception are nm_nonctx_* functions -- these functions use nm_default_uri + * (or parse URI from another resourse) */ #if HAVE_CONFIG_H # include "config.h" @@ -200,7 +212,7 @@ static int deinit_context(CONTEXT *ctx) { int i; - if (!ctx) + if (!ctx || ctx->magic != M_NOTMUCH) return -1; for (i = 0; i < ctx->msgcount; i++) { @@ -275,7 +287,10 @@ char *nm_header_get_fullpath(HEADER *h, char *buf, size_t bufsz) static struct nm_ctxdata *get_ctxdata(CONTEXT *ctx) { - return ctx->data; + if (ctx && ctx->magic == M_NOTMUCH) + return ctx->data; + + return NULL; } static char *get_query_string(CONTEXT *ctx) @@ -354,7 +369,7 @@ static notmuch_database_t *get_db(CONTEXT *ctx, int writable) return data->db; } -static void release_db(CONTEXT *ctx) +static int release_db(CONTEXT *ctx) { struct nm_ctxdata *data = get_ctxdata(ctx); @@ -363,7 +378,10 @@ static void release_db(CONTEXT *ctx) notmuch_database_close(data->db); data->db = NULL; data->longrun = FALSE; + return 0; } + + return -1; } void nm_longrun_init(CONTEXT *ctx, int writable) @@ -378,12 +396,8 @@ void nm_longrun_init(CONTEXT *ctx, int writable) void nm_longrun_done(CONTEXT *ctx) { - struct nm_ctxdata *data = get_ctxdata(ctx); - - if (data) { - release_db(ctx); + if (release_db(ctx) == 0) dprint(2, (debugfile, "nm: long run deinitialied\n")); - } } static int is_longrun(CONTEXT *ctx) @@ -644,10 +658,10 @@ done: char *nm_uri_from_query(CONTEXT *ctx, char *buf, size_t bufsz) { - struct nm_ctxdata *data; + struct nm_ctxdata *data = get_ctxdata(ctx); char uri[_POSIX_PATH_MAX]; - if (ctx && ctx->magic == M_NOTMUCH && (data = get_ctxdata(ctx))) + if (data) snprintf(uri, sizeof(uri), "notmuch://%s?query=%s", get_db_filename(ctx), buf); else if (NotmuchDefaultUri) snprintf(uri, sizeof(uri), "%s?query=%s", NotmuchDefaultUri, buf); @@ -685,10 +699,8 @@ int nm_modify_message_tags(CONTEXT *ctx, HEADER *hdr, char *buf0) int rc = -1; char *tag = NULL, *end = NULL, *p, *buf = NULL; - if (!buf0 || !*buf0 || !ctx - || ctx->magic != M_NOTMUCH - || !(db = get_db(ctx, TRUE)) - || !(msg = get_nm_message(db, hdr))) + if (!buf0 || !*buf0 || !(db = get_db(ctx, TRUE)) + || !(msg = get_nm_message(db, hdr))) goto done; dprint(1, (debugfile, "nm: tags modify: '%s'\n", buf0)); @@ -865,7 +877,7 @@ static unsigned count_query(notmuch_database_t *db, const char *qstr) return res; } -int nm_get_count(char *path, int *all, int *new) +int nm_nonctx_get_count(char *path, int *all, int *new) { struct uri_tag *query_items = NULL, *item; char *db_filename = NULL, *db_query = NULL; diff --git a/mutt_notmuch.h b/mutt_notmuch.h index b52d4bf51..0a26c8203 100644 --- a/mutt_notmuch.h +++ b/mutt_notmuch.h @@ -11,7 +11,6 @@ char *nm_header_get_folder(HEADER *h); int nm_header_get_magic(HEADER *h); char *nm_header_get_fullpath(HEADER *h, char *buf, size_t bufsz); char *nm_header_get_tags(HEADER *h); -int nm_get_count(char *path, int *all, int *new); int nm_update_filename(CONTEXT *ctx, const char *old, const char *new); char *nm_uri_from_query(CONTEXT *ctx, char *buf, size_t bufsz); int nm_modify_message_tags(CONTEXT *ctx, HEADER *hdr, char *tags); @@ -23,4 +22,9 @@ char *nm_get_description(CONTEXT *ctx); void nm_debug_check(CONTEXT *ctx); +/* + * functions usable outside notmuch CONTEXT + */ +int nm_nonctx_get_count(char *path, int *all, int *new); + #endif /* _MUTT_NOTMUCH_H_ */