From: Kevin McCarthy Date: Tue, 8 Nov 2016 20:42:56 +0000 (-0800) Subject: Move mbox close-append logic inside mbox_close_mailbox(). X-Git-Tag: neomutt-20170225~32^2~81 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=51631725e6983584d5e1f635852404ccd22b6334;p=neomutt Move mbox close-append logic inside mbox_close_mailbox(). The mx_fastclose_mailbox() calls mx_ops->close(), which invokes mbox_close_mailbox(). Also, close the ctx->fp inside mbox_close_mailbox(). This way, the (to be added) compress logic can call the mx_ops->close() instead of "knowing" to close the fp before recompressing. mx_fastclose_mailbox() will safe_fclose() the fp again, but I'm leaving it there just in case I missed a usage of the fp in some other part of the code. Thanks to Damien Riegel for the original patch. --- diff --git a/mbox.c b/mbox.c index d3c2ec46a..13fc3d626 100644 --- a/mbox.c +++ b/mbox.c @@ -465,6 +465,14 @@ static int mbox_open_mailbox_append (CONTEXT *ctx, int flags) static int mbox_close_mailbox (CONTEXT *ctx) { + if (ctx->append) + { + mx_unlock_file (ctx->path, fileno (ctx->fp), 1); + mutt_unblock_signals (); + } + + safe_fclose (&ctx->fp); + return 0; } diff --git a/mx.c b/mx.c index 8f1b397e5..680d38f40 100644 --- a/mx.c +++ b/mx.c @@ -514,15 +514,6 @@ static int mx_open_mailbox_append (CONTEXT *ctx, int flags) return ctx->mx_ops->open_append (ctx, flags); } -/* close a mailbox opened in write-mode */ -static int mx_close_mailbox_append (CONTEXT *ctx) -{ - mx_unlock_file (ctx->path, fileno (ctx->fp), 1); - mutt_unblock_signals (); - mx_fastclose_mailbox (ctx); - return 0; -} - /* * open a mailbox and parse it * @@ -793,23 +784,12 @@ int mx_close_mailbox (CONTEXT *ctx, int *index_hint) ctx->closing = 1; - if (ctx->readonly || ctx->dontwrite) + if (ctx->readonly || ctx->dontwrite || ctx->append) { - /* mailbox is readonly or we don't want to write */ mx_fastclose_mailbox (ctx); return 0; } - if (ctx->append) - { - /* mailbox was opened in write-mode */ - if (ctx->magic == MUTT_MBOX || ctx->magic == MUTT_MMDF) - mx_close_mailbox_append (ctx); - else - mx_fastclose_mailbox (ctx); - return 0; - } - for (i = 0; i < ctx->msgcount; i++) { if (!ctx->hdrs[i]->deleted && ctx->hdrs[i]->read