From: Austin Ray Date: Thu, 11 Oct 2018 18:18:40 +0000 (-0400) Subject: mailbox: try to find existing description X-Git-Tag: 2019-10-25~602^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3a5a978dc9cbd5f1dbbeaa7b298a01f7245bdd31;p=neomutt mailbox: try to find existing description `mx_mbox_open(...)` creates a new `Context`, which requires creating new `Mailbox` instances. Modified `mailbox_new(...)` to try and find an existing description that matches the mailbox `path`. --- diff --git a/mailbox.c b/mailbox.c index 79988f0e4..7b7aa702c 100644 --- a/mailbox.c +++ b/mailbox.c @@ -76,6 +76,23 @@ static short MailboxNotify = 0; /**< # of unnotified new boxes */ struct MailboxList AllMailboxes = STAILQ_HEAD_INITIALIZER(AllMailboxes); +/** + * get_mailbox_description - Find a mailbox's description given a path. + * @param path Path to the mailbox + * @retval ptr Description + * @retval NULL No mailbox matching path + */ +static char *get_mailbox_description(const char *path) +{ + struct MailboxNode *np = NULL; + STAILQ_FOREACH(np, &AllMailboxes, entries) + { + if (np->m->desc && (strcmp(np->m->path, path) == 0)) + return np->m->desc; + } + return NULL; +} + /** * mailbox_new - Create a new Mailbox * @param path Path to the mailbox @@ -90,6 +107,7 @@ struct Mailbox *mailbox_new(const char *path) char *r = realpath(path, rp); mutt_str_strfcpy(mailbox->realpath, r ? rp : path, sizeof(mailbox->realpath)); mailbox->magic = MUTT_UNKNOWN; + mailbox->desc = get_mailbox_description(mailbox->path); return mailbox; }