#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"
char ctmp;
bool showparents = false;
bool save_lsub;
- struct ImapMbox mx;
+ struct ImapMbox mx, mx_tmp;
if (imap_parse_path(path, &mx))
{
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;
* 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;
* 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;
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);