]> granicus.if.org Git - neomutt/commitdiff
notmuch: use mailbox, not context
authorRichard Russon <rich@flatcap.org>
Thu, 6 Sep 2018 09:56:18 +0000 (10:56 +0100)
committerRichard Russon <rich@flatcap.org>
Sun, 9 Sep 2018 15:10:20 +0000 (16:10 +0100)
commands.c
curs_main.c
init.c
notmuch/mutt_notmuch.c
notmuch/mutt_notmuch.h
send.c
status.c

index 6c3db34fd4d9f043015285104df5eb9f8a3fcad3..f6cc68195fc3baecf0f16d2014bb7fbf8fbfc95b 100644 (file)
@@ -1026,7 +1026,7 @@ int mutt_save_message(struct Header *h, bool delete, bool decode, bool decrypt)
 
 #ifdef USE_NOTMUCH
       if (Context->mailbox->magic == MUTT_NOTMUCH)
-        nm_longrun_init(Context, true);
+        nm_longrun_init(Context->mailbox, true);
 #endif
       for (int i = 0; i < Context->mailbox->msg_count; i++)
       {
@@ -1051,7 +1051,7 @@ int mutt_save_message(struct Header *h, bool delete, bool decode, bool decrypt)
       }
 #ifdef USE_NOTMUCH
       if (Context->mailbox->magic == MUTT_NOTMUCH)
-        nm_longrun_done(Context);
+        nm_longrun_done(Context->mailbox);
 #endif
       if (rc != 0)
       {
index 19d0e47f71983399c9c32642ca511e1d54c517bd..a1026176e7ab6f0b1c3abf7230d6a7e544e7da0f 100644 (file)
@@ -1246,7 +1246,7 @@ int mutt_index_menu(void)
 
 #ifdef USE_NOTMUCH
     if (Context)
-      nm_debug_check(Context);
+      nm_debug_check(Context->mailbox);
 #endif
 
     switch (op)
@@ -1999,7 +1999,7 @@ int mutt_index_menu(void)
 
 #ifdef USE_NOTMUCH
           if (Context->mailbox->magic == MUTT_NOTMUCH)
-            nm_longrun_init(Context, true);
+            nm_longrun_init(Context->mailbox, true);
 #endif
           for (px = 0, j = 0; j < Context->mailbox->msg_count; j++)
           {
@@ -2014,8 +2014,8 @@ int mutt_index_menu(void)
               bool still_queried = false;
 #ifdef USE_NOTMUCH
               if (Context->mailbox->magic == MUTT_NOTMUCH)
-                still_queried =
-                    nm_message_is_still_queried(Context, Context->mailbox->hdrs[j]);
+                still_queried = nm_message_is_still_queried(
+                    Context->mailbox, Context->mailbox->hdrs[j]);
 #endif
               Context->mailbox->hdrs[j]->quasi_deleted = !still_queried;
               Context->mailbox->changed = true;
@@ -2023,7 +2023,7 @@ int mutt_index_menu(void)
           }
 #ifdef USE_NOTMUCH
           if (Context->mailbox->magic == MUTT_NOTMUCH)
-            nm_longrun_done(Context);
+            nm_longrun_done(Context->mailbox);
 #endif
           menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
         }
@@ -2039,7 +2039,7 @@ int mutt_index_menu(void)
             bool still_queried = false;
 #ifdef USE_NOTMUCH
             if (Context->mailbox->magic == MUTT_NOTMUCH)
-              still_queried = nm_message_is_still_queried(Context, CURHDR);
+              still_queried = nm_message_is_still_queried(Context->mailbox, CURHDR);
 #endif
             CURHDR->quasi_deleted = !still_queried;
             Context->mailbox->changed = true;
@@ -2079,7 +2079,7 @@ int mutt_index_menu(void)
           mutt_message(_("No query, aborting"));
           break;
         }
-        if (!nm_uri_from_query(Context, buf, sizeof(buf)))
+        if (!nm_uri_from_query(Context->mailbox, buf, sizeof(buf)))
           mutt_message(_("Failed to create query, aborting"));
         else
           main_change_folder(menu, op, buf, sizeof(buf), &oldcount, &index_hint);
@@ -2099,7 +2099,7 @@ int mutt_index_menu(void)
         }
         nm_query_window_backward();
         strncpy(buf, NmQueryWindowCurrentSearch, sizeof(buf));
-        if (!nm_uri_from_query(Context, buf, sizeof(buf)))
+        if (!nm_uri_from_query(Context->mailbox, buf, sizeof(buf)))
           mutt_message(_("Failed to create query, aborting"));
         else
           main_change_folder(menu, op, buf, sizeof(buf), &oldcount, &index_hint);
@@ -2118,7 +2118,7 @@ int mutt_index_menu(void)
         }
         nm_query_window_forward();
         strncpy(buf, NmQueryWindowCurrentSearch, sizeof(buf));
-        if (!nm_uri_from_query(Context, buf, sizeof(buf)))
+        if (!nm_uri_from_query(Context->mailbox, buf, sizeof(buf)))
           mutt_message(_("Failed to create query, aborting"));
         else
         {
@@ -3494,7 +3494,7 @@ int mutt_index_menu(void)
 
 #ifdef USE_NOTMUCH
     if (Context)
-      nm_debug_check(Context);
+      nm_debug_check(Context->mailbox);
 #endif
 
     if (menu->menu == MENU_PAGER)
diff --git a/init.c b/init.c
index 485099d423f0a27eb448434e61da82de6e7e9883..792c22ac971a8ea47129aa0004f1524159517dd6 100644 (file)
--- a/init.c
+++ b/init.c
@@ -225,10 +225,10 @@ static int complete_all_nm_tags(const char *pt)
   memset(Matches, 0, MatchesListsize);
   memset(Completed, 0, sizeof(Completed));
 
-  nm_longrun_init(Context, false);
+  nm_longrun_init(Context->mailbox, false);
 
   /* Work out how many tags there are. */
-  if (nm_get_all_tags(Context, NULL, &tag_count_1) || tag_count_1 == 0)
+  if (nm_get_all_tags(Context->mailbox, NULL, &tag_count_1) || tag_count_1 == 0)
     goto done;
 
   /* Free the old list, if any. */
@@ -243,11 +243,11 @@ static int complete_all_nm_tags(const char *pt)
   nm_tags[tag_count_1] = NULL;
 
   /* Get all the tags. */
-  if (nm_get_all_tags(Context, nm_tags, &tag_count_2) || tag_count_1 != tag_count_2)
+  if (nm_get_all_tags(Context->mailbox, nm_tags, &tag_count_2) || tag_count_1 != tag_count_2)
   {
     FREE(&nm_tags);
     nm_tags = NULL;
-    nm_longrun_done(Context);
+    nm_longrun_done(Context->mailbox);
     return -1;
   }
 
@@ -261,7 +261,7 @@ static int complete_all_nm_tags(const char *pt)
   Matches[NumMatched++] = UserTyped;
 
 done:
-  nm_longrun_done(Context);
+  nm_longrun_done(Context->mailbox);
   return 0;
 }
 #endif
index 7bacfbc53bc6048322aa41d20841b273e213c419..94a543a5ec46c83643b3fb6da270dad6321eaf92 100644 (file)
@@ -170,7 +170,7 @@ static void free_hdrdata(struct NmHdrData *data)
  * free_mboxdata - Free data attached to the context
  * @param data Notmuch data
  *
- * The nm_mboxdata struct stores global Notmuch data, such as the connection to
+ * The NmMboxData struct stores global Notmuch data, such as the connection to
  * the database.  This function will close the database, free the resources and
  * the struct itself.
  */
@@ -198,11 +198,11 @@ static void free_mboxdata(void *data)
 }
 
 /**
- * new_mboxdata - Create a new nm_mboxdata object from a query
+ * new_mboxdata - Create a new NmMboxData object from a query
  * @param uri Notmuch query string
- * @retval ptr New nm_mboxdata struct
+ * @retval ptr New NmMboxData struct
  *
- * A new nm_mboxdata struct is created, then the query is parsed and saved
+ * A new NmMboxData struct is created, then the query is parsed and saved
  * within it.  This should be freed using free_mboxdata().
  */
 static struct NmMboxData *new_mboxdata(const char *uri)
@@ -233,7 +233,7 @@ static struct NmMboxData *new_mboxdata(const char *uri)
  * @retval  0 Success
  * @retval -1 Error Bad format
  *
- * Create a new nm_mboxdata struct and add it Mailbox::data.
+ * Create a new NmMboxData struct and add it Mailbox::data.
  * Notmuch-specific data will be stored in this struct.
  * This struct can be freed using free_hdrdata().
  */
@@ -1022,21 +1022,21 @@ static const char *get_message_last_filename(notmuch_message_t *msg)
 
 /**
  * progress_reset - Reset the progress counter
- * @param ctx Mailbox
+ * @param mailbox Mailbox
  */
-static void progress_reset(struct Context *ctx)
+static void progress_reset(struct Mailbox *mailbox)
 {
   struct NmMboxData *data = NULL;
 
-  if (ctx->mailbox->quiet)
+  if (mailbox->quiet)
     return;
 
-  data = get_mboxdata(ctx->mailbox);
+  data = get_mboxdata(mailbox);
   if (!data)
     return;
 
   memset(&data->progress, 0, sizeof(data->progress));
-  data->oldmsgcount = ctx->mailbox->msg_count;
+  data->oldmsgcount = mailbox->msg_count;
   data->ignmsgcount = 0;
   data->noprogress = false;
   data->progress_ready = false;
@@ -1044,14 +1044,14 @@ static void progress_reset(struct Context *ctx)
 
 /**
  * progress_update - Update the progress counter
- * @param ctx Mailbox
+ * @param mailbox Mailbox
  * @param q   Notmuch query
  */
-static void progress_update(struct Context *ctx, notmuch_query_t *q)
+static void progress_update(struct Mailbox *mailbox, notmuch_query_t *q)
 {
-  struct NmMboxData *data = get_mboxdata(ctx->mailbox);
+  struct NmMboxData *data = get_mboxdata(mailbox);
 
-  if (ctx->mailbox->quiet || !data || data->noprogress)
+  if (mailbox->quiet || !data || data->noprogress)
     return;
 
   if (!data->progress_ready && q)
@@ -1076,8 +1076,7 @@ static void progress_update(struct Context *ctx, notmuch_query_t *q)
   if (data->progress_ready)
   {
     mutt_progress_update(&data->progress,
-                         ctx->mailbox->msg_count + data->ignmsgcount - data->oldmsgcount,
-                         -1);
+                         mailbox->msg_count + data->ignmsgcount - data->oldmsgcount, -1);
   }
 }
 
@@ -1141,8 +1140,8 @@ static void append_message(struct Context *ctx, notmuch_query_t *q,
   if (dedup && get_mutt_header(ctx, msg))
   {
     data->ignmsgcount++;
-    progress_update(ctx, q);
-    mutt_debug(2, "nm: ignore id=%s, already in the context\n",
+    progress_update(ctx->mailbox, q);
+    mutt_debug(2, "nm: ignore id=%s, already in the mailbox\n",
                notmuch_message_get_message_id(msg));
     return;
   }
@@ -1209,7 +1208,7 @@ static void append_message(struct Context *ctx, notmuch_query_t *q,
       hd->oldpath = mutt_str_strdup(path);
     }
   }
-  progress_update(ctx, q);
+  progress_update(ctx->mailbox, q);
 done:
   FREE(&newpath);
 }
@@ -1786,12 +1785,12 @@ char *nm_header_get_folder(struct Header *h)
 
 /**
  * nm_longrun_init - Start a long transaction
- * @param ctx      Mailbox
+ * @param mailbox  Mailbox
  * @param writable Read/write?
  */
-void nm_longrun_init(struct Context *ctx, bool writable)
+void nm_longrun_init(struct Mailbox *mailbox, bool writable)
 {
-  struct NmMboxData *data = get_mboxdata(ctx->mailbox);
+  struct NmMboxData *data = get_mboxdata(mailbox);
 
   if (data && get_db(data, writable))
   {
@@ -1802,11 +1801,11 @@ void nm_longrun_init(struct Context *ctx, bool writable)
 
 /**
  * nm_longrun_done - Finish a long transaction
- * @param ctx Mailbox
+ * @param mailbox Mailbox
  */
-void nm_longrun_done(struct Context *ctx)
+void nm_longrun_done(struct Mailbox *mailbox)
 {
-  struct NmMboxData *data = get_mboxdata(ctx->mailbox);
+  struct NmMboxData *data = get_mboxdata(mailbox);
 
   if (data && (release_db(data) == 0))
     mutt_debug(2, "nm: long run deinitialized\n");
@@ -1814,11 +1813,11 @@ void nm_longrun_done(struct Context *ctx)
 
 /**
  * nm_debug_check - Check if the database is open
- * @param ctx Mailbox
+ * @param mailbox Mailbox
  */
-void nm_debug_check(struct Context *ctx)
+void nm_debug_check(struct Mailbox *mailbox)
 {
-  struct NmMboxData *data = get_mboxdata(ctx->mailbox);
+  struct NmMboxData *data = get_mboxdata(mailbox);
   if (!data)
     return;
 
@@ -1854,7 +1853,7 @@ int nm_read_entire_thread(struct Context *ctx, struct Header *h)
   mutt_debug(1, "nm: reading entire-thread messages...[current count=%d]\n",
              ctx->mailbox->msg_count);
 
-  progress_reset(ctx);
+  progress_reset(ctx->mailbox);
   id = notmuch_message_get_thread_id(msg);
   if (!id)
     goto done;
@@ -1892,16 +1891,16 @@ done:
 
 /**
  * nm_uri_from_query - Turn a query into a URI
- * @param ctx    Mailbox
- * @param buf    Buffer for URI
- * @param buflen Length of buffer
+ * @param mailbox Mailbox
+ * @param buf     Buffer for URI
+ * @param buflen  Length of buffer
  * @retval ptr  Query as a URI
  * @retval NULL Error
  */
-char *nm_uri_from_query(struct Context *ctx, char *buf, size_t buflen)
+char *nm_uri_from_query(struct Mailbox *mailbox, char *buf, size_t buflen)
 {
   mutt_debug(2, "(%s)\n", buf);
-  struct NmMboxData *data = get_mboxdata(ctx->mailbox);
+  struct NmMboxData *data = get_mboxdata(mailbox);
   char uri[PATH_MAX + LONG_STRING + 32]; /* path to DB + query + URI "decoration" */
   int added;
 
@@ -1970,14 +1969,14 @@ bool nm_normalize_uri(const char *uri, char *buf, size_t buflen)
   char tmp[PATH_MAX];
   int rc = -1;
 
-  struct Context tmp_ctx = { 0 };
+  struct Mailbox tmp_mbox = { 0 };
   struct NmMboxData *tmp_mboxdata = new_mboxdata(uri);
 
   if (!tmp_mboxdata)
     return false;
 
-  tmp_ctx.mailbox->magic = MUTT_NOTMUCH;
-  tmp_ctx.mailbox->data = tmp_mboxdata;
+  tmp_mbox.magic = MUTT_NOTMUCH;
+  tmp_mbox.data = tmp_mboxdata;
 
   mutt_debug(2, "#1 () -> db_query: %s\n", tmp_mboxdata->db_query);
 
@@ -1988,7 +1987,7 @@ bool nm_normalize_uri(const char *uri, char *buf, size_t buflen)
 
   mutt_str_strfcpy(tmp, tmp_mboxdata->db_query, sizeof(tmp));
 
-  if (!nm_uri_from_query(&tmp_ctx, tmp, sizeof(tmp)))
+  if (!nm_uri_from_query(&tmp_mbox, tmp, sizeof(tmp)))
     goto gone;
 
   strncpy(buf, tmp, buflen);
@@ -2090,14 +2089,14 @@ done:
 
 /**
  * nm_message_is_still_queried - Is a message still visible in the query?
- * @param ctx Mailbox
- * @param hdr Email Header
+ * @param mailbox Mailbox
+ * @param hdr     Email Header
  * @retval true Message is still in query
  */
-bool nm_message_is_still_queried(struct Context *ctx, struct Header *hdr)
+bool nm_message_is_still_queried(struct Mailbox *mailbox, struct Header *hdr)
 {
   char *new_str = NULL;
-  struct NmMboxData *data = get_mboxdata(ctx->mailbox);
+  struct NmMboxData *data = get_mboxdata(mailbox);
   bool result = false;
 
   notmuch_database_t *db = get_db(data, false);
@@ -2281,16 +2280,16 @@ done:
 
 /**
  * nm_get_description - Get the folder's description
- * @param ctx Mailbox
- * @retval ptr  Description
+ * @param  mailbox Mailbox
+ * @retval ptr     Description
  * @retval NULL No description
  */
-char *nm_get_description(struct Context *ctx)
+char *nm_get_description(struct Mailbox *mailbox)
 {
   struct MailboxNode *np = NULL;
   STAILQ_FOREACH(np, &AllMailboxes, entries)
   {
-    if (np->b->desc && (strcmp(np->b->path, ctx->mailbox->path) == 0))
+    if (np->b->desc && (strcmp(np->b->path, mailbox->path) == 0))
       return np->b->desc;
   }
 
@@ -2326,19 +2325,19 @@ int nm_description_to_path(const char *desc, char *buf, size_t buflen)
 
 /**
  * nm_record_message - Add a message to the Notmuch database
- * @param ctx  Mailbox
- * @param path Path of the email
- * @param h    Email Header
+ * @param mailbox Mailbox
+ * @param path    Path of the email
+ * @param h       Email Header
  * @retval  0 Success
  * @retval -1 Failure
  */
-int nm_record_message(struct Context *ctx, char *path, struct Header *h)
+int nm_record_message(struct Mailbox *mailbox, char *path, struct Header *h)
 {
   notmuch_database_t *db = NULL;
   notmuch_status_t st;
   notmuch_message_t *msg = NULL;
   int rc = -1, trans;
-  struct NmMboxData *data = get_mboxdata(ctx->mailbox);
+  struct NmMboxData *data = get_mboxdata(mailbox);
 
   if (!path || !data || (access(path, F_OK) != 0))
     return 0;
@@ -2389,7 +2388,7 @@ done:
 
 /**
  * nm_get_all_tags - Fill a list with all notmuch tags
- * @param ctx       Mailbox
+ * @param mailbox   Mailbox
  * @param tag_list  List of tags
  * @param tag_count Number of tags
  * @retval  0 Success
@@ -2397,9 +2396,9 @@ done:
  *
  * If tag_list is NULL, just count the tags.
  */
-int nm_get_all_tags(struct Context *ctx, char **tag_list, int *tag_count)
+int nm_get_all_tags(struct Mailbox *mailbox, char **tag_list, int *tag_count)
 {
-  struct NmMboxData *data = get_mboxdata(ctx->mailbox);
+  struct NmMboxData *data = get_mboxdata(mailbox);
   notmuch_database_t *db = NULL;
   notmuch_tags_t *tags = NULL;
   const char *tag = NULL;
@@ -2457,7 +2456,7 @@ static int nm_mbox_open(struct Context *ctx)
 
   mutt_debug(1, "nm: reading messages...[current count=%d]\n", ctx->mailbox->msg_count);
 
-  progress_reset(ctx);
+  progress_reset(ctx->mailbox);
 
   q = get_query(data, false);
   if (q)
index 14c9f272c10b52a0be4badcab2ef860071a0c2cc..0e52b63257ec7a3c6243439c0c5f9698d88c8b40 100644 (file)
@@ -56,22 +56,22 @@ int nm_read_entire_thread(struct Context *ctx, struct Header *h);
 char *nm_header_get_folder(struct Header *h);
 int nm_update_filename(struct Context *ctx, const char *old, const char *new, struct Header *h);
 bool nm_normalize_uri(const char *uri, char *buf, size_t buflen);
-char *nm_uri_from_query(struct Context *ctx, char *buf, size_t buflen);
-bool nm_message_is_still_queried(struct Context *ctx, struct Header *hdr);
+char *nm_uri_from_query(struct Mailbox *mailbox, char *buf, size_t buflen);
+bool nm_message_is_still_queried(struct Mailbox *mailbox, struct Header *hdr);
 
 void nm_query_window_backward(void);
 void nm_query_window_forward(void);
 
-void nm_longrun_init(struct Context *ctx, bool writable);
-void nm_longrun_done(struct Context *ctx);
+void nm_longrun_init(struct Mailbox *mailbox, bool writable);
+void nm_longrun_done(struct Mailbox *mailbox);
 
-char *nm_get_description(struct Context *ctx);
+char *nm_get_description(struct Mailbox *mailbox);
 int nm_description_to_path(const char *desc, char *buf, size_t buflen);
 
-int nm_record_message(struct Context *ctx, char *path, struct Header *h);
+int nm_record_message(struct Mailbox *mailbox, char *path, struct Header *h);
 
-void nm_debug_check(struct Context *ctx);
-int nm_get_all_tags(struct Context *ctx, char **tag_list, int *tag_count);
+void nm_debug_check(struct Mailbox *mailbox);
+int nm_get_all_tags(struct Mailbox *mailbox, char **tag_list, int *tag_count);
 
 /*
  * functions usable outside notmuch Context
diff --git a/send.c b/send.c
index 8cf32cad03f73625808d0fdfbad1fe35515de3c5..a5d3820aaf9696b1e360877eeb2bb0332b7ace31 100644 (file)
--- a/send.c
+++ b/send.c
@@ -2397,7 +2397,7 @@ int ci_send_message(int flags, struct Header *msg, char *tempfile,
                               _("Mail sent"));
 #ifdef USE_NOTMUCH
     if (NmRecord)
-      nm_record_message(ctx, finalpath, cur);
+      nm_record_message(ctx->mailbox, finalpath, cur);
 #endif
   }
 
index 6360a12209ae54e1a499660d8331a1d04f70f636..62400872a55f9fcf755b4c8356ef4ce3c92ff393 100644 (file)
--- a/status.c
+++ b/status.c
@@ -126,7 +126,7 @@ static const char *status_format_str(char *buf, size_t buflen, size_t col, int c
 #ifdef USE_NOTMUCH
       char *p = NULL;
       if (Context && Context->mailbox->magic == MUTT_NOTMUCH &&
-          (p = nm_get_description(Context)))
+          (p = nm_get_description(Context->mailbox)))
         mutt_str_strfcpy(tmp, p, sizeof(tmp));
       else
 #endif