]> granicus.if.org Git - neomutt/commitdiff
notmuch: virtual-mailboxes should accept a limit
authorAustin Ray <austin.duke.ray@gmail.com>
Tue, 17 Oct 2017 21:23:36 +0000 (17:23 -0400)
committerRichard Russon <rich@flatcap.org>
Tue, 17 Oct 2017 21:23:36 +0000 (22:23 +0100)
* Fix issue #849

nm_uri_from_query() checks if there is a custom limit and includes it
in the URI. This keeps the limit intact after nm_normalize_uri()
terminates. Otherwise, the limit is stored within nm_normalize_uri()'s
temporary NmCtxData struct and lost upon termination.

Additionally, nm_normalize_uri() properly initializes tmp_ctxdata, which
sets the default db_limit value. This ensures db_limit is either
NmDbLimit or the custom limit. My earlier attempt to resolve #849 did
not initialize db_limit and suffered from random db_limit values.

The url_parse_query() check was removed from nm_normalize_uri() as
new_ctxdata() contains the same block of code. Error message numbering
has been updated the reflect the change.

* Remove redundant variable

Refactor per suggestions in code review to remove redundant variable and
update method signature.

The removal of the redundant variable prompt the need to change
tmp_ctxdata from NmCtxData to *NmCtxData. Calls to its fields have been
updated to reflect its new status.

* wipe the context before use

mutt_notmuch.c

index af5893d5c1eeff15b44e4bd8a47564bb3d6d0b71..3a22a89369f03fc485b2ba6afe2cbff48a360412 100644 (file)
@@ -334,7 +334,7 @@ static void free_ctxdata(struct NmCtxData *data)
  * A new nm_ctxdata struct is created, then the query is parsed and saved
  * within it.  This should be freed using free_ctxdata().
  */
-static struct NmCtxData *new_ctxdata(char *uri)
+static struct NmCtxData *new_ctxdata(const char *uri)
 {
   struct NmCtxData *data = NULL;
 
@@ -1741,9 +1741,20 @@ char *nm_uri_from_query(struct Context *ctx, char *buf, size_t bufsz)
   int added;
 
   if (data)
-    added = snprintf(uri, sizeof(uri),
-                     "notmuch://%s?type=%s&query=", get_db_filename(data),
-                     query_type_to_string(data->query_type));
+  {
+    if (get_limit(data) != NmDbLimit)
+    {
+      added = snprintf(uri, sizeof(uri),
+                       "notmuch://%s?type=%s&limit=%d&query=", get_db_filename(data),
+                       query_type_to_string(data->query_type), get_limit(data));
+    }
+    else
+    {
+      added = snprintf(uri, sizeof(uri),
+                       "notmuch://%s?type=%s&query=", get_db_filename(data),
+                       query_type_to_string(data->query_type));
+    }
+  }
   else if (NmDefaultUri)
     added = snprintf(uri, sizeof(uri), "%s?type=%s&query=", NmDefaultUri,
                      query_type_to_string(string_to_query_type(NmQueryType)));
@@ -1790,39 +1801,39 @@ bool nm_normalize_uri(char *new_uri, const char *orig_uri, size_t new_uri_sz)
   char buf[LONG_STRING];
 
   struct Context tmp_ctx;
-  struct NmCtxData tmp_ctxdata;
+  memset(&tmp_ctx, 0, sizeof(tmp_ctx));
+  struct NmCtxData *tmp_ctxdata = new_ctxdata(orig_uri);
 
-  tmp_ctx.magic = MUTT_NOTMUCH;
-  tmp_ctx.data = &tmp_ctxdata;
-  tmp_ctxdata.db_query = NULL;
-
-  if (!url_parse_query(orig_uri, &tmp_ctxdata.db_filename, &tmp_ctxdata.query_items))
-  {
-    mutt_error(_("failed to parse notmuch uri: %s"), orig_uri);
-    mutt_debug(2, "nm_normalize_uri () -> error #1\n");
+  if (!tmp_ctxdata)
     return false;
-  }
 
-  mutt_debug(2, "nm_normalize_uri #1 () -> db_query: %s\n", tmp_ctxdata.db_query);
+  tmp_ctx.magic = MUTT_NOTMUCH;
+  tmp_ctx.data = tmp_ctxdata;
+
+  mutt_debug(2, "nm_normalize_uri #1 () -> db_query: %s\n", tmp_ctxdata->db_query);
 
-  if (get_query_string(&tmp_ctxdata, false) == NULL)
+  if (get_query_string(tmp_ctxdata, false) == NULL)
   {
     mutt_error(_("failed to parse notmuch uri: %s"), orig_uri);
-    mutt_debug(2, "nm_normalize_uri () -> error #2\n");
+    mutt_debug(2, "nm_normalize_uri () -> error #1\n");
+    FREE(&tmp_ctxdata);
     return false;
   }
 
-  mutt_debug(2, "nm_normalize_uri #2 () -> db_query: %s\n", tmp_ctxdata.db_query);
+  mutt_debug(2, "nm_normalize_uri #2 () -> db_query: %s\n", tmp_ctxdata->db_query);
 
-  strfcpy(buf, tmp_ctxdata.db_query, sizeof(buf));
+  strfcpy(buf, tmp_ctxdata->db_query, sizeof(buf));
 
   if (nm_uri_from_query(&tmp_ctx, buf, sizeof(buf)) == NULL)
   {
     mutt_error(_("failed to parse notmuch uri: %s"), orig_uri);
-    mutt_debug(2, "nm_normalize_uri () -> error #3\n");
+    mutt_debug(2, "nm_normalize_uri () -> error #2\n");
+    FREE(&tmp_ctxdata);
     return true;
   }
 
+  FREE(&tmp_ctxdata);
+
   strncpy(new_uri, buf, new_uri_sz);
 
   mutt_debug(2, "nm_normalize_uri #3 (%s) -> %s\n", orig_uri, new_uri);