{
if (mutt_save_message_ctx(h, delete, decode, decrypt, savectx) != 0)
{
- mx_mbox_close(savectx, NULL);
- FREE(&savectx);
+ mx_mbox_close(&savectx, NULL);
return -1;
}
#ifdef USE_COMPRESSED
#endif
if (rc != 0)
{
- mx_mbox_close(savectx, NULL);
- FREE(&savectx);
+ mx_mbox_close(&savectx, NULL);
return -1;
}
}
const bool need_mailbox_cleanup = ((savectx->magic == MUTT_MBOX) || (savectx->magic == MUTT_MMDF));
- mx_mbox_close(savectx, NULL);
- FREE(&savectx);
+ mx_mbox_close(&savectx, NULL);
if (need_mailbox_cleanup)
mutt_mailbox_cleanup(buf, &st);
if (!ctx->msgcount)
{
- mx_mbox_close(ctx, NULL);
- FREE(&ctx);
+ mx_mbox_close(&ctx, NULL);
mutt_error(_("No messages in that folder"));
break;
}
menu->redraw |= REDRAW_FULL;
if (close == OP_QUIT)
- mx_mbox_close(Context, NULL);
+ mx_mbox_close(&Context, NULL);
else
+ {
mx_fastclose_mailbox(Context);
- FREE(&Context);
+ FREE(&Context);
+ }
/* go back to the folder we started from */
Context = this;
new_last_folder = mutt_str_strdup(Context->path);
*oldcount = Context ? Context->msgcount : 0;
- int check = mx_mbox_close(Context, index_hint);
+ int check = mx_mbox_close(&Context, index_hint);
if (check != 0)
{
if (check == MUTT_NEW_MAIL || check == MUTT_REOPENED)
menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
return 0;
}
- FREE(&Context);
FREE(&LastFolder);
LastFolder = new_last_folder;
}
mutt_startup_shutdown_hook(MUTT_SHUTDOWN_HOOK);
- if (!Context || (check = mx_mbox_close(Context, &index_hint)) == 0)
+ if (!Context || (check = mx_mbox_close(&Context, &index_hint)) == 0)
done = true;
else
{
case OP_MAIN_IMAP_LOGOUT_ALL:
if (Context && Context->magic == MUTT_IMAP)
{
- if (mx_mbox_close(Context, &index_hint) != 0)
+ if (mx_mbox_close(&Context, &index_hint) != 0)
{
OptSearchInvalid = true;
menu->redraw = REDRAW_FULL;
break;
}
- FREE(&Context);
}
imap_logout_all();
mutt_message(_("Logged out of IMAP servers"));
rc = mutt_append_message(tmpctx, ctx, cur, 0, chflags);
oerrno = errno;
- mx_mbox_close(tmpctx, NULL);
- FREE(&tmpctx);
+ mx_mbox_close(&tmpctx, NULL);
if (rc == -1)
{
if (!msg)
{
mutt_error(_("Can't append to folder: %s"), strerror(errno));
- mx_mbox_close(tmpctx, NULL);
- FREE(&tmpctx);
+ mx_mbox_close(&tmpctx, NULL);
goto bail;
}
rc = mx_msg_commit(tmpctx, msg);
mx_msg_close(tmpctx, &msg);
- mx_mbox_close(tmpctx, NULL);
- FREE(&tmpctx);
+ mx_mbox_close(&tmpctx, NULL);
bail:
if (fp)
mailbox->msg_unread = ctx->unread;
mailbox->msg_flagged = ctx->flagged;
mailbox->stats_last_checked = ctx->mtime;
- mx_mbox_close(ctx, NULL);
- FREE(&ctx);
+ mx_mbox_close(&ctx, NULL);
}
}
msg = mx_msg_open_new(ctx, hn, is_from(buf, NULL, 0, NULL) ? 0 : MUTT_ADD_FROM);
if (!msg)
{
- mx_mbox_close(ctx, NULL);
- FREE(&ctx);
+ mx_mbox_close(&ctx, NULL);
return -1;
}
if ((ctx->magic == MUTT_MBOX) || (ctx->magic == MUTT_MMDF))
}
mx_msg_close(ctx, &msg);
- mx_mbox_close(ctx, NULL);
- FREE(&ctx);
+ mx_mbox_close(&ctx, NULL);
return r;
}
else
{
if (mutt_append_message(ctx_trash, ctx, ctx->hdrs[i], 0, 0) == -1)
{
- mx_mbox_close(ctx_trash, NULL);
- FREE(&ctx_trash);
+ mx_mbox_close(&ctx_trash, NULL);
return -1;
}
}
}
- mx_mbox_close(ctx_trash, NULL);
- FREE(&ctx_trash);
+ mx_mbox_close(&ctx_trash, NULL);
}
else
{
}
/**
- * mx_mbox_close - save changes and close mailbox
+ * mx_mbox_close - Save changes and close mailbox
* @param ctx Mailbox
* @param index_hint Current email
* @retval 0 Success
* @retval -1 Failure
*/
-int mx_mbox_close(struct Context *ctx, int *index_hint)
+int mx_mbox_close(struct Context **pctx, int *index_hint)
{
+ if (!pctx || !*pctx)
+ return 0;
+
+ struct Context *ctx = *pctx;
int i, move_messages = 0, purge = 1, read_msgs = 0;
char mbox[PATH_MAX];
char buf[PATH_MAX + 64];
- if (!ctx)
- return 0;
-
ctx->closing = true;
if (ctx->readonly || ctx->dontwrite || ctx->append)
{
mx_fastclose_mailbox(ctx);
+ FREE(pctx);
return 0;
}
}
else
{
- mx_mbox_close(f, NULL);
- FREE(&f);
+ mx_mbox_close(&f, NULL);
ctx->closing = false;
return -1;
}
}
}
- mx_mbox_close(f, NULL);
- FREE(&f);
+ mx_mbox_close(&f, NULL);
}
}
else if (!ctx->changed && ctx->deleted == 0)
if (ctx->magic == MUTT_MBOX || ctx->magic == MUTT_MMDF)
mbox_reset_atime(ctx, NULL);
mx_fastclose_mailbox(ctx);
+ FREE(pctx);
return 0;
}
#endif
mx_fastclose_mailbox(ctx);
+ FREE(pctx);
return 0;
}
/* Wrappers for the Mailbox API, see MxOps */
int mx_mbox_check (struct Context *ctx, int *index_hint);
-int mx_mbox_close (struct Context *ctx, int *index_hint);
+int mx_mbox_close (struct Context **pctx, int *index_hint);
struct Context *mx_mbox_open (const char *path, int flags);
int mx_mbox_sync (struct Context *ctx, int *index_hint);
int mx_msg_close (struct Context *ctx, struct Message **msg);
if (ret == -1)
{
- mx_mbox_close(ctx, NULL);
- FREE(&ctx);
+ mx_mbox_close(&ctx, NULL);
goto fail;
}
if (ret == -2)
msgbuf, i - last, msgs - last);
}
- mx_mbox_close(ctx, NULL);
- FREE(&ctx);
+ mx_mbox_close(&ctx, NULL);
if (rset)
{
if (!PostContext->msgcount)
{
PostCount = 0;
- mx_mbox_close(PostContext, NULL);
- FREE(&PostContext);
+ mx_mbox_close(&PostContext, NULL);
mutt_error(_("No postponed messages"));
return -1;
}
}
else if (!(h = select_msg()))
{
- mx_mbox_close(PostContext, NULL);
- FREE(&PostContext);
+ mx_mbox_close(&PostContext, NULL);
return -1;
}
/* avoid the "purge deleted messages" prompt */
opt_delete = Delete;
Delete = MUTT_YES;
- mx_mbox_close(PostContext, NULL);
+ mx_mbox_close(&PostContext, NULL);
Delete = opt_delete;
- FREE(&PostContext);
-
struct ListNode *np, *tmp;
STAILQ_FOREACH_SAFE(np, &hdr->env->userhdrs, entries, tmp)
{
if (!tempfp)
{
mutt_perror(tempfile);
- mx_mbox_close(f, NULL);
- FREE(&f);
+ mx_mbox_close(&f, NULL);
goto done;
}
/* remember new mail status before appending message */
if (!msg)
{
mutt_file_fclose(&tempfp);
- mx_mbox_close(f, NULL);
- FREE(&f);
+ mx_mbox_close(&f, NULL);
goto done;
}
unlink(tempfile);
mx_msg_commit(f, msg); /* XXX really? */
mx_msg_close(f, &msg);
- mx_mbox_close(f, NULL);
- FREE(&f);
+ mx_mbox_close(&f, NULL);
goto done;
}
else if (finalpath)
*finalpath = mutt_str_strdup(msg->committed_path);
mx_msg_close(f, &msg);
- mx_mbox_close(f, NULL);
- FREE(&f);
+ mx_mbox_close(&f, NULL);
if (!post && need_mailbox_cleanup)
mutt_mailbox_cleanup(path, &st);