From: Richard Russon Date: Mon, 27 Aug 2018 17:22:35 +0000 (+0100) Subject: don't use mx_open's Context parameter X-Git-Tag: 2019-10-25~676^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=452da3b65d06a6ad40653c367836fcedb940e7b1;p=neomutt don't use mx_open's Context parameter --- diff --git a/commands.c b/commands.c index fb4f63661..a9bc9c885 100644 --- a/commands.c +++ b/commands.c @@ -876,7 +876,7 @@ int mutt_save_message(struct Header *h, bool delete, bool decode, bool decrypt) int app = 0; char buf[PATH_MAX]; const char *prompt = NULL; - struct Context ctx; + struct Context *savectx = NULL; struct stat st; if (delete) @@ -986,23 +986,25 @@ int mutt_save_message(struct Header *h, bool delete, bool decode, bool decrypt) } #endif - if (mx_mbox_open(buf, MUTT_APPEND, &ctx)) + savectx = mx_mbox_open(buf, MUTT_APPEND, NULL); + if (savectx) { #ifdef USE_COMPRESSED /* If we're saving to a compressed mailbox, the stats won't be updated * until the next open. Until then, improvise. */ struct Mailbox *cm = NULL; - if (ctx.compress_info) - cm = mutt_find_mailbox(ctx.realpath); + if (savectx->compress_info) + cm = mutt_find_mailbox(savectx->realpath); /* We probably haven't been opened yet */ if (cm && (cm->msg_count == 0)) cm = NULL; #endif if (h) { - if (mutt_save_message_ctx(h, delete, decode, decrypt, &ctx) != 0) + if (mutt_save_message_ctx(h, delete, decode, decrypt, savectx) != 0) { - mx_mbox_close(&ctx, NULL); + mx_mbox_close(savectx, NULL); + FREE(&savectx); return -1; } #ifdef USE_COMPRESSED @@ -1030,7 +1032,7 @@ int mutt_save_message(struct Header *h, bool delete, bool decode, bool decrypt) continue; mutt_message_hook(Context, Context->hdrs[i], MUTT_MESSAGE_HOOK); - rc = mutt_save_message_ctx(Context->hdrs[i], delete, decode, decrypt, &ctx); + rc = mutt_save_message_ctx(Context->hdrs[i], delete, decode, decrypt, savectx); if (rc != 0) break; #ifdef USE_COMPRESSED @@ -1051,14 +1053,16 @@ int mutt_save_message(struct Header *h, bool delete, bool decode, bool decrypt) #endif if (rc != 0) { - mx_mbox_close(&ctx, NULL); + mx_mbox_close(savectx, NULL); + FREE(&savectx); return -1; } } - const int need_mailbox_cleanup = (ctx.magic == MUTT_MBOX || ctx.magic == MUTT_MMDF); + const bool need_mailbox_cleanup = ((savectx->magic == MUTT_MBOX) || (savectx->magic == MUTT_MMDF)); - mx_mbox_close(&ctx, NULL); + mx_mbox_close(savectx, NULL); + FREE(&savectx); if (need_mailbox_cleanup) mutt_mailbox_cleanup(buf, &st); diff --git a/curs_main.c b/curs_main.c index 158a3c305..92b19519e 100644 --- a/curs_main.c +++ b/curs_main.c @@ -550,8 +550,8 @@ static int main_change_folder(struct Menu *menu, int op, char *buf, * switch statement would need to be run. */ mutt_folder_hook(buf); - Context = mx_mbox_open( - buf, (ReadOnly || (op == OP_MAIN_CHANGE_FOLDER_READONLY)) ? MUTT_READONLY : 0, NULL); + const int flags = (ReadOnly || (op == OP_MAIN_CHANGE_FOLDER_READONLY)) ? MUTT_READONLY : 0; + Context = mx_mbox_open(buf, flags, NULL); if (Context) { menu->current = ci_first_message(); diff --git a/editmsg.c b/editmsg.c index 3553e67c1..288babe20 100644 --- a/editmsg.c +++ b/editmsg.c @@ -70,7 +70,7 @@ static int edit_or_view_one_message(bool edit, struct Context *ctx, struct Heade int of, cf; - struct Context tmpctx; + struct Context *tmpctx = NULL; struct Message *msg = NULL; FILE *fp = NULL; @@ -83,22 +83,22 @@ static int edit_or_view_one_message(bool edit, struct Context *ctx, struct Heade omagic = MboxType; MboxType = MUTT_MBOX; - rc = mx_mbox_open(tmp, MUTT_NEWFOLDER, &tmpctx) ? 0 : -1; + tmpctx = mx_mbox_open(tmp, MUTT_NEWFOLDER, NULL); MboxType = omagic; - if (rc == -1) + if (!tmpctx) { mutt_error(_("could not create temporary folder: %s"), strerror(errno)); return -1; } - rc = mutt_append_message( - &tmpctx, ctx, cur, 0, - CH_NOLEN | ((ctx->magic == MUTT_MBOX || ctx->magic == MUTT_MMDF) ? 0 : CH_NOSTATUS)); + const int chflags = CH_NOLEN | ((ctx->magic == MUTT_MBOX || ctx->magic == MUTT_MMDF) ? 0 : CH_NOSTATUS); + rc = mutt_append_message(tmpctx, ctx, cur, 0, chflags); oerrno = errno; - mx_mbox_close(&tmpctx, NULL); + mx_mbox_close(tmpctx, NULL); + FREE(&tmpctx); if (rc == -1) { @@ -185,7 +185,8 @@ static int edit_or_view_one_message(bool edit, struct Context *ctx, struct Heade goto bail; } - if (!mx_mbox_open(ctx->path, MUTT_APPEND, &tmpctx)) + tmpctx = mx_mbox_open(ctx->path, MUTT_APPEND, NULL); + if (!tmpctx) { rc = -1; /* L10N: %s is from strerror(errno) */ @@ -194,11 +195,11 @@ static int edit_or_view_one_message(bool edit, struct Context *ctx, struct Heade } of = 0; - cf = ((tmpctx.magic == MUTT_MBOX || tmpctx.magic == MUTT_MMDF) ? 0 : CH_NOSTATUS); + cf = (((tmpctx->magic == MUTT_MBOX) || (tmpctx->magic == MUTT_MMDF)) ? 0 : CH_NOSTATUS); if (fgets(buf, sizeof(buf), fp) && is_from(buf, NULL, 0, NULL)) { - if (tmpctx.magic == MUTT_MBOX || tmpctx.magic == MUTT_MMDF) + if ((tmpctx->magic == MUTT_MBOX) || (tmpctx->magic == MUTT_MMDF)) cf = CH_FROM | CH_FORCE_FROM; } else @@ -211,14 +212,15 @@ static int edit_or_view_one_message(bool edit, struct Context *ctx, struct Heade o_old = cur->old; cur->read = false; cur->old = false; - msg = mx_msg_open_new(&tmpctx, cur, of); + msg = mx_msg_open_new(tmpctx, cur, of); cur->read = o_read; cur->old = o_old; if (!msg) { mutt_error(_("Can't append to folder: %s"), strerror(errno)); - mx_mbox_close(&tmpctx, NULL); + mx_mbox_close(tmpctx, NULL); + FREE(&tmpctx); goto bail; } @@ -229,10 +231,11 @@ static int edit_or_view_one_message(bool edit, struct Context *ctx, struct Heade mutt_file_copy_stream(fp, msg->fp); } - rc = mx_msg_commit(&tmpctx, msg); - mx_msg_close(&tmpctx, &msg); + rc = mx_msg_commit(tmpctx, msg); + mx_msg_close(tmpctx, &msg); - mx_mbox_close(&tmpctx, NULL); + mx_mbox_close(tmpctx, NULL); + FREE(&tmpctx); bail: if (fp) diff --git a/mailbox.c b/mailbox.c index 19927a720..3ae2dd5c1 100644 --- a/mailbox.c +++ b/mailbox.c @@ -328,16 +328,15 @@ static int mailbox_maildir_check(struct Mailbox *mailbox, bool check_stats) static int mailbox_mbox_check(struct Mailbox *mailbox, struct stat *sb, bool check_stats) { int rc = 0; - int new_or_changed; - struct Context ctx; + bool new_or_changed; if (CheckMboxSize) - new_or_changed = sb->st_size > mailbox->size; + new_or_changed = (sb->st_size > mailbox->size); else { - new_or_changed = sb->st_mtime > sb->st_atime || - (mailbox->newly_created && sb->st_ctime == sb->st_mtime && - sb->st_ctime == sb->st_atime); + new_or_changed = (sb->st_mtime > sb->st_atime) || + (mailbox->newly_created && (sb->st_ctime == sb->st_mtime) && + (sb->st_ctime == sb->st_atime)); } if (new_or_changed) @@ -359,14 +358,15 @@ static int mailbox_mbox_check(struct Mailbox *mailbox, struct stat *sb, bool che if (check_stats && (mailbox->stats_last_checked < sb->st_mtime)) { - if (mx_mbox_open(mailbox->path, MUTT_READONLY | MUTT_QUIET | MUTT_NOSORT | MUTT_PEEK, - &ctx)) + struct Context *ctx = mx_mbox_open(mailbox->path, MUTT_READONLY | MUTT_QUIET | MUTT_NOSORT | MUTT_PEEK, NULL); + if (ctx) { - mailbox->msg_count = ctx.msgcount; - mailbox->msg_unread = ctx.unread; - mailbox->msg_flagged = ctx.flagged; - mailbox->stats_last_checked = ctx.mtime; - mx_mbox_close(&ctx, 0); + mailbox->msg_count = ctx->msgcount; + mailbox->msg_unread = ctx->unread; + mailbox->msg_flagged = ctx->flagged; + mailbox->stats_last_checked = ctx->mtime; + mx_mbox_close(ctx, NULL); + FREE(&ctx); } } diff --git a/mutt_attach.c b/mutt_attach.c index e6945aebe..242f5f793 100644 --- a/mutt_attach.c +++ b/mutt_attach.c @@ -791,7 +791,6 @@ int mutt_save_attachment(FILE *fp, struct Body *m, char *path, int flags, struct /* message type attachments are written to mail folders. */ char buf[HUGE_STRING]; - struct Context ctx; struct Message *msg = NULL; int chflags = 0; int r = -1; @@ -804,19 +803,21 @@ int mutt_save_attachment(FILE *fp, struct Body *m, char *path, int flags, struct return -1; if (!fgets(buf, sizeof(buf), fp)) return -1; - if (!mx_mbox_open(path, MUTT_APPEND | MUTT_QUIET, &ctx)) + struct Context *ctx = mx_mbox_open(path, MUTT_APPEND | MUTT_QUIET, NULL); + if (!ctx) return -1; - msg = mx_msg_open_new(&ctx, hn, is_from(buf, NULL, 0, NULL) ? 0 : MUTT_ADD_FROM); + msg = mx_msg_open_new(ctx, hn, is_from(buf, NULL, 0, NULL) ? 0 : MUTT_ADD_FROM); if (!msg) { - mx_mbox_close(&ctx, NULL); + mx_mbox_close(ctx, NULL); + FREE(&ctx); return -1; } - if (ctx.magic == MUTT_MBOX || ctx.magic == MUTT_MMDF) + if ((ctx->magic == MUTT_MBOX) || (ctx->magic == MUTT_MMDF)) chflags = CH_FROM | CH_UPDATE_LEN; - chflags |= (ctx.magic == MUTT_MAILDIR ? CH_NOSTATUS : CH_UPDATE); - if (mutt_copy_message_fp(msg->fp, fp, hn, 0, chflags) == 0 && - mx_msg_commit(&ctx, msg) == 0) + chflags |= (ctx->magic == MUTT_MAILDIR ? CH_NOSTATUS : CH_UPDATE); + if ((mutt_copy_message_fp(msg->fp, fp, hn, 0, chflags) == 0) && + (mx_msg_commit(ctx, msg) == 0)) { r = 0; } @@ -825,8 +826,9 @@ int mutt_save_attachment(FILE *fp, struct Body *m, char *path, int flags, struct r = -1; } - mx_msg_close(&ctx, &msg); - mx_mbox_close(&ctx, NULL); + mx_msg_close(ctx, &msg); + mx_mbox_close(ctx, NULL); + FREE(&ctx); return r; } else diff --git a/mx.c b/mx.c index f0bcd635d..a6b4ad795 100644 --- a/mx.c +++ b/mx.c @@ -415,7 +415,6 @@ static int sync_mailbox(struct Context *ctx, int *index_hint) */ static int trash_append(struct Context *ctx) { - struct Context ctx_trash; int i; struct stat st, stc; int opt_confappend, rc; @@ -468,22 +467,25 @@ static int trash_append(struct Context *ctx) } #endif - if (mx_mbox_open(Trash, MUTT_APPEND, &ctx_trash)) + struct Context *ctx_trash = mx_mbox_open(Trash, MUTT_APPEND, NULL); + if (ctx_trash) { /* continue from initial scan above */ for (i = first_del; i < ctx->msgcount; i++) { if (ctx->hdrs[i]->deleted && (!ctx->hdrs[i]->purge)) { - if (mutt_append_message(&ctx_trash, ctx, ctx->hdrs[i], 0, 0) == -1) + if (mutt_append_message(ctx_trash, ctx, ctx->hdrs[i], 0, 0) == -1) { - mx_mbox_close(&ctx_trash, NULL); + mx_mbox_close(ctx_trash, NULL); + FREE(&ctx_trash); return -1; } } } - mx_mbox_close(&ctx_trash, NULL); + mx_mbox_close(ctx_trash, NULL); + FREE(&ctx_trash); } else { @@ -504,7 +506,6 @@ static int trash_append(struct Context *ctx) int mx_mbox_close(struct Context *ctx, int *index_hint) { int i, move_messages = 0, purge = 1, read_msgs = 0; - struct Context f; char mbox[PATH_MAX]; char buf[PATH_MAX + 64]; @@ -647,7 +648,8 @@ int mx_mbox_close(struct Context *ctx, int *index_hint) else /* use regular append-copy mode */ #endif { - if (!mx_mbox_open(mbox, MUTT_APPEND, &f)) + struct Context *f = mx_mbox_open(mbox, MUTT_APPEND, NULL); + if (!f) { ctx->closing = false; return -1; @@ -658,21 +660,23 @@ int mx_mbox_close(struct Context *ctx, int *index_hint) if (ctx->hdrs[i]->read && !ctx->hdrs[i]->deleted && !(ctx->hdrs[i]->flagged && KeepFlagged)) { - if (mutt_append_message(&f, ctx, ctx->hdrs[i], 0, CH_UPDATE_LEN) == 0) + if (mutt_append_message(f, ctx, ctx->hdrs[i], 0, CH_UPDATE_LEN) == 0) { mutt_set_flag(ctx, ctx->hdrs[i], MUTT_DELETE, 1); mutt_set_flag(ctx, ctx->hdrs[i], MUTT_PURGE, 1); } else { - mx_mbox_close(&f, NULL); + mx_mbox_close(f, NULL); + FREE(&f); ctx->closing = false; return -1; } } } - mx_mbox_close(&f, NULL); + mx_mbox_close(f, NULL); + FREE(&f); } } else if (!ctx->changed && ctx->deleted == 0) diff --git a/mx.h b/mx.h index 6f3f536ef..7d44c3402 100644 --- a/mx.h +++ b/mx.h @@ -34,6 +34,7 @@ struct Header; struct Context; +struct Mailbox; struct stat; /* These Config Variables are only used in mx.c */ diff --git a/pop/pop.c b/pop/pop.c index e25da70b9..9ff5fa17f 100644 --- a/pop/pop.c +++ b/pop/pop.c @@ -893,7 +893,6 @@ void pop_fetch_mail(void) char *url = NULL, *p = NULL; int delanswer, last = 0, msgs, bytes, rset = 0, ret; struct Connection *conn = NULL; - struct Context ctx; struct Message *msg = NULL; struct Account acct; struct PopData *pop_data = NULL; @@ -969,7 +968,8 @@ void pop_fetch_mail(void) goto finish; } - if (!mx_mbox_open(Spoolfile, MUTT_APPEND, &ctx)) + struct Context *ctx = mx_mbox_open(Spoolfile, MUTT_APPEND, NULL); + if (!ctx) goto finish; delanswer = query_quadoption(PopDelete, _("Delete messages from server?")); @@ -982,7 +982,7 @@ void pop_fetch_mail(void) for (int i = last + 1; i <= msgs; i++) { - msg = mx_msg_open_new(&ctx, NULL, MUTT_ADD_FROM); + msg = mx_msg_open_new(ctx, NULL, MUTT_ADD_FROM); if (!msg) ret = -3; else @@ -992,13 +992,13 @@ void pop_fetch_mail(void) if (ret == -3) rset = 1; - if (ret == 0 && mx_msg_commit(&ctx, msg) != 0) + if (ret == 0 && mx_msg_commit(ctx, msg) != 0) { rset = 1; ret = -3; } - mx_msg_close(&ctx, &msg); + mx_msg_close(ctx, &msg); } if (ret == 0 && delanswer == MUTT_YES) @@ -1010,7 +1010,8 @@ void pop_fetch_mail(void) if (ret == -1) { - mx_mbox_close(&ctx, NULL); + mx_mbox_close(ctx, NULL); + FREE(&ctx); goto fail; } if (ret == -2) @@ -1031,7 +1032,8 @@ void pop_fetch_mail(void) msgbuf, i - last, msgs - last); } - mx_mbox_close(&ctx, NULL); + mx_mbox_close(ctx, NULL); + FREE(&ctx); if (rset) { diff --git a/postpone.c b/postpone.c index a66af71fe..e2f27454b 100644 --- a/postpone.c +++ b/postpone.c @@ -84,7 +84,6 @@ static short UpdateNumPostponed = 0; int mutt_num_postponed(bool force) { struct stat st; - struct Context ctx; static time_t LastModify = 0; static char *OldPostponed = NULL; @@ -162,11 +161,13 @@ int mutt_num_postponed(bool force) if (optnews) OptNews = false; #endif - if (!mx_mbox_open(Postponed, MUTT_NOSORT | MUTT_QUIET, &ctx)) + struct Context *ctx = mx_mbox_open(Postponed, MUTT_NOSORT | MUTT_QUIET, NULL); + if (!ctx) PostCount = 0; else - PostCount = ctx.msgcount; - mx_fastclose_mailbox(&ctx); + PostCount = ctx->msgcount; + mx_fastclose_mailbox(ctx); + FREE(&ctx); #ifdef USE_NNTP if (optnews) OptNews = true; diff --git a/sendlib.c b/sendlib.c index 76bc024eb..7bc944f3d 100644 --- a/sendlib.c +++ b/sendlib.c @@ -3161,7 +3161,6 @@ int mutt_write_multiple_fcc(const char *path, struct Header *hdr, const char *ms int mutt_write_fcc(const char *path, struct Header *hdr, const char *msgid, bool post, char *fcc, char **finalpath) { - struct Context f; struct Message *msg = NULL; char tempfile[PATH_MAX]; FILE *tempfp = NULL; @@ -3177,7 +3176,8 @@ int mutt_write_fcc(const char *path, struct Header *hdr, const char *msgid, #ifdef RECORD_FOLDER_HOOK mutt_folder_hook(path); #endif - if (!mx_mbox_open(path, MUTT_APPEND | MUTT_QUIET, &f)) + struct Context *f = mx_mbox_open(path, MUTT_APPEND | MUTT_QUIET, NULL); + if (!f) { mutt_debug(1, "unable to open mailbox %s in append-mode, aborting.\n", path); goto done; @@ -3186,14 +3186,15 @@ int mutt_write_fcc(const char *path, struct Header *hdr, const char *msgid, /* We need to add a Content-Length field to avoid problems where a line in * the message body begins with "From " */ - if (f.magic == MUTT_MMDF || f.magic == MUTT_MBOX) + if ((f->magic == MUTT_MMDF) || (f->magic == MUTT_MBOX)) { mutt_mktemp(tempfile, sizeof(tempfile)); tempfp = mutt_file_fopen(tempfile, "w+"); if (!tempfp) { mutt_perror(tempfile); - mx_mbox_close(&f, NULL); + mx_mbox_close(f, NULL); + FREE(&f); goto done; } /* remember new mail status before appending message */ @@ -3205,11 +3206,12 @@ int mutt_write_fcc(const char *path, struct Header *hdr, const char *msgid, onm_flags = MUTT_ADD_FROM; if (post) onm_flags |= MUTT_SET_DRAFT; - msg = mx_msg_open_new(&f, hdr, onm_flags); + msg = mx_msg_open_new(f, hdr, onm_flags); if (!msg) { mutt_file_fclose(&tempfp); - mx_mbox_close(&f, NULL); + mx_mbox_close(f, NULL); + FREE(&f); goto done; } @@ -3233,7 +3235,7 @@ int mutt_write_fcc(const char *path, struct Header *hdr, const char *msgid, if (post && fcc) fprintf(msg->fp, "X-Mutt-Fcc: %s\n", fcc); - if (f.magic == MUTT_MMDF || f.magic == MUTT_MBOX) + if ((f->magic == MUTT_MMDF) || (f->magic == MUTT_MBOX)) fprintf(msg->fp, "Status: RO\n"); /* mutt_rfc822_write_header() only writes out a Date: header with @@ -3325,9 +3327,10 @@ int mutt_write_fcc(const char *path, struct Header *hdr, const char *msgid, mutt_debug(1, "%s: write failed.\n", tempfile); mutt_file_fclose(&tempfp); unlink(tempfile); - mx_msg_commit(&f, msg); /* XXX really? */ - mx_msg_close(&f, &msg); - mx_mbox_close(&f, NULL); + mx_msg_commit(f, msg); /* XXX really? */ + mx_msg_close(f, &msg); + mx_mbox_close(f, NULL); + FREE(&f); goto done; } @@ -3353,12 +3356,13 @@ int mutt_write_fcc(const char *path, struct Header *hdr, const char *msgid, rc = mutt_write_mime_body(hdr->content, msg->fp); } - if (mx_msg_commit(&f, msg) != 0) + if (mx_msg_commit(f, msg) != 0) rc = -1; else if (finalpath) *finalpath = mutt_str_strdup(msg->committed_path); - mx_msg_close(&f, &msg); - mx_mbox_close(&f, NULL); + mx_msg_close(f, &msg); + mx_mbox_close(f, NULL); + FREE(&f); if (!post && need_mailbox_cleanup) mutt_mailbox_cleanup(path, &st);