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-20161126~17^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=77c3cad20017cb090fd879dd177f4862faf260d5;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 12d70d870..2067d76c9 100644 --- a/mx.c +++ b/mx.c @@ -593,15 +593,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 * @@ -896,23 +887,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; - } - #ifdef USE_NNTP if (ctx->unread && ctx->magic == MUTT_NNTP) {