]> granicus.if.org Git - neomutt/commitdiff
imap: remove imap_conn_find from imap_browse
authorMehdi Abaakouk <sileht@sileht.net>
Thu, 8 Nov 2018 16:25:48 +0000 (17:25 +0100)
committerRichard Russon <rich@flatcap.org>
Sat, 10 Nov 2018 13:24:26 +0000 (13:24 +0000)
imap/browse.c
imap/imap.c
imap/imap_private.h

index 6db41c61f23c7f238d75f5618fa09ca42b388078..b94b93c158fe2a539e628a4a71d43da448b6a7c7 100644 (file)
 #include <stdbool.h>
 #include <stdio.h>
 #include <string.h>
-#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;
 
index 3718f6d146f4096762f93aebabdfc1ad7e3ba007..a9f61d1a87390bf5eeabcbbe6c277eea5a0297ba 100644 (file)
@@ -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;
index 0f7d769554b34e948fded0b8c7474b9d7ecc207b..a855937f675e4b42d810d5f06d65d535cc870d9f 100644 (file)
@@ -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);