From 7f3d7bbdc94df62ed612ec221a43d0358313e1d3 Mon Sep 17 00:00:00 2001 From: Mehdi Abaakouk Date: Thu, 8 Nov 2018 17:25:48 +0100 Subject: [PATCH] imap: remove imap_conn_find from imap_browse --- imap/browse.c | 27 ++++++++++++++++++++++++--- imap/imap.c | 8 ++++---- imap/imap_private.h | 1 + 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/imap/browse.c b/imap/browse.c index 6db41c61f..b94b93c15 100644 --- a/imap/browse.c +++ b/imap/browse.c @@ -33,10 +33,11 @@ #include #include #include -#include "imap_private.h" +#include "imap/imap_private.h" #include "mutt/mutt.h" #include "conn/conn.h" #include "mutt.h" +#include "account.h" #include "browser.h" #include "context.h" #include "curs_lib.h" @@ -200,7 +201,7 @@ int imap_browse(char *path, struct BrowserState *state) char ctmp; bool showparents = false; bool save_lsub; - struct ImapMbox mx; + struct ImapMbox mx, mx_tmp; if (imap_parse_path(path, &mx)) { @@ -212,7 +213,27 @@ int imap_browse(char *path, struct BrowserState *state) ImapCheckSubscribed = false; mutt_str_strfcpy(list_cmd, ImapListSubscribed ? "LSUB" : "LIST", sizeof(list_cmd)); - adata = imap_conn_find(&(mx.account), 0); + struct MailboxNode *np = NULL; + STAILQ_FOREACH(np, &AllMailboxes, entries) + { + if (np->m->magic != MUTT_IMAP) + continue; + if (imap_parse_path(np->m->path, &mx_tmp) < 0) + continue; + + // Pick first mailbox connected on the same server + if (imap_account_match(&mx.account, &mx_tmp.account)) + { + /* ensure we are connected */ + int rc = imap_prepare_mailbox(np->m, &mx, path, buf, sizeof(buf), false, true); + if (rc < 0) + continue; + + adata = np->m->account->adata; + break; + } + } + FREE(&mx_tmp.mbox); if (!adata) goto fail; diff --git a/imap/imap.c b/imap/imap.c index 3718f6d14..a9f61d1a8 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -340,9 +340,9 @@ static int sync_helper(struct ImapAccountData *adata, int right, int flag, const * This method ensure we have a valid Mailbox object with the ImapAccountData * structure setuped and ready to use. */ -static int imap_prepare_mailbox(struct Mailbox *m, struct ImapMbox *mx, - const char *path, char *mailbox, size_t mailboxlen, - bool run_hook, bool create_new_connection) +int imap_prepare_mailbox(struct Mailbox *m, struct ImapMbox *mx, + const char *path, char *mailbox, size_t mailboxlen, + bool run_hook, bool create_new_connection) { if (!m || !m->account) return -1; @@ -402,7 +402,7 @@ static int imap_prepare_mailbox(struct Mailbox *m, struct ImapMbox *mx, * TODO(sileht): We should drop this method and pass a Context or Mailbox * object everywhere instead. */ -static int get_mailbox(const char *path, struct ImapAccountData **adata, char *buf, size_t buflen) +int get_mailbox(const char *path, struct ImapAccountData **adata, char *buf, size_t buflen) { int rc; struct ImapMbox mx; diff --git a/imap/imap_private.h b/imap/imap_private.h index 0f7d76955..a855937f6 100644 --- a/imap/imap_private.h +++ b/imap/imap_private.h @@ -306,6 +306,7 @@ void imap_expunge_mailbox(struct ImapAccountData *adata); void imap_logout(struct ImapAccountData **adata); int imap_sync_message_for_copy(struct ImapAccountData *adata, struct Email *e, struct Buffer *cmd, int *err_continue); bool imap_has_flag(struct ListHead *flag_list, const char *flag); +int imap_prepare_mailbox(struct Mailbox *m, struct ImapMbox *mx, const char *path, char *mailbox, size_t mailboxlen, bool run_hook, bool create_new_connection); /* auth.c */ int imap_authenticate(struct ImapAccountData *adata); -- 2.40.0