}
#endif
- savectx = mx_mbox_open(NULL, buf, MUTT_APPEND);
+ struct Mailbox *m_save = mx_path_resolve(buf);
+ savectx = mx_mbox_open(m_save, NULL, MUTT_APPEND);
if (!savectx)
+ {
+ mailbox_free(&m_save);
return -1;
+ }
#ifdef USE_COMPRESSED
/* If we're saving to a compressed mailbox, the stats won't be updated
menu->redraw = REDRAW_FULL;
- ctx = mx_mbox_open(NULL, fname, MUTT_READONLY);
+ struct Mailbox *m = mx_path_resolve(fname);
+ ctx = mx_mbox_open(m, NULL, MUTT_READONLY);
if (!ctx)
{
mutt_error(_("Unable to open mailbox %s"), fname);
+ mailbox_free(&m);
break;
}
enum MailboxType omagic = MboxType;
MboxType = MUTT_MBOX;
- struct Context *tmpctx = mx_mbox_open(NULL, fname, MUTT_NEWFOLDER);
+ struct Mailbox *m_fname = mx_path_resolve(fname);
+ struct Context *tmpctx = mx_mbox_open(m_fname, NULL, MUTT_NEWFOLDER);
MboxType = omagic;
if (!tmpctx)
{
mutt_error(_("could not create temporary folder: %s"), strerror(errno));
+ mailbox_free(&m_fname);
return -1;
}
? MUTT_READONLY
: 0;
- Context = mx_mbox_open(m, buf, flags);
+ bool free_m = false;
+ if (!m)
+ {
+ m = mx_path_resolve(buf);
+ free_m = true;
+ }
+ Context = mx_mbox_open(m, NULL, flags);
if (Context)
{
menu->current = ci_first_message();
#endif
}
else
+ {
menu->current = 0;
+ if (free_m)
+ mailbox_free(&m);
+ }
if (((Sort & SORT_MASK) == SORT_THREADS) && CollapseAll)
collapse_all(menu, 0);
mutt_startup_shutdown_hook(MUTT_STARTUP_HOOK);
repeat_error = true;
- Context = mx_mbox_open(NULL, folder,
- ((flags & MUTT_RO) || ReadOnly) ? MUTT_READONLY : 0);
+ struct Mailbox *m = mx_path_resolve(folder);
+ Context = mx_mbox_open(m, NULL, ((flags & MUTT_RO) || ReadOnly) ? MUTT_READONLY : 0);
+ if (!Context)
+ {
+ mailbox_free(&m);
+ }
if (Context || !explicit_folder)
{
#ifdef USE_SIDEBAR
return -1;
if (!fgets(buf, sizeof(buf), fp))
return -1;
- struct Context *ctx = mx_mbox_open(NULL, path, MUTT_APPEND | MUTT_QUIET);
+ struct Mailbox *m_att = mx_path_resolve(path);
+ struct Context *ctx = mx_mbox_open(m_att, NULL, MUTT_APPEND | MUTT_QUIET);
if (!ctx)
+ {
+ mailbox_free(&m_att);
return -1;
+ }
msg = mx_msg_open_new(ctx->mailbox, en, is_from(buf, NULL, 0, NULL) ? 0 : MUTT_ADD_FROM);
if (!msg)
{
}
#endif
- struct Context *ctx_trash = mx_mbox_open(NULL, Trash, MUTT_APPEND);
+ struct Mailbox *m_trash = mx_path_resolve(Trash);
+ struct Context *ctx_trash = mx_mbox_open(m_trash, NULL, MUTT_APPEND);
if (ctx_trash)
{
/* continue from initial scan above */
else
{
mutt_error(_("Can't open trash folder"));
+ mailbox_free(&m_trash);
return -1;
}
else /* use regular append-copy mode */
#endif
{
- struct Context *f = mx_mbox_open(NULL, mbox, MUTT_APPEND);
- if (!f)
+ struct Mailbox *m_read = mx_path_resolve(mbox);
+ struct Context *ctx_read = mx_mbox_open(m_read, NULL, MUTT_APPEND);
+ if (!ctx_read)
+ {
+ mailbox_free(&m_read);
return -1;
+ }
for (i = 0; i < m->msg_count; i++)
{
if (m->emails[i]->read && !m->emails[i]->deleted &&
!(m->emails[i]->flagged && KeepFlagged))
{
- if (mutt_append_message(f->mailbox, ctx->mailbox, m->emails[i], 0, CH_UPDATE_LEN) == 0)
+ if (mutt_append_message(ctx_read->mailbox, ctx->mailbox, m->emails[i], 0, CH_UPDATE_LEN) == 0)
{
mutt_set_flag(m, m->emails[i], MUTT_DELETE, 1);
mutt_set_flag(m, m->emails[i], MUTT_PURGE, 1);
}
else
{
- mx_mbox_close(&f);
+ mx_mbox_close(&ctx_read);
return -1;
}
}
}
- mx_mbox_close(&f);
+ mx_mbox_close(&ctx_read);
}
}
else if (!m->changed && m->msg_deleted == 0)
return NULL;
}
+/**
+ * mx_path_resolve - XXX
+ */
+struct Mailbox *mx_path_resolve(const char *path)
+{
+ if (!path)
+ return NULL;
+
+ struct Mailbox *m = mx_mbox_find2(path);
+ if (m)
+ return m;
+
+ m = mailbox_new();
+ m->flags = MB_HIDDEN;
+ mutt_str_strfcpy(m->path, path, sizeof(m->path));
+ mx_path_canon2(m, Folder);
+
+ return m;
+}
+
/**
* mx_ac_add - Add a Mailbox to an Account - Wrapper for MxOps::ac_add
*/
int mx_path_parent (char *buf, size_t buflen);
int mx_path_pretty (char *buf, size_t buflen, const char *folder);
enum MailboxType mx_path_probe (const char *path, struct stat *st);
+struct Mailbox *mx_path_resolve (const char *path);
int mx_tags_commit (struct Mailbox *m, struct Email *e, char *tags);
int mx_tags_edit (struct Mailbox *m, const char *tags, char *buf, size_t buflen);
goto finish;
}
- struct Context *ctx = mx_mbox_open(NULL, Spoolfile, MUTT_APPEND);
+ struct Mailbox *m_spool = mx_path_resolve(Spoolfile);
+ struct Context *ctx = mx_mbox_open(m_spool, NULL, MUTT_APPEND);
if (!ctx)
+ {
+ mailbox_free(&m_spool);
goto finish;
+ }
delanswer = query_quadoption(PopDelete, _("Delete messages from server?"));
if (optnews)
OptNews = false;
#endif
- struct Context *ctx = mx_mbox_open(NULL, Postponed, MUTT_NOSORT | MUTT_QUIET);
+ struct Mailbox *m_post = mx_path_resolve(Postponed);
+ struct Context *ctx = mx_mbox_open(m_post, NULL, MUTT_NOSORT | MUTT_QUIET);
if (!ctx)
+ {
+ mailbox_free(&m_post);
PostCount = 0;
+ }
else
PostCount = ctx->mailbox->msg_count;
mx_fastclose_mailbox(ctx->mailbox);
if (!Postponed)
return -1;
- struct Mailbox *m = mx_mbox_find2(Postponed);
+ struct Mailbox *m = mx_path_resolve(Postponed);
if (ctx->mailbox == m)
PostContext = ctx;
else
- PostContext = mx_mbox_open(m, Postponed, MUTT_NOSORT);
+ PostContext = mx_mbox_open(m, NULL, MUTT_NOSORT);
if (!PostContext)
{
PostCount = 0;
mutt_error(_("No postponed messages"));
+ mailbox_free(&m);
return -1;
}
#ifdef RECORD_FOLDER_HOOK
mutt_folder_hook(path, NULL);
#endif
- struct Context *f = mx_mbox_open(NULL, path, MUTT_APPEND | MUTT_QUIET);
- if (!f)
+ struct Mailbox *m_fcc = mx_path_resolve(path);
+ struct Context *ctx_fcc = mx_mbox_open(m_fcc, NULL, MUTT_APPEND | MUTT_QUIET);
+ if (!ctx_fcc)
{
mutt_debug(1, "unable to open mailbox %s in append-mode, aborting.\n", path);
+ mailbox_free(&m_fcc);
goto done;
}
/* We need to add a Content-Length field to avoid problems where a line in
* the message body begins with "From "
*/
- if ((f->mailbox->magic == MUTT_MMDF) || (f->mailbox->magic == MUTT_MBOX))
+ if ((ctx_fcc->mailbox->magic == MUTT_MMDF) || (ctx_fcc->mailbox->magic == MUTT_MBOX))
{
mutt_mktemp(tempfile, sizeof(tempfile));
tempfp = mutt_file_fopen(tempfile, "w+");
if (!tempfp)
{
mutt_perror(tempfile);
- mx_mbox_close(&f);
+ mx_mbox_close(&ctx_fcc);
goto done;
}
/* remember new mail status before appending message */
onm_flags = MUTT_ADD_FROM;
if (post)
onm_flags |= MUTT_SET_DRAFT;
- msg = mx_msg_open_new(f->mailbox, e, onm_flags);
+ msg = mx_msg_open_new(ctx_fcc->mailbox, e, onm_flags);
if (!msg)
{
mutt_file_fclose(&tempfp);
- mx_mbox_close(&f);
+ mx_mbox_close(&ctx_fcc);
goto done;
}
if (post && fcc)
fprintf(msg->fp, "X-Mutt-Fcc: %s\n", fcc);
- if ((f->mailbox->magic == MUTT_MMDF) || (f->mailbox->magic == MUTT_MBOX))
+ if ((ctx_fcc->mailbox->magic == MUTT_MMDF) || (ctx_fcc->mailbox->magic == MUTT_MBOX))
fprintf(msg->fp, "Status: RO\n");
/* mutt_rfc822_write_header() only writes out a Date: header with
mutt_debug(1, "%s: write failed.\n", tempfile);
mutt_file_fclose(&tempfp);
unlink(tempfile);
- mx_msg_commit(f->mailbox, msg); /* XXX really? */
- mx_msg_close(f->mailbox, &msg);
- mx_mbox_close(&f);
+ mx_msg_commit(ctx_fcc->mailbox, msg); /* XXX really? */
+ mx_msg_close(ctx_fcc->mailbox, &msg);
+ mx_mbox_close(&ctx_fcc);
goto done;
}
rc = mutt_write_mime_body(e->content, msg->fp);
}
- if (mx_msg_commit(f->mailbox, msg) != 0)
+ if (mx_msg_commit(ctx_fcc->mailbox, msg) != 0)
rc = -1;
else if (finalpath)
*finalpath = mutt_str_strdup(msg->committed_path);
- mx_msg_close(f->mailbox, &msg);
- mx_mbox_close(&f);
+ mx_msg_close(ctx_fcc->mailbox, &msg);
+ mx_mbox_close(&ctx_fcc);
if (!post && need_mailbox_cleanup)
mutt_mailbox_cleanup(path, &st);