]> granicus.if.org Git - neomutt/commitdiff
explicitly require notmuch context
authorKarel Zak <kzak@redhat.com>
Thu, 12 Apr 2012 10:18:06 +0000 (12:18 +0200)
committerRichard Russon <rich@flatcap.org>
Mon, 14 Mar 2016 23:11:41 +0000 (23:11 +0000)
Signed-off-by: Karel Zak <kzak@redhat.com>
browser.c
buffy.c
mutt_notmuch.c
mutt_notmuch.h

index 2564ee6a38737a37f453d8749b066d56bb9e3f35..3da0774185de2b20215e63dc7d8ca58a4a88bbaa 100644 (file)
--- 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 4e9a75509d95588089c714877f5914f6121b3361..a5bbda9d92406b329cf0beddf9bf89f71da5dabf 100644 (file)
--- 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;
index ffba8a59cde52069ab7b78eaeff0a37785acebad..9de5079dc99a1c4868ec03f0bad533feacd91455 100644 (file)
@@ -2,6 +2,18 @@
  * Notmuch support for mutt
  *
  * Copyright (C) 2011, 2012 Karel Zak <kzak@redhat.com>
+ *
+ * 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;
index b52d4bf5190b6db372213c91c508526ce7a1dffb..0a26c8203003b08da5fcc0f4b8374d770a6140be 100644 (file)
@@ -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_ */