// 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;
+ adata = imap_adata_get(np->m);
+ if (adata)
+ break;
}
}
FREE(&mx_tmp.mbox);
char buf[PATH_MAX];
short n;
- if (imap_parse_path(folder, &mx) < 0)
- {
- mutt_debug(1, "Bad starting path %s\n", folder);
- return -1;
- }
-
- adata = imap_ac_data_find(&mx);
+ adata = imap_adata_find(folder, &mx);
if (!adata)
{
mutt_debug(1, "Couldn't find open connection to %s\n", folder);
char buf[PATH_MAX];
char newname[PATH_MAX];
- if (imap_parse_path(mailbox, &mx) < 0)
- {
- mutt_debug(1, "Bad source mailbox %s\n", mailbox);
- return -1;
- }
-
- adata = imap_ac_data_find(&mx);
+ adata = imap_adata_find(mailbox, &mx);
if (!adata)
{
mutt_debug(1, "Couldn't find open connection to %s\n", mailbox);
}
/**
- * imap_prepare_mailbox - this method ensure we have a valid Mailbox
+ * imap_prepare_mailbox - Ensure we have a valid Mailbox
* @param m Mailbox
* @param mx Imap Mailbox
- * @param path Mailbox path
* @param mailbox Buffer for tidied mailbox path
* @param mailboxlen Length of buffer
- * @param run_hook should we run account hook
- * @param create_new_connection should we create a new connection
* @retval 0 Success
* @retval -1 Failure
*
* This method ensure we have a valid Mailbox object with the ImapAccountData
* structure setuped and ready to use.
*/
-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, char *mailbox, size_t mailboxlen)
{
if (!m || !m->account)
return -1;
- if (!path)
- path = m->path;
-
- if ((imap_path_probe(path, NULL) != MUTT_IMAP) || imap_parse_path(path, mx))
+ if ((imap_path_probe(m->path, NULL) != MUTT_IMAP) || imap_parse_path(m->path, mx))
{
- mutt_debug(1, "Error parsing %s\n", path);
+ mutt_debug(1, "Error parsing %s\n", m->path);
mutt_error(_("Bad mailbox name"));
return -1;
}
struct ImapAccountData *adata = m->account->adata;
- if (!adata)
- {
- if (!create_new_connection)
- return -1;
- adata = imap_adata_new();
- m->account->adata = adata;
- m->account->free_adata = imap_adata_free;
- }
-
- struct Connection *conn = adata->conn;
- if (!conn)
- {
- adata->conn = mutt_conn_new(&mx->account);
- if (!adata->conn)
- return -1;
- }
- if (run_hook)
- mutt_account_hook(m->realpath);
+ mutt_account_hook(m->realpath);
- /* we require a connection which isn't currently in IMAP_SELECTED state */
if (imap_login(adata) < 0)
return -1;
{
struct ImapMbox mx;
- if (imap_parse_path(path, &mx) < 0)
- return -1;
-
- *adata = imap_ac_data_find(&mx);
+ *adata = imap_adata_find(path, &mx);
if (!*adata)
{
FREE(&mx.mbox);
{
struct ImapMbox mx;
char buf[PATH_MAX], mbox[PATH_MAX];
- int rc;
- rc = imap_prepare_mailbox(m, &mx, path, buf, sizeof(buf), true, !ImapPassive);
- if (rc < 0)
- {
- FREE(&mx.mbox);
+ if (imap_parse_path(path, &mx) < 0)
return -1;
- }
- imap_munge_mbox_name(m->account->adata, mbox, sizeof(mbox), mx.mbox);
+ struct ImapAccountData *adata = imap_adata_get(m);
+
+ imap_munge_mbox_name(adata, mbox, sizeof(mbox), mx.mbox);
snprintf(buf, sizeof(buf), "DELETE %s", mbox);
FREE(&mx.mbox);
if (np->m->magic != MUTT_IMAP)
continue;
- // TODO(sileht): get_mailbox also browse AllMailboxes we could do an
- // optimization here.
- mutt_account_hook(np->m->realpath);
if (get_mailbox(np->m->path, &adata, name, sizeof(name)) < 0)
{
np->m->has_new = false;
return 0;
}
-struct ImapAccountData *imap_ac_data_find(struct ImapMbox *mx)
-{
- struct Account *np = NULL;
- struct ImapAccountData *adata = NULL;
- TAILQ_FOREACH(np, &AllAccounts, entries)
- {
- if (np->magic != MUTT_IMAP)
- continue;
-
- adata = np->adata;
- if (imap_account_match(&adata->conn_account, &mx->account))
- return adata;
- }
- mutt_debug(3, "no ImapAccountData found\n");
- return NULL;
-}
/**
* imap_complete - Try to complete an IMAP folder path
struct ImapMbox mx;
int rc;
- if (imap_parse_path(path, &mx))
- {
- mutt_str_strfcpy(buf, path, buflen);
- return complete_hosts(buf, buflen);
- }
-
- adata = imap_ac_data_find(&mx);
+ adata = imap_adata_find(path, &mx);
if (!adata)
{
FREE(&mx.mbox);
if (!a->adata)
{
struct ImapAccountData *adata = imap_adata_new();
+ struct ImapMbox mx;
a->magic = MUTT_IMAP;
a->adata = adata;
a->free_adata = imap_adata_free;
- struct Url url;
- char tmp[PATH_MAX];
- mutt_str_strfcpy(tmp, m->path, sizeof(tmp));
- url_parse(&url, tmp);
-
- mutt_str_strfcpy(adata->conn_account.user, url.user,
- sizeof(adata->conn_account.user));
- mutt_str_strfcpy(adata->conn_account.pass, url.pass,
- sizeof(adata->conn_account.pass));
- mutt_str_strfcpy(adata->conn_account.host, url.host,
- sizeof(adata->conn_account.host));
- adata->conn_account.port = url.port;
- adata->conn_account.type = MUTT_ACCT_TYPE_IMAP;
-
- if (adata->conn_account.user[0] != '\0')
- adata->conn_account.flags |= MUTT_ACCT_USER;
- if (adata->conn_account.pass[0] != '\0')
- adata->conn_account.flags |= MUTT_ACCT_PASS;
+ if (imap_parse_path(m->path, &mx) < 0)
+ return -1;
+ FREE(&mx.mbox);
+ adata->conn_account = mx.account;
+ adata->conn = mutt_conn_new(&adata->conn_account);
+ if (!adata->conn)
+ return -1;
}
m->account = a;
int rc;
const char *condstore = NULL;
- rc = imap_prepare_mailbox(m, &mx, NULL, buf, sizeof(buf), true, true);
+ rc = imap_prepare_mailbox(m, &mx, buf, sizeof(buf));
if (rc < 0)
{
FREE(&mx.mbox);
/* in APPEND mode, we appear to hijack an existing IMAP connection -
* ctx is brand new and mostly empty */
- rc = imap_prepare_mailbox(m, &mx, NULL, mailbox, sizeof(mailbox), false, !ImapPassive);
+ rc = imap_prepare_mailbox(m, &mx, mailbox, sizeof(mailbox));
FREE(&mx.mbox);
if (rc < 0)
return -1;
return a->adata;
}
+/**
+ * imap_adata_find - Find the Account data for this path
+ */
+struct ImapAccountData *imap_adata_find(const char *path, struct ImapMbox *mx)
+{
+
+ if (imap_parse_path(path, mx) < 0)
+ return NULL;
+
+ struct Account *np = NULL;
+ struct ImapAccountData *adata = NULL;
+ TAILQ_FOREACH(np, &AllAccounts, entries)
+ {
+ if (np->magic != MUTT_IMAP)
+ continue;
+
+ adata = np->adata;
+ if (imap_account_match(&adata->conn_account, &mx->account))
+ return adata;
+ }
+ mutt_debug(3, "no ImapAccountData found\n");
+ return NULL;
+}
+
+
/**
* imap_get_parent - Get an IMAP folder's parent
* @param mbox Mailbox whose parent is to be determined
struct ImapAccountData *adata = NULL;
char mbox[LONG_STRING] = "";
- if (imap_parse_path(path, &mx) < 0)
- {
- mutt_str_strfcpy(buf, path, buflen);
- return;
- }
-
- adata = imap_ac_data_find(&mx);
+ adata = imap_adata_find(path, &mx);
if (!adata)
{
mutt_str_strfcpy(buf, path, buflen);
struct ImapAccountData *adata = NULL;
char mbox[LONG_STRING] = "";
- if (imap_parse_path(path, &mx) < 0)
- return;
-
- adata = imap_ac_data_find(&mx);
+ adata = imap_adata_find(path, &mx);
if (!adata)
return;