/**
* imap_mailbox_create - Create a new IMAP mailbox
- * @param folder Mailbox to create
+ * @param path Mailbox to create
* @retval 0 Success
* @retval -1 Failure
*
* Prompt for a new mailbox name, and try to create it
*/
-int imap_mailbox_create(const char *folder)
+int imap_mailbox_create(const char *path)
{
struct ImapAccountData *adata = NULL;
- struct ImapMbox mx;
char buf[PATH_MAX];
+ char name[LONG_STRING];
short n;
- adata = imap_adata_find(folder, &mx);
+ adata = imap_adata_find(path, name, sizeof(name));
if (!adata)
{
- mutt_debug(1, "Couldn't find open connection to %s\n", folder);
- goto fail;
+ mutt_debug(1, "Couldn't find open connection to %s\n", path);
+ return -1;
}
- mutt_str_strfcpy(buf, mx.mbox, sizeof(buf));
+ mutt_str_strfcpy(buf, name, sizeof(buf));
/* append a delimiter if necessary */
n = mutt_str_strlen(buf);
}
if (mutt_get_field(_("Create mailbox: "), buf, sizeof(buf), MUTT_FILE) < 0)
- goto fail;
+ return -1;
if (mutt_str_strlen(buf) == 0)
{
mutt_error(_("Mailbox must have a name"));
- goto fail;
+ return -1;
}
if (imap_create_mailbox(adata, buf) < 0)
- goto fail;
+ return -1;
mutt_message(_("Mailbox created"));
mutt_sleep(0);
- FREE(&mx.mbox);
return 0;
-
-fail:
- FREE(&mx.mbox);
- return -1;
}
/**
* imap_mailbox_rename - Rename a mailbox
- * @param mailbox Mailbox to rename
+ * @param path Mailbox to rename
* @retval 0 Success
* @retval -1 Failure
*
* The user will be prompted for a new name.
*/
-int imap_mailbox_rename(const char *mailbox)
+int imap_mailbox_rename(const char *path)
{
struct ImapAccountData *adata = NULL;
- struct ImapMbox mx;
char buf[PATH_MAX];
+ char oldname[LONG_STRING];
char newname[PATH_MAX];
- adata = imap_adata_find(mailbox, &mx);
+ adata = imap_adata_find(path, oldname, sizeof(oldname));
if (!adata)
{
- mutt_debug(1, "Couldn't find open connection to %s\n", mailbox);
- goto fail;
+ mutt_debug(1, "Couldn't find open connection to %s\n", path);
+ return -1;
}
- if (!mx.mbox)
+ if (oldname[0] == '\0')
{
mutt_error(_("Cannot rename root folder"));
- goto fail;
+ return -1;
}
- snprintf(buf, sizeof(buf), _("Rename mailbox %s to: "), mx.mbox);
- mutt_str_strfcpy(newname, mx.mbox, sizeof(newname));
+ snprintf(buf, sizeof(buf), _("Rename mailbox %s to: "), oldname);
+ mutt_str_strfcpy(newname, oldname, sizeof(newname));
if (mutt_get_field(buf, newname, sizeof(newname), MUTT_FILE) < 0)
- goto fail;
+ return -1;
if (mutt_str_strlen(newname) == 0)
{
mutt_error(_("Mailbox must have a name"));
- goto fail;
+ return -1;
}
imap_fix_path(adata, newname, buf, sizeof(buf));
- if (imap_rename_mailbox(adata, &mx, buf) < 0)
+ if (imap_rename_mailbox(adata, oldname, buf) < 0)
{
mutt_error(_("Rename failed: %s"), imap_get_qualifier(adata->buf));
- goto fail;
+ return -1;
}
mutt_message(_("Mailbox renamed"));
mutt_sleep(0);
- FREE(&mx.mbox);
return 0;
-
-fail:
- FREE(&mx.mbox);
- return -1;
}
*/
int get_mailbox(const char *path, struct ImapAccountData **adata, char *buf, size_t buflen)
{
- struct ImapMbox mx;
+ char tmp[LONG_STRING];
- *adata = imap_adata_find(path, &mx);
+ *adata = imap_adata_find(path, tmp, sizeof(tmp));
if (!*adata)
- {
- FREE(&mx.mbox);
return -1;
- }
- imap_fix_path(*adata, mx.mbox, buf, buflen);
+ imap_fix_path(*adata, tmp, buf, buflen);
if (!*buf)
mutt_str_strfcpy(buf, "INBOX", buflen);
- FREE(&mx.mbox);
-
return 0;
}
/**
* imap_rename_mailbox - Rename a mailbox
* @param adata Imap Account data
- * @param mx Existing mailbox
+ * @param oldname Existing mailbox
* @param newname New name for mailbox
* @retval 0 Success
* @retval -1 Failure
*/
-int imap_rename_mailbox(struct ImapAccountData *adata, struct ImapMbox *mx, const char *newname)
+int imap_rename_mailbox(struct ImapAccountData *adata, char *oldname, const char *newname)
{
char oldmbox[LONG_STRING];
char newmbox[LONG_STRING];
int rc = 0;
- imap_munge_mbox_name(adata, oldmbox, sizeof(oldmbox), mx->mbox);
+ imap_munge_mbox_name(adata, oldmbox, sizeof(oldmbox), oldname);
imap_munge_mbox_name(adata, newmbox, sizeof(newmbox), newname);
struct Buffer *b = mutt_buffer_pool_get();
struct ImapAccountData *adata = NULL;
char list[LONG_STRING];
char tmp[LONG_STRING * 2];
+ char mailbox[LONG_STRING];
struct ImapList listresp;
char completion[LONG_STRING];
int clen;
size_t matchlen = 0;
int completions = 0;
- struct ImapMbox mx;
int rc;
- adata = imap_adata_find(path, &mx);
+ adata = imap_adata_find(path, mailbox, sizeof(mailbox));
if (!adata)
{
- FREE(&mx.mbox);
mutt_str_strfcpy(buf, path, buflen);
return complete_hosts(buf, buflen);
}
/* reformat path for IMAP list, and append wildcard */
/* don't use INBOX in place of "" */
- if (mx.mbox && mx.mbox[0])
- imap_fix_path(adata, mx.mbox, list, sizeof(list));
+ if (mailbox[0] != '\0')
+ imap_fix_path(adata, mailbox, list, sizeof(list));
else
list[0] = '\0';
imap_cmd_start(adata, tmp);
/* and see what the results are */
- mutt_str_strfcpy(completion, mx.mbox, sizeof(completion));
+ mutt_str_strfcpy(completion, mailbox, sizeof(completion));
adata->cmdtype = IMAP_CT_LIST;
adata->cmddata = &listresp;
do
if (completions)
{
/* reformat output */
- imap_qualify_path(buf, buflen, &mx, completion);
+ imap_qualify_path2(buf, buflen, &adata->conn_account, completion);
mutt_pretty_mailbox(buf, buflen);
-
- FREE(&mx.mbox);
return 0;
}
/* browse.c */
int imap_browse(char *path, struct BrowserState *state);
int imap_mailbox_create(const char *folder);
-int imap_mailbox_rename(const char *mailbox);
+int imap_mailbox_rename(const char *path);
/* message.c */
int imap_copy_messages(struct Context *ctx, struct Email *e, char *dest, bool delete);
/* imap.c */
int imap_check(struct ImapAccountData *adata, bool force);
int imap_create_mailbox(struct ImapAccountData *adata, char *mailbox);
-int imap_rename_mailbox(struct ImapAccountData *adata, struct ImapMbox *mx, const char *newname);
+int imap_rename_mailbox(struct ImapAccountData *adata, char *oldname, const char *newname);
struct ImapStatus *imap_mboxcache_get(struct ImapAccountData *adata, const char *mbox, bool create);
void imap_mboxcache_free(struct ImapAccountData *adata);
int imap_exec_msgset(struct ImapAccountData *adata, const char *pre, const char *post,
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);
-struct ImapAccountData *imap_adata_find(const char *path, struct ImapMbox *mx);
+struct ImapAccountData *imap_adata_find(const char *path, char *mailbox, size_t mailboxlen);
/* auth.c */
int imap_authenticate(struct ImapAccountData *adata);
/**
* imap_adata_find - Find the Account data for this path
*/
-struct ImapAccountData *imap_adata_find(const char *path, struct ImapMbox *mx)
+struct ImapAccountData *imap_adata_find(const char *path, char *mailbox, size_t mailboxlen)
{
- if (imap_parse_path(path, mx) < 0)
+ // NOTE(sileht): Remove mx when we are able to pass Mailbox or Url there.
+ struct ImapMbox mx;
+
+ if (imap_parse_path(path, &mx) < 0)
return NULL;
struct Account *np = NULL;
continue;
adata = np->adata;
- if (imap_account_match(&adata->conn_account, &mx->account))
+ if (imap_account_match(&adata->conn_account, &mx.account))
+ {
+ if (mx.mbox)
+ mutt_str_strfcpy(mailbox, mx.mbox, mailboxlen);
return adata;
+ }
}
mutt_debug(3, "no ImapAccountData found\n");
return NULL;
*/
void imap_get_parent_path(const char *path, char *buf, size_t buflen)
{
- struct ImapMbox mx;
struct ImapAccountData *adata = NULL;
- char mbox[LONG_STRING] = "";
+ char mbox[LONG_STRING], tmp[LONG_STRING];
- adata = imap_adata_find(path, &mx);
- if (!adata)
+ adata = imap_adata_find(path, tmp, sizeof(tmp));
+ if (!adata || tmp[0] == '\0')
{
mutt_str_strfcpy(buf, path, buflen);
- FREE(&mx.mbox);
return;
}
/* Stores a fixed path in mbox */
- imap_fix_path(adata, mx.mbox, mbox, sizeof(mbox));
+ imap_fix_path(adata, tmp, mbox, sizeof(mbox));
/* Gets the parent mbox in mbox */
imap_get_parent(mbox, adata->delim, mbox, sizeof(mbox));
/* Returns a fully qualified IMAP url */
- imap_qualify_path(buf, buflen, &mx, mbox);
- FREE(&mx.mbox);
+ imap_qualify_path2(buf, buflen, &adata->conn_account, mbox);
}
/**
*/
void imap_clean_path(char *path, size_t plen)
{
- struct ImapMbox mx;
struct ImapAccountData *adata = NULL;
- char mbox[LONG_STRING] = "";
+ char mbox[LONG_STRING], tmp[LONG_STRING];
- adata = imap_adata_find(path, &mx);
- if (!adata)
+ adata = imap_adata_find(path, tmp, sizeof(tmp));
+ if (!adata || tmp[0] == '\0')
return;
/* Stores a fixed path in mbox */
- imap_fix_path(adata, mx.mbox, mbox, sizeof(mbox));
+ imap_fix_path(adata, tmp, mbox, sizeof(mbox));
/* Returns a fully qualified IMAP url */
- imap_qualify_path(path, plen, &mx, mbox);
+ imap_qualify_path2(path, plen, &adata->conn_account, mbox);
}
#ifdef USE_HCACHE