From 6b9065ab1c5147dc9b2df85b7744b20ddd093726 Mon Sep 17 00:00:00 2001 From: Austin Ray Date: Tue, 1 Jan 2019 15:59:48 -0500 Subject: [PATCH] Index: try description when changing mailboxes 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 | 18 +++++++++++++++--- mailbox.c | 21 +++++++++++++++++++++ mailbox.h | 1 + 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/index.c b/index.c index 8f3d661cb..53bbbb14e 100644 --- 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 */ diff --git a/mailbox.c b/mailbox.c index 0b8855e35..f8b468d44 100644 --- 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 diff --git a/mailbox.h b/mailbox.h index e8ab1420a..e2baddfd1 100644 --- 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); -- 2.40.0