From: Richard Russon Date: Sun, 23 Dec 2018 00:06:32 +0000 (+0000) Subject: mx_fastclose_mailbox: factor out Context X-Git-Tag: 2019-10-25~399^2~10 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=47b80f230793ca5f653d45f2a3b9f3885db2b576;p=neomutt mx_fastclose_mailbox: factor out Context --- diff --git a/compose.c b/compose.c index 365982a58..d93b2a4e9 100644 --- a/compose.c +++ b/compose.c @@ -1507,7 +1507,7 @@ int mutt_compose_menu(struct Email *msg, char *fcc, size_t fcclen, struct Email mx_mbox_close(&Context, NULL); else { - mx_fastclose_mailbox(Context); + mx_fastclose_mailbox(Context->mailbox); mutt_context_free(&Context); } diff --git a/imap/command.c b/imap/command.c index c1e26f81d..ce724f3ce 100644 --- a/imap/command.c +++ b/imap/command.c @@ -165,7 +165,7 @@ static void cmd_handle_fatal(struct ImapAccountData *adata) if (adata->state >= IMAP_SELECTED && (mdata->reopen & IMAP_REOPEN_ALLOW)) { - mx_fastclose_mailbox(mdata->ctx); + mx_fastclose_mailbox(adata->mailbox); mutt_socket_close(adata->conn); mutt_error(_("Mailbox %s@%s closed"), adata->conn->account.user, adata->conn->account.host); diff --git a/index.c b/index.c index 071b24ebd..5f9b0eef9 100644 --- a/index.c +++ b/index.c @@ -2331,7 +2331,7 @@ int mutt_index_menu(void) { if (Context) { - mx_fastclose_mailbox(Context); + mx_fastclose_mailbox(Context->mailbox); mutt_context_free(&Context); } done = true; diff --git a/mbox/mbox.c b/mbox/mbox.c index 1860582dd..3f1f74995 100644 --- a/mbox/mbox.c +++ b/mbox/mbox.c @@ -1124,7 +1124,7 @@ static int mbox_mbox_check(struct Context *ctx, int *index_hint) /* fatal error */ mbox_unlock_mailbox(m); - mx_fastclose_mailbox(ctx); + mx_fastclose_mailbox(m); mutt_sig_unblock(); mutt_error(_("Mailbox was corrupted")); return -1; @@ -1175,7 +1175,7 @@ static int mbox_mbox_sync(struct Context *ctx, int *index_hint) adata->fp = freopen(m->path, "r+", adata->fp); if (!adata->fp) { - mx_fastclose_mailbox(ctx); + mx_fastclose_mailbox(m); mutt_error(_("Fatal error! Could not reopen mailbox!")); return -1; } @@ -1353,7 +1353,7 @@ static int mbox_mbox_sync(struct Context *ctx, int *index_hint) if (!fp) { mutt_sig_unblock(); - mx_fastclose_mailbox(ctx); + mx_fastclose_mailbox(m); mutt_debug(1, "unable to reopen temp copy of mailbox!\n"); mutt_perror(tempfile); FREE(&new_offset); @@ -1417,7 +1417,7 @@ static int mbox_mbox_sync(struct Context *ctx, int *index_hint) NONULL(Username), NONULL(ShortHostname), (unsigned int) getpid()); rename(tempfile, savefile); mutt_sig_unblock(); - mx_fastclose_mailbox(ctx); + mx_fastclose_mailbox(m); mutt_pretty_mailbox(savefile, sizeof(savefile)); mutt_error(_("Write failed! Saved partial mailbox to %s"), savefile); FREE(&new_offset); @@ -1434,7 +1434,7 @@ static int mbox_mbox_sync(struct Context *ctx, int *index_hint) { unlink(tempfile); mutt_sig_unblock(); - mx_fastclose_mailbox(ctx); + mx_fastclose_mailbox(m); mutt_error(_("Fatal error! Could not reopen mailbox!")); FREE(&new_offset); FREE(&old_offset); @@ -1494,7 +1494,7 @@ bail: /* Come here in case of disaster */ if (!adata->fp) { mutt_error(_("Could not reopen mailbox")); - mx_fastclose_mailbox(ctx); + mx_fastclose_mailbox(m); return -1; } diff --git a/mx.c b/mx.c index 20e9e0ec7..f5d559421 100644 --- a/mx.c +++ b/mx.c @@ -355,7 +355,7 @@ struct Context *mx_mbox_open(struct Mailbox *m, const char *path, int flags) { if (mx_open_mailbox_append(ctx->mailbox, flags) != 0) { - mx_fastclose_mailbox(ctx); + mx_fastclose_mailbox(m); mutt_context_free(&ctx); return NULL; } @@ -378,7 +378,7 @@ struct Context *mx_mbox_open(struct Mailbox *m, const char *path, int flags) else if (m->magic == MUTT_UNKNOWN || !m->mx_ops) mutt_error(_("%s is not a mailbox"), path); - mx_fastclose_mailbox(ctx); + mx_fastclose_mailbox(m); mutt_context_free(&ctx); return NULL; } @@ -417,7 +417,7 @@ struct Context *mx_mbox_open(struct Mailbox *m, const char *path, int flags) } else { - mx_fastclose_mailbox(ctx); + mx_fastclose_mailbox(m); mutt_context_free(&ctx); } @@ -427,15 +427,13 @@ struct Context *mx_mbox_open(struct Mailbox *m, const char *path, int flags) /** * mx_fastclose_mailbox - free up memory associated with the mailbox context - * @param ctx Mailbox + * @param m Mailbox */ -void mx_fastclose_mailbox(struct Context *ctx) +void mx_fastclose_mailbox(struct Mailbox *m) { - if (!ctx || !ctx->mailbox) + if (!m) return; - struct Mailbox *m = ctx->mailbox; - m->opened--; if (m->opened != 0) return; @@ -611,7 +609,7 @@ int mx_mbox_close(struct Context **pctx, int *index_hint) if (m->readonly || m->dontwrite || m->append) { - mx_fastclose_mailbox(ctx); + mx_fastclose_mailbox(m); FREE(pctx); return 0; } @@ -765,7 +763,7 @@ int mx_mbox_close(struct Context **pctx, int *index_hint) mutt_message(_("Mailbox is unchanged")); if (m->magic == MUTT_MBOX || m->magic == MUTT_MMDF) mbox_reset_atime(m, NULL); - mx_fastclose_mailbox(ctx); + mx_fastclose_mailbox(m); FREE(pctx); return 0; } @@ -840,7 +838,7 @@ int mx_mbox_close(struct Context **pctx, int *index_hint) } #endif - mx_fastclose_mailbox(ctx); + mx_fastclose_mailbox(m); FREE(pctx); return 0; @@ -1049,7 +1047,7 @@ int mx_mbox_sync(struct Context *ctx, int *index_hint) !mutt_is_spool(m->path) && !SaveEmpty) { unlink(m->path); - mx_fastclose_mailbox(ctx); + mx_fastclose_mailbox(m); return 0; } diff --git a/mx.h b/mx.h index aa3608a6d..2224767c7 100644 --- a/mx.h +++ b/mx.h @@ -288,7 +288,7 @@ int mx_ac_remove (struct Mailbox *m); int mx_access (const char *path, int flags); void mx_alloc_memory (struct Mailbox *m); int mx_check_empty (const char *path); -void mx_fastclose_mailbox(struct Context *ctx); +void mx_fastclose_mailbox(struct Mailbox *m); const struct MxOps *mx_get_ops (enum MailboxType magic); bool mx_tags_is_supported(struct Mailbox *m); void mx_update_context (struct Context *ctx); diff --git a/postpone.c b/postpone.c index 49d8bcd6d..e5ba3792a 100644 --- a/postpone.c +++ b/postpone.c @@ -175,7 +175,7 @@ int mutt_num_postponed(struct Mailbox *m, bool force) PostCount = 0; else PostCount = ctx->mailbox->msg_count; - mx_fastclose_mailbox(ctx); + mx_fastclose_mailbox(ctx->mailbox); mutt_context_free(&ctx); #ifdef USE_NNTP if (optnews) @@ -337,7 +337,7 @@ int mutt_get_postponed(struct Context *ctx, struct Email *hdr, { if (PostContext != ctx) { - mx_fastclose_mailbox(PostContext); + mx_fastclose_mailbox(PostContext->mailbox); FREE(&PostContext); } return -1;