From 60f4b3a79450a12ece464b051e261589db22b394 Mon Sep 17 00:00:00 2001 From: Mehdi Abaakouk Date: Wed, 14 Nov 2018 09:15:53 +0100 Subject: [PATCH] imap: create mdata in imap_prepare_mailbox() Hidden mailbox does not call mx_ac_add(). So this change moves the ImapMailboxData initialisation in imap_prepare_mailbox(). This ensures we always have a valid m->mdata; --- imap/imap.c | 32 +++++++++++++++++++------------- imap/util.c | 2 +- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/imap/imap.c b/imap/imap.c index 30aa08196..7e5a00982 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -342,15 +342,31 @@ int imap_prepare_mailbox(struct Mailbox *m, char *mailbox, size_t mailboxlen) if (!m || !m->account) return -1; + struct ImapMailboxData *mdata; struct ImapAccountData *adata = m->account->adata; mutt_account_hook(m->realpath); + if (!m->mdata) + { + struct Url url; + char tmp[PATH_MAX]; + mutt_str_strfcpy(tmp, m->path, sizeof(tmp)); + url_parse(&url, tmp); + + mdata = imap_mdata_new(adata, url.path); + m->mdata = mdata; + m->free_mdata = imap_mdata_free; + mutt_str_strfcpy(mailbox, mdata->name, mailboxlen); + } + else + mdata = m->mdata; + + mutt_str_strfcpy(mailbox, mdata->name, mailboxlen); + if (imap_login(adata) < 0) return -1; - struct ImapMailboxData *mdata = m->mdata; - mutt_str_strfcpy(mailbox, mdata->name, mailboxlen); return 0; } @@ -2060,7 +2076,7 @@ int imap_ac_add(struct Account *a, struct Mailbox *m) // NOTE(sileht): The goal is to use ImapMbox and imap_parse_path() only here // So we can remove it at this end. - if (!a->adata || !m->mdata) + if (!a->adata) { struct ConnAccount *conn_account = mutt_mem_calloc(1, sizeof(struct ConnAccount)); char mailbox[LONG_STRING]; @@ -2084,17 +2100,7 @@ int imap_ac_add(struct Account *a, struct Mailbox *m) } else FREE(&conn_account); - - if (!m->mdata) - { - struct ImapMailboxData *mdata = imap_mdata_new(a->adata, mailbox); - if (!mdata) - return -1; - m->mdata = mdata; - m->free_mdata = imap_mdata_free; - } } - m->account = a; struct MailboxNode *np = mutt_mem_calloc(1, sizeof(*np)); diff --git a/imap/util.c b/imap/util.c index 3cd219105..5e6697c78 100644 --- a/imap/util.c +++ b/imap/util.c @@ -171,7 +171,7 @@ struct ImapMailboxData *imap_mdata_new(struct ImapAccountData *adata, const char mdata->real_name = mutt_str_strdup(name); imap_fix_path(adata, name, buf, sizeof(buf)); - if (!*buf) + if (buf[0] == '\0') mutt_str_strfcpy(buf, "INBOX", sizeof(buf)); mdata->name = mutt_str_strdup(buf); -- 2.40.0