]> granicus.if.org Git - neomutt/commitdiff
Index: try description when changing mailboxes 1516/head
authorAustin Ray <austin@austinray.io>
Tue, 1 Jan 2019 20:59:48 +0000 (15:59 -0500)
committerRichard Russon <rich@flatcap.org>
Wed, 2 Jan 2019 22:56:12 +0000 (22:56 +0000)
Mailbox: find mailbox by description

Introduce `mutt_find_mailbox_desc()`, which takes a pointer to a
description, and tries to find a mailbox that corresponds to it.

With the introduction of `named-mailboxes` and removal of
`virtual-mailboxes` special cases, users may prefer to operate with
descriptions instead of (potentially) ugly paths. We can no longer
assume that a buffer is a path and require a method to find by
description.

This is not included as an `mxapi` function since `desc` is common to
all mailboxes so the backends do not need implement their own function.

Index: try description when changing mailboxes

Since mailbox descriptions are more prevalent with `named-mailboxes` and
`virtual-mailbox` special cases being removed, some users will try to
change folders with a description instead of a path.

This commit modifies `main_change_folder()` to look for a mailbox with a
given description if path probing fails.

index.c
mailbox.c
mailbox.h

diff --git a/index.c b/index.c
index 8f3d661cb38e483320f8b82b321917b4b4e3fdd1..53bbbb14e22e1d46b15e5fe766b64dca731cf0b3 100644 (file)
--- a/index.c
+++ b/index.c
@@ -569,8 +569,20 @@ static int main_change_folder(struct Menu *menu, int op, struct Mailbox *m,
   enum MailboxType magic = mx_path_probe(buf, NULL);
   if ((magic == MUTT_MAILBOX_ERROR) || (magic == MUTT_UNKNOWN))
   {
-    mutt_error(_("%s is not a mailbox"), buf);
-    return -1;
+    // Try and see if the buffer matches a description before we bail. We'll receive a
+    // non-null pointer if there is a corresponding mailbox.
+    m = mutt_find_mailbox_desc(buf);
+    if (m)
+    {
+      magic = m->magic;
+      mutt_str_strfcpy(buf, m->path, buflen);
+    }
+    else
+    {
+      // Bail.
+      mutt_error(_("%s is not a mailbox"), buf);
+      return -1;
+    }
   }
 
   /* keepalive failure in mutt_enter_fname may kill connection. #3028 */
@@ -965,7 +977,7 @@ static void index_custom_redraw(struct Menu *menu)
  */
 int mutt_index_menu(void)
 {
-  char buf[LONG_STRING], helpstr[LONG_STRING];
+  char buf[PATH_MAX], helpstr[LONG_STRING];
   int flags;
   int op = OP_NULL;
   bool done = false; /* controls when to exit the "event" loop */
index 0b8855e35d975b5e961d50153043d19bb37487da..f8b468d4414e37662f51a8a668bf20a5ab9830c7 100644 (file)
--- a/mailbox.c
+++ b/mailbox.c
@@ -289,6 +289,27 @@ struct Mailbox *mutt_find_mailbox(const char *path)
   return NULL;
 }
 
+/**
+ * mutt_find_mailbox_desc - Find the mailbox with a given description
+ * @param desc Description to match
+ * @retval ptr Matching Mailbox
+ * @retval NULL No matching mailbox found
+ */
+struct Mailbox *mutt_find_mailbox_desc(const char *desc)
+{
+  if (!desc)
+    return NULL;
+
+  struct MailboxNode *np = NULL;
+  STAILQ_FOREACH(np, &AllMailboxes, entries)
+  {
+    if (np->m->desc && mutt_str_strcmp(np->m->desc, desc) == 0)
+      return np->m;
+  }
+
+  return NULL;
+}
+
 /**
  * mutt_update_mailbox - Get the mailbox's current size
  * @param m Mailbox to check
index e8ab1420a300a760205e587232651e0c1340e51e..e2baddfd1e748c5c348d1391a387c94d6473a22a 100644 (file)
--- a/mailbox.h
+++ b/mailbox.h
@@ -149,6 +149,7 @@ void            mailbox_free(struct Mailbox **m);
 void            mutt_context_free(struct Context **ctx);
 
 struct Mailbox *mutt_find_mailbox(const char *path);
+struct Mailbox *mutt_find_mailbox_desc(const char *desc);
 void mutt_update_mailbox(struct Mailbox *m);
 
 void mutt_mailbox_cleanup(const char *path, struct stat *st);