else
{
char msg[SHORT_STRING];
- struct ImapMbox mx;
int nentry = menu->current;
- if (imap_parse_path(state.entry[nentry].name, &mx) < 0)
- {
- mutt_debug(1, "imap_parse_path failed\n");
- mutt_error(_("Mailbox deletion failed"));
- break;
- }
- if (!mx.mbox)
- {
- mutt_error(_("Cannot delete root folder"));
- break;
- }
- snprintf(msg, sizeof(msg), _("Really delete mailbox \"%s\"?"), mx.mbox);
+ snprintf(msg, sizeof(msg), _("Really delete mailbox \"%s\"?"), state.entry[nentry].name);
if (mutt_yesorno(msg, MUTT_NO) == MUTT_YES)
{
- if (imap_delete_mailbox(Context->mailbox, &mx) == 0)
+ if (imap_delete_mailbox(Context->mailbox, state.entry[nentry].name) == 0)
{
/* free the mailbox from the browser */
FREE(&((state.entry)[nentry].name));
}
else
mutt_message(_("Mailbox not deleted"));
- FREE(&mx.mbox);
}
break;
#endif
* imap_prepare_mailbox - this method 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
* 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, char *mailbox,
- size_t mailboxlen, bool run_hook, bool create_new_connection)
+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)
{
- if (!m->account)
+ if (!m || !m->account)
return -1;
- if ((imap_path_probe(m->path, NULL) != MUTT_IMAP) || imap_parse_path(m->path, mx))
+ if (!path)
+ path = m->path;
+
+ if ((imap_path_probe(path, NULL) != MUTT_IMAP) || imap_parse_path(path, mx))
{
- mutt_debug(1, "Error parsing %s\n", m->path);
+ mutt_debug(1, "Error parsing %s\n", path);
mutt_error(_("Bad mailbox name"));
return -1;
}
if (mutt_str_strcasecmp(path, np->m->path) == 0)
{
- rc = imap_prepare_mailbox(np->m, &mx, buf, buflen, false, true);
+ rc = imap_prepare_mailbox(np->m, &mx, path, buf, buflen, false, true);
if (rc == 0)
*adata = np->m->account->adata;
FREE(&mx.mbox);
/**
* imap_delete_mailbox - Delete a mailbox
* @param m Mailbox
- * @param im Mailbox to delete
+ * @param path name of the mailbox to delete
* @retval 0 Success
* @retval -1 Failure
*/
-int imap_delete_mailbox(struct Mailbox *m, struct ImapMbox *im)
+int imap_delete_mailbox(struct Mailbox *m, char *path)
{
+ struct ImapMbox mx;
char buf[PATH_MAX], mbox[PATH_MAX];
- struct ImapAccountData *adata = imap_adata_get(m);
+ int rc;
- if (!m || !adata)
- {
- adata = imap_conn_find(&im->account, ImapPassive ? MUTT_IMAP_CONN_NONEW : 0);
- if (!adata)
- {
- FREE(&im->mbox);
- return -1;
- }
- }
- else
+ rc = imap_prepare_mailbox(m, &mx, path, buf, sizeof(buf), true, !ImapPassive);
+ if (rc < 0)
{
- adata = m->mdata;
+ FREE(&mx.mbox);
+ return -1;
}
- imap_munge_mbox_name(adata, mbox, sizeof(mbox), im->mbox);
+ imap_munge_mbox_name(m->account->adata, mbox, sizeof(mbox), mx.mbox);
snprintf(buf, sizeof(buf), "DELETE %s", mbox);
+ FREE(&mx.mbox);
- if (imap_exec(adata, buf, 0) != 0)
+ if (imap_exec(m->account->adata, buf, 0) != 0)
return -1;
return 0;
int rc;
const char *condstore = NULL;
- rc = imap_prepare_mailbox(m, &mx, buf, sizeof(buf), true, true);
+ rc = imap_prepare_mailbox(m, &mx, NULL, buf, sizeof(buf), true, true);
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, mailbox, sizeof(mailbox), false, !ImapPassive);
+ rc = imap_prepare_mailbox(m, &mx, NULL, mailbox, sizeof(mailbox), false, !ImapPassive);
FREE(&mx.mbox);
if (rc < 0)
return -1;