From: Richard Russon Date: Mon, 27 Aug 2018 18:53:56 +0000 (+0100) Subject: drop mx_open's Context parameter X-Git-Tag: 2019-10-25~676^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=42ef336db483e67beecaee087414bd5c630f5215;p=neomutt drop mx_open's Context parameter --- diff --git a/commands.c b/commands.c index a9bc9c885..2f3775390 100644 --- a/commands.c +++ b/commands.c @@ -986,7 +986,7 @@ int mutt_save_message(struct Header *h, bool delete, bool decode, bool decrypt) } #endif - savectx = mx_mbox_open(buf, MUTT_APPEND, NULL); + savectx = mx_mbox_open(buf, MUTT_APPEND); if (savectx) { #ifdef USE_COMPRESSED diff --git a/compose.c b/compose.c index 398cedc44..6690cb265 100644 --- a/compose.c +++ b/compose.c @@ -1451,7 +1451,7 @@ int mutt_compose_menu(struct Header *msg, char *fcc, size_t fcclen, menu->redraw = REDRAW_FULL; - ctx = mx_mbox_open(fname, MUTT_READONLY, NULL); + ctx = mx_mbox_open(fname, MUTT_READONLY); if (!ctx) { mutt_error(_("Unable to open mailbox %s"), fname); diff --git a/curs_main.c b/curs_main.c index 92b19519e..bcf47e6b8 100644 --- a/curs_main.c +++ b/curs_main.c @@ -551,7 +551,7 @@ static int main_change_folder(struct Menu *menu, int op, char *buf, mutt_folder_hook(buf); const int flags = (ReadOnly || (op == OP_MAIN_CHANGE_FOLDER_READONLY)) ? MUTT_READONLY : 0; - Context = mx_mbox_open(buf, flags, NULL); + Context = mx_mbox_open(buf, flags); if (Context) { menu->current = ci_first_message(); diff --git a/editmsg.c b/editmsg.c index 288babe20..8410c8d49 100644 --- a/editmsg.c +++ b/editmsg.c @@ -83,7 +83,7 @@ static int edit_or_view_one_message(bool edit, struct Context *ctx, struct Heade omagic = MboxType; MboxType = MUTT_MBOX; - tmpctx = mx_mbox_open(tmp, MUTT_NEWFOLDER, NULL); + tmpctx = mx_mbox_open(tmp, MUTT_NEWFOLDER); MboxType = omagic; @@ -185,7 +185,7 @@ static int edit_or_view_one_message(bool edit, struct Context *ctx, struct Heade goto bail; } - tmpctx = mx_mbox_open(ctx->path, MUTT_APPEND, NULL); + tmpctx = mx_mbox_open(ctx->path, MUTT_APPEND); if (!tmpctx) { rc = -1; diff --git a/imap/imap.c b/imap/imap.c index 6568f2293..86b9ea553 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -2439,7 +2439,7 @@ int imap_sync_mailbox(struct Context *ctx, bool expunge) "Saving changed messages... [%d/%d]", ctx->msgcount), i + 1, ctx->msgcount); if (!appendctx) - appendctx = mx_mbox_open(ctx->path, MUTT_APPEND | MUTT_QUIET, NULL); + appendctx = mx_mbox_open(ctx->path, MUTT_APPEND | MUTT_QUIET); if (!appendctx) mutt_debug(1, "Error opening mailbox in append mode\n"); else diff --git a/mailbox.c b/mailbox.c index 3ae2dd5c1..8ebdb24af 100644 --- a/mailbox.c +++ b/mailbox.c @@ -358,7 +358,7 @@ static int mailbox_mbox_check(struct Mailbox *mailbox, struct stat *sb, bool che if (check_stats && (mailbox->stats_last_checked < sb->st_mtime)) { - struct Context *ctx = mx_mbox_open(mailbox->path, MUTT_READONLY | MUTT_QUIET | MUTT_NOSORT | MUTT_PEEK, NULL); + struct Context *ctx = mx_mbox_open(mailbox->path, MUTT_READONLY | MUTT_QUIET | MUTT_NOSORT | MUTT_PEEK); if (ctx) { mailbox->msg_count = ctx->msgcount; diff --git a/main.c b/main.c index 5cd767a81..78fbe51be 100644 --- a/main.c +++ b/main.c @@ -1196,7 +1196,7 @@ int main(int argc, char *argv[], char *envp[]) mutt_startup_shutdown_hook(MUTT_STARTUP_HOOK); repeat_error = true; - Context = mx_mbox_open(folder, ((flags & MUTT_RO) || ReadOnly) ? MUTT_READONLY : 0, NULL); + Context = mx_mbox_open(folder, ((flags & MUTT_RO) || ReadOnly) ? MUTT_READONLY : 0); if (Context || !explicit_folder) { #ifdef USE_SIDEBAR diff --git a/mutt_attach.c b/mutt_attach.c index 242f5f793..75c7061a1 100644 --- a/mutt_attach.c +++ b/mutt_attach.c @@ -803,7 +803,7 @@ int mutt_save_attachment(FILE *fp, struct Body *m, char *path, int flags, struct return -1; if (!fgets(buf, sizeof(buf), fp)) return -1; - struct Context *ctx = mx_mbox_open(path, MUTT_APPEND | MUTT_QUIET, NULL); + struct Context *ctx = mx_mbox_open(path, MUTT_APPEND | MUTT_QUIET); if (!ctx) return -1; msg = mx_msg_open_new(ctx, hn, is_from(buf, NULL, 0, NULL) ? 0 : MUTT_ADD_FROM); diff --git a/mx.c b/mx.c index a6b4ad795..9618822fe 100644 --- a/mx.c +++ b/mx.c @@ -228,7 +228,6 @@ static int mx_open_mailbox_append(struct Context *ctx, int flags) * mx_mbox_open - Open a mailbox and parse it * @param path Path to the mailbox * @param flags See below - * @param pctx Reuse this Context (if supplied) * @retval ptr Mailbox context * @retval NULL Error * @@ -239,23 +238,19 @@ static int mx_open_mailbox_append(struct Context *ctx, int flags) * * #MUTT_QUIET only print error messages * * #MUTT_PEEK revert atime where applicable */ -struct Context *mx_mbox_open(const char *path, int flags, struct Context *pctx) +struct Context *mx_mbox_open(const char *path, int flags) { - struct Context *ctx = pctx; - int rc; - if (!path || !path[0]) return NULL; - if (!ctx) - ctx = mutt_mem_malloc(sizeof(struct Context)); - memset(ctx, 0, sizeof(struct Context)); + int rc; + + struct Context *ctx = mutt_mem_calloc(1, sizeof(*ctx)); ctx->path = mutt_str_strdup(path); if (!ctx->path) { - if (!pctx) - FREE(&ctx); + FREE(&ctx); return NULL; } ctx->realpath = realpath(ctx->path, NULL); @@ -280,8 +275,7 @@ struct Context *mx_mbox_open(const char *path, int flags, struct Context *pctx) if (mx_open_mailbox_append(ctx, flags) != 0) { mx_fastclose_mailbox(ctx); - if (!pctx) - FREE(&ctx); + FREE(&ctx); return NULL; } return ctx; @@ -298,8 +292,7 @@ struct Context *mx_mbox_open(const char *path, int flags, struct Context *pctx) mutt_error(_("%s is not a mailbox"), path); mx_fastclose_mailbox(ctx); - if (!pctx) - FREE(&ctx); + FREE(&ctx); return NULL; } @@ -335,8 +328,7 @@ struct Context *mx_mbox_open(const char *path, int flags, struct Context *pctx) else { mx_fastclose_mailbox(ctx); - if (!pctx) - FREE(&ctx); + FREE(&ctx); } OptForceRefresh = false; @@ -467,7 +459,7 @@ static int trash_append(struct Context *ctx) } #endif - struct Context *ctx_trash = mx_mbox_open(Trash, MUTT_APPEND, NULL); + struct Context *ctx_trash = mx_mbox_open(Trash, MUTT_APPEND); if (ctx_trash) { /* continue from initial scan above */ @@ -648,7 +640,7 @@ int mx_mbox_close(struct Context *ctx, int *index_hint) else /* use regular append-copy mode */ #endif { - struct Context *f = mx_mbox_open(mbox, MUTT_APPEND, NULL); + struct Context *f = mx_mbox_open(mbox, MUTT_APPEND); if (!f) { ctx->closing = false; diff --git a/mx.h b/mx.h index 7d44c3402..f69e3ba68 100644 --- a/mx.h +++ b/mx.h @@ -230,7 +230,7 @@ struct MxOps /* 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); -struct Context *mx_mbox_open (const char *path, int flags, struct Context *pctx); +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); int mx_msg_commit (struct Context *ctx, struct Message *msg); diff --git a/pop/pop.c b/pop/pop.c index 9ff5fa17f..d39ad4a9e 100644 --- a/pop/pop.c +++ b/pop/pop.c @@ -968,7 +968,7 @@ void pop_fetch_mail(void) goto finish; } - struct Context *ctx = mx_mbox_open(Spoolfile, MUTT_APPEND, NULL); + struct Context *ctx = mx_mbox_open(Spoolfile, MUTT_APPEND); if (!ctx) goto finish; diff --git a/postpone.c b/postpone.c index e2f27454b..80a7aee85 100644 --- a/postpone.c +++ b/postpone.c @@ -161,7 +161,7 @@ int mutt_num_postponed(bool force) if (optnews) OptNews = false; #endif - struct Context *ctx = mx_mbox_open(Postponed, MUTT_NOSORT | MUTT_QUIET, NULL); + struct Context *ctx = mx_mbox_open(Postponed, MUTT_NOSORT | MUTT_QUIET); if (!ctx) PostCount = 0; else @@ -290,7 +290,7 @@ int mutt_get_postponed(struct Context *ctx, struct Header *hdr, if (!Postponed) return -1; - PostContext = mx_mbox_open(Postponed, MUTT_NOSORT, NULL); + PostContext = mx_mbox_open(Postponed, MUTT_NOSORT); if (!PostContext) { PostCount = 0; diff --git a/sendlib.c b/sendlib.c index 7bc944f3d..18424d623 100644 --- a/sendlib.c +++ b/sendlib.c @@ -3176,7 +3176,7 @@ int mutt_write_fcc(const char *path, struct Header *hdr, const char *msgid, #ifdef RECORD_FOLDER_HOOK mutt_folder_hook(path); #endif - struct Context *f = mx_mbox_open(path, MUTT_APPEND | MUTT_QUIET, NULL); + struct Context *f = mx_mbox_open(path, MUTT_APPEND | MUTT_QUIET); if (!f) { mutt_debug(1, "unable to open mailbox %s in append-mode, aborting.\n", path);