From 9a3d2709193430046cfaaf60d510a1fc436402f4 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Tue, 24 Oct 2017 13:27:21 +0100 Subject: [PATCH] fix actions on tagged messages (#823) Many actions aren't performed on all tagged messages if the messages are within a collapsed thread. --- commands.c | 129 +++++++++++++++++++++++++------------------------ compose.c | 22 ++++----- curs_lib.c | 31 ++++++++++++ curs_main.c | 69 +++++++++++++------------- editmsg.c | 13 +++-- flags.c | 6 +-- headers.c | 20 ++++---- imap/message.c | 21 ++++---- ncrypt/crypt.c | 80 +++++++++++++++--------------- protos.h | 3 ++ send.c | 100 ++++++++++++++++++++------------------ sendlib.c | 2 +- thread.c | 6 +-- 13 files changed, 271 insertions(+), 231 deletions(-) diff --git a/commands.c b/commands.c index ff12b91a6..3a1b43d74 100644 --- a/commands.c +++ b/commands.c @@ -281,7 +281,7 @@ void ci_bounce_message(struct Header *h) { for (rc = 0; rc < Context->msgcount; rc++) { - if (Context->hdrs[rc]->tagged && !Context->hdrs[rc]->env->from) + if (message_is_tagged(Context, rc) && !Context->hdrs[rc]->env->from) { mutt_error(_("Warning: message contains no From: header")); mutt_sleep(2); @@ -425,45 +425,49 @@ static int _mutt_pipe_message(struct Header *h, char *cmd, int decode, unset_option(OPT_KEEP_QUIET); } else - { /* handle tagged messages */ - + { + /* handle tagged messages */ if (WithCrypto && decode) { - for (int i = 0; i < Context->vcount; i++) - if (Context->hdrs[Context->v2r[i]]->tagged) + for (int i = 0; i < Context->msgcount; i++) + { + if (!message_is_tagged(Context, i)) + continue; + + mutt_message_hook(Context, Context->hdrs[i], MUTT_MESSAGEHOOK); + mutt_parse_mime_message(Context, Context->hdrs[i]); + if (Context->hdrs[i]->security & ENCRYPT && + !crypt_valid_passphrase(Context->hdrs[i]->security)) { - mutt_message_hook(Context, Context->hdrs[Context->v2r[i]], MUTT_MESSAGEHOOK); - mutt_parse_mime_message(Context, Context->hdrs[Context->v2r[i]]); - if (Context->hdrs[Context->v2r[i]]->security & ENCRYPT && - !crypt_valid_passphrase(Context->hdrs[Context->v2r[i]]->security)) - return 1; + return 1; } + } } if (split) { - for (int i = 0; i < Context->vcount; i++) + for (int i = 0; i < Context->msgcount; i++) { - if (Context->hdrs[Context->v2r[i]]->tagged) + if (!message_is_tagged(Context, i)) + continue; + + mutt_message_hook(Context, Context->hdrs[i], MUTT_MESSAGEHOOK); + mutt_endwin(NULL); + thepid = mutt_create_filter(cmd, &fpout, NULL, NULL); + if (thepid < 0) { - mutt_message_hook(Context, Context->hdrs[Context->v2r[i]], MUTT_MESSAGEHOOK); - mutt_endwin(NULL); - thepid = mutt_create_filter(cmd, &fpout, NULL, NULL); - if (thepid < 0) - { - mutt_perror(_("Can't create filter process")); - return 1; - } - set_option(OPT_KEEP_QUIET); - pipe_msg(Context->hdrs[Context->v2r[i]], fpout, decode, print); - /* add the message separator */ - if (sep) - fputs(sep, fpout); - safe_fclose(&fpout); - if (mutt_wait_filter(thepid) != 0) - rc = 1; - unset_option(OPT_KEEP_QUIET); + mutt_perror(_("Can't create filter process")); + return 1; } + set_option(OPT_KEEP_QUIET); + pipe_msg(Context->hdrs[i], fpout, decode, print); + /* add the message separator */ + if (sep) + fputs(sep, fpout); + safe_fclose(&fpout); + if (mutt_wait_filter(thepid) != 0) + rc = 1; + unset_option(OPT_KEEP_QUIET); } } else @@ -476,16 +480,16 @@ static int _mutt_pipe_message(struct Header *h, char *cmd, int decode, return 1; } set_option(OPT_KEEP_QUIET); - for (int i = 0; i < Context->vcount; i++) + for (int i = 0; i < Context->msgcount; i++) { - if (Context->hdrs[Context->v2r[i]]->tagged) - { - mutt_message_hook(Context, Context->hdrs[Context->v2r[i]], MUTT_MESSAGEHOOK); - pipe_msg(Context->hdrs[Context->v2r[i]], fpout, decode, print); - /* add the message separator */ - if (sep) - fputs(sep, fpout); - } + if (!message_is_tagged(Context, i)) + continue; + + mutt_message_hook(Context, Context->hdrs[i], MUTT_MESSAGEHOOK); + pipe_msg(Context->hdrs[i], fpout, decode, print); + /* add the message separator */ + if (sep) + fputs(sep, fpout); } safe_fclose(&fpout); if (mutt_wait_filter(thepid) != 0) @@ -781,12 +785,11 @@ int mutt_save_message(struct Header *h, int delete, int decode, int decrypt) else { /* look for the first tagged message */ - - for (int i = 0; i < Context->vcount; i++) + for (int i = 0; i < Context->msgcount; i++) { - if (Context->hdrs[Context->v2r[i]]->tagged) + if (message_is_tagged(Context, i)) { - h = Context->hdrs[Context->v2r[i]]; + h = Context->hdrs[i]; break; } } @@ -892,26 +895,25 @@ int mutt_save_message(struct Header *h, int delete, int decode, int decrypt) if (Context->magic == MUTT_NOTMUCH) nm_longrun_init(Context, true); #endif - for (int i = 0; i < Context->vcount; i++) + for (int i = 0; i < Context->msgcount; i++) { - if (Context->hdrs[Context->v2r[i]]->tagged) - { - mutt_message_hook(Context, Context->hdrs[Context->v2r[i]], MUTT_MESSAGEHOOK); - if ((rc = _mutt_save_message(Context->hdrs[Context->v2r[i]], &ctx, - delete, decode, decrypt) != 0)) - break; + if (!message_is_tagged(Context, i)) + continue; + + mutt_message_hook(Context, Context->hdrs[i], MUTT_MESSAGEHOOK); + if ((rc = _mutt_save_message(Context->hdrs[i], &ctx, delete, decode, decrypt) != 0)) + break; #ifdef USE_COMPRESSED - if (cm) - { - struct Header *h2 = Context->hdrs[Context->v2r[i]]; - cm->msg_count++; - if (!h2->read) - cm->msg_unread++; - if (h2->flagged) - cm->msg_flagged++; - } -#endif + if (cm) + { + struct Header *h2 = Context->hdrs[i]; + cm->msg_count++; + if (!h2->read) + cm->msg_unread++; + if (h2->flagged) + cm->msg_flagged++; } +#endif } #ifdef USE_NOTMUCH if (Context->magic == MUTT_NOTMUCH) @@ -1081,12 +1083,13 @@ int mutt_check_traditional_pgp(struct Header *h, int *redraw) rv = _mutt_check_traditional_pgp(h, redraw); else { - for (int i = 0; i < Context->vcount; i++) - if (Context->hdrs[Context->v2r[i]]->tagged && - !(Context->hdrs[Context->v2r[i]]->security & PGP_TRADITIONAL_CHECKED)) + for (int i = 0; i < Context->msgcount; i++) + { + if (message_is_tagged(Context, i) && !(Context->hdrs[i]->security & PGP_TRADITIONAL_CHECKED)) { - rv = _mutt_check_traditional_pgp(Context->hdrs[Context->v2r[i]], redraw) || rv; + rv = _mutt_check_traditional_pgp(Context->hdrs[i], redraw) || rv; } + } } return rv; } diff --git a/compose.c b/compose.c index 4ac7c4e5a..b91ab0dc9 100644 --- a/compose.c +++ b/compose.c @@ -1057,7 +1057,6 @@ int mutt_compose_menu(struct Header *msg, /* structure for new message */ #endif { char *prompt = NULL; - struct Header *h = NULL; fname[0] = 0; prompt = _("Open mailbox to attach message from"); @@ -1149,18 +1148,17 @@ int mutt_compose_menu(struct Header *msg, /* structure for new message */ for (i = 0; i < Context->msgcount; i++) { - h = Context->hdrs[i]; - if (h->tagged) + if (!message_is_tagged(Context, i)) + continue; + + new = (struct AttachPtr *) safe_calloc(1, sizeof(struct AttachPtr)); + new->content = mutt_make_message_attach(Context, Context->hdrs[i], 1); + if (new->content != NULL) + update_idx(menu, actx, new); + else { - new = (struct AttachPtr *) safe_calloc(1, sizeof(struct AttachPtr)); - new->content = mutt_make_message_attach(Context, h, 1); - if (new->content) - update_idx(menu, actx, new); - else - { - mutt_error(_("Unable to attach!")); - FREE(&new); - } + mutt_error(_("Unable to attach!")); + FREE(&new); } } menu->redraw |= REDRAW_FULL; diff --git a/curs_lib.c b/curs_lib.c index 2810cfb27..08fbdecd8 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -43,8 +43,10 @@ #include #include "lib/lib.h" #include "mutt.h" +#include "context.h" #include "enter_state.h" #include "globals.h" +#include "header.h" #include "mbyte.h" #include "mutt_curses.h" #include "mutt_menu.h" @@ -1461,3 +1463,32 @@ int mutt_strwidth(const char *s) } return w; } + +/** + * message_is_visible - Is a message in the index within limit + * @param ctx Open mailbox + * @param index Message ID (index into `ctx->hdrs[]` + * @retval bool True if the message is within limit + * + * If no limit is in effect, all the messages are visible. + */ +bool message_is_visible(struct Context *ctx, int index) +{ + if (!ctx || !ctx->hdrs || (index >= ctx->msgcount)) + return false; + + return !ctx->pattern || ctx->hdrs[index]->limited; +} + +/** + * message_is_tagged - Is a message in the index tagged (and within limit) + * @param ctx Open mailbox + * @param index Message ID (index into `ctx->hdrs[]` + * @retval bool True if the message is both tagged and within limit + * + * If a limit is in effect, the message must be visible within it. + */ +bool message_is_tagged(struct Context *ctx, int index) +{ + return message_is_visible(ctx, index) && ctx->hdrs[index]->tagged; +} diff --git a/curs_main.c b/curs_main.c index eb34ffb0e..7c4d7db86 100644 --- a/curs_main.c +++ b/curs_main.c @@ -1631,8 +1631,9 @@ int mutt_index_menu(void) CHECK_VISIBLE; if (tag && !option(OPT_AUTO_TAG)) { - for (j = 0; j < Context->vcount; j++) - mutt_set_flag(Context, Context->hdrs[Context->v2r[j]], MUTT_TAG, 0); + for (j = 0; j < Context->msgcount; j++) + if (message_is_visible(Context, j)) + mutt_set_flag(Context, Context->hdrs[j], MUTT_TAG, 0); menu->redraw |= REDRAW_STATUS | REDRAW_INDEX; } else @@ -1791,11 +1792,11 @@ int mutt_index_menu(void) CHECK_VISIBLE; if (tag) { - for (j = 0; j < Context->vcount; j++) + for (j = 0; j < Context->msgcount; j++) { - if (Context->hdrs[Context->v2r[j]]->tagged) + if (message_is_tagged(Context, j)) { - Context->hdrs[Context->v2r[j]]->quasi_deleted = true; + Context->hdrs[j]->quasi_deleted = true; Context->changed = true; } } @@ -1887,24 +1888,23 @@ int mutt_index_menu(void) if (Context->magic == MUTT_NOTMUCH) nm_longrun_init(Context, true); #endif - for (px = 0, j = 0; j < Context->vcount; j++) + for (px = 0, j = 0; j < Context->msgcount; j++) { - if (Context->hdrs[Context->v2r[j]]->tagged) + if (!message_is_tagged(Context, j)) + continue; + + if (!Context->quiet) + mutt_progress_update(&progress, ++px, -1); + mx_tags_commit(Context, Context->hdrs[j], buf); + if (op == OP_MAIN_MODIFY_TAGS_THEN_HIDE) { - if (!Context->quiet) - mutt_progress_update(&progress, ++px, -1); - mx_tags_commit(Context, Context->hdrs[Context->v2r[j]], buf); - if (op == OP_MAIN_MODIFY_TAGS_THEN_HIDE) - { - bool still_queried = false; + bool still_queried = false; #ifdef USE_NOTMUCH - if (Context->magic == MUTT_NOTMUCH) - still_queried = nm_message_is_still_queried( - Context, Context->hdrs[Context->v2r[j]]); + if (Context->magic == MUTT_NOTMUCH) + still_queried = nm_message_is_still_queried(Context, Context->hdrs[j]); #endif - Context->hdrs[Context->v2r[j]]->quasi_deleted = !still_queried; - Context->changed = true; - } + Context->hdrs[j]->quasi_deleted = !still_queried; + Context->changed = true; } } #ifdef USE_NOTMUCH @@ -2527,11 +2527,11 @@ int mutt_index_menu(void) if (tag) { - for (j = 0; j < Context->vcount; j++) + for (j = 0; j < Context->msgcount; j++) { - if (Context->hdrs[Context->v2r[j]]->tagged) - mutt_set_flag(Context, Context->hdrs[Context->v2r[j]], MUTT_FLAG, - !Context->hdrs[Context->v2r[j]]->flagged); + if (message_is_tagged(Context, j)) + mutt_set_flag(Context, Context->hdrs[j], MUTT_FLAG, + !Context->hdrs[j]->flagged); } menu->redraw |= REDRAW_INDEX; @@ -2566,16 +2566,15 @@ int mutt_index_menu(void) if (tag) { - for (j = 0; j < Context->vcount; j++) + for (j = 0; j < Context->msgcount; j++) { - if (Context->hdrs[Context->v2r[j]]->tagged) - { - if (Context->hdrs[Context->v2r[j]]->read || - Context->hdrs[Context->v2r[j]]->old) - mutt_set_flag(Context, Context->hdrs[Context->v2r[j]], MUTT_NEW, 1); - else - mutt_set_flag(Context, Context->hdrs[Context->v2r[j]], MUTT_READ, 1); - } + if (!message_is_tagged(Context, j)) + continue; + + if (Context->hdrs[j]->read || Context->hdrs[j]->old) + mutt_set_flag(Context, Context->hdrs[j], MUTT_NEW, 1); + else + mutt_set_flag(Context, Context->hdrs[j], MUTT_READ, 1); } menu->redraw |= REDRAW_STATUS | REDRAW_INDEX; } @@ -3107,10 +3106,10 @@ int mutt_index_menu(void) if (tag) { - for (j = 0; j < Context->vcount; j++) + for (j = 0; j < Context->msgcount; j++) { - if (Context->hdrs[Context->v2r[j]]->tagged) - mutt_resend_message(NULL, Context, Context->hdrs[Context->v2r[j]]); + if (message_is_tagged(Context, j)) + mutt_resend_message(NULL, Context, Context->hdrs[j]); } } else diff --git a/editmsg.c b/editmsg.c index 33de5a5d7..456536820 100644 --- a/editmsg.c +++ b/editmsg.c @@ -226,14 +226,13 @@ int mutt_edit_message(struct Context *ctx, struct Header *hdr) if (hdr) return edit_one_message(ctx, hdr); - for (int i = 0; i < ctx->vcount; i++) + for (int i = 0; i < ctx->msgcount; i++) { - int j = ctx->v2r[i]; - if (ctx->hdrs[j]->tagged) - { - if (edit_one_message(ctx, ctx->hdrs[j]) == -1) - return -1; - } + if (!message_is_tagged(ctx, i)) + continue; + + if (edit_one_message(ctx, ctx->hdrs[i]) == -1) + return -1; } return 0; diff --git a/flags.c b/flags.c index ef8c18d2c..1419b3553 100644 --- a/flags.c +++ b/flags.c @@ -334,9 +334,9 @@ void _mutt_set_flag(struct Context *ctx, struct Header *h, int flag, int bf, int */ void mutt_tag_set_flag(int flag, int bf) { - for (int i = 0; i < Context->vcount; i++) - if (Context->hdrs[Context->v2r[i]]->tagged) - mutt_set_flag(Context, Context->hdrs[Context->v2r[i]], flag, bf); + for (int i = 0; i < Context->msgcount; i++) + if (message_is_tagged(Context, i)) + mutt_set_flag(Context, Context->hdrs[i], flag, bf); } int mutt_thread_set_flag(struct Header *hdr, int flag, int bf, int subthread) diff --git a/headers.c b/headers.c index 2418c3cd2..05c4fe999 100644 --- a/headers.c +++ b/headers.c @@ -313,16 +313,18 @@ int mutt_label_message(struct Header *hdr) } else { -#define HDR_OF(index) Context->hdrs[Context->v2r[(index)]] - for (int i = 0; i < Context->vcount; ++i) + for (int i = 0; i < Context->msgcount; ++i) { - if (HDR_OF(i)->tagged) - if (label_message(Context, HDR_OF(i), new)) - { - changed++; - mutt_set_flag(Context, HDR_OF(i), MUTT_TAG, 0); - /* mutt_set_flag re-evals the header color */ - } + if (!message_is_tagged(Context, i)) + continue; + + struct Header *h = Context->hdrs[i]; + if (label_message(Context, h, new)) + { + changed++; + mutt_set_flag(Context, h, MUTT_TAG, 0); + /* mutt_set_flag re-evals the header color */ + } } } diff --git a/imap/message.c b/imap/message.c index 1b35fa8f9..2c6530be3 100644 --- a/imap/message.c +++ b/imap/message.c @@ -1275,14 +1275,17 @@ int imap_copy_messages(struct Context *ctx, struct Header *h, char *dest, int de * remainder. */ for (int i = 0; i < ctx->msgcount; i++) { - if (ctx->hdrs[i]->tagged && ctx->hdrs[i]->attach_del) + if (!message_is_tagged(ctx, i)) + continue; + + if (ctx->hdrs[i]->attach_del) { mutt_debug(3, "imap_copy_messages: Message contains attachments to " "be deleted\n"); return 1; } - if (ctx->hdrs[i]->tagged && ctx->hdrs[i]->active && ctx->hdrs[i]->changed) + if (ctx->hdrs[i]->active && ctx->hdrs[i]->changed) { rc = imap_sync_message_for_copy(idata, ctx->hdrs[i], &sync_cmd, &err_continue); if (rc < 0) @@ -1368,13 +1371,13 @@ int imap_copy_messages(struct Context *ctx, struct Header *h, char *dest, int de { for (int i = 0; i < ctx->msgcount; i++) { - if (ctx->hdrs[i]->tagged) - { - mutt_set_flag(ctx, ctx->hdrs[i], MUTT_DELETE, 1); - mutt_set_flag(ctx, ctx->hdrs[i], MUTT_PURGE, 1); - if (option(OPT_DELETE_UNTAG)) - mutt_set_flag(ctx, ctx->hdrs[i], MUTT_TAG, 0); - } + if (!message_is_tagged(ctx, i)) + continue; + + mutt_set_flag(ctx, ctx->hdrs[i], MUTT_DELETE, 1); + mutt_set_flag(ctx, ctx->hdrs[i], MUTT_PURGE, 1); + if (option(OPT_DELETE_UNTAG)) + mutt_set_flag(ctx, ctx->hdrs[i], MUTT_TAG, 0); } } else diff --git a/ncrypt/crypt.c b/ncrypt/crypt.c index 9ac94c4d0..63df292f0 100644 --- a/ncrypt/crypt.c +++ b/ncrypt/crypt.c @@ -708,55 +708,53 @@ void crypt_extract_keys_from_messages(struct Header *h) if (!h) { - for (int i = 0; i < Context->vcount; i++) + for (int i = 0; i < Context->msgcount; i++) { - if (Context->hdrs[Context->v2r[i]]->tagged) + if (!message_is_tagged(Context, i)) + continue; + + struct Header *h = Context->hdrs[i]; + + mutt_parse_mime_message(Context, h); + if (h->security & ENCRYPT && !crypt_valid_passphrase(h->security)) { - mutt_parse_mime_message(Context, Context->hdrs[Context->v2r[i]]); - if (Context->hdrs[Context->v2r[i]]->security & ENCRYPT && - !crypt_valid_passphrase(Context->hdrs[Context->v2r[i]]->security)) - { - safe_fclose(&fpout); - break; - } + safe_fclose(&fpout); + break; + } - if ((WithCrypto & APPLICATION_PGP) && - (Context->hdrs[Context->v2r[i]]->security & APPLICATION_PGP)) - { - mutt_copy_message(fpout, Context, Context->hdrs[Context->v2r[i]], - MUTT_CM_DECODE | MUTT_CM_CHARCONV, 0); - fflush(fpout); + if ((WithCrypto & APPLICATION_PGP) && (h->security & APPLICATION_PGP)) + { + mutt_copy_message(fpout, Context, h, MUTT_CM_DECODE | MUTT_CM_CHARCONV, 0); + fflush(fpout); - mutt_endwin(_("Trying to extract PGP keys...\n")); - crypt_pgp_invoke_import(tempfname); - } + mutt_endwin(_("Trying to extract PGP keys...\n")); + crypt_pgp_invoke_import(tempfname); + } - if ((WithCrypto & APPLICATION_SMIME) && - (Context->hdrs[Context->v2r[i]]->security & APPLICATION_SMIME)) + if ((WithCrypto & APPLICATION_SMIME) && (h->security & APPLICATION_SMIME)) + { + if (h->security & ENCRYPT) + mutt_copy_message(fpout, Context, h, + MUTT_CM_NOHEADER | MUTT_CM_DECODE_CRYPT | MUTT_CM_DECODE_SMIME, + 0); + else + mutt_copy_message(fpout, Context, h, 0, 0); + fflush(fpout); + + if (h->env->from) + tmp = mutt_expand_aliases(h->env->from); + else if (h->env->sender) + tmp = mutt_expand_aliases(h->env->sender); + mbox = tmp ? tmp->mailbox : NULL; + if (mbox) { - if (Context->hdrs[Context->v2r[i]]->security & ENCRYPT) - mutt_copy_message(fpout, Context, Context->hdrs[Context->v2r[i]], - MUTT_CM_NOHEADER | MUTT_CM_DECODE_CRYPT | MUTT_CM_DECODE_SMIME, - 0); - else - mutt_copy_message(fpout, Context, Context->hdrs[Context->v2r[i]], 0, 0); - fflush(fpout); - - if (Context->hdrs[Context->v2r[i]]->env->from) - tmp = mutt_expand_aliases(Context->hdrs[Context->v2r[i]]->env->from); - else if (Context->hdrs[Context->v2r[i]]->env->sender) - tmp = mutt_expand_aliases(Context->hdrs[Context->v2r[i]]->env->sender); - mbox = tmp ? tmp->mailbox : NULL; - if (mbox) - { - mutt_endwin(_("Trying to extract S/MIME certificates...\n")); - crypt_smime_invoke_import(tempfname, mbox); - tmp = NULL; - } + mutt_endwin(_("Trying to extract S/MIME certificates...\n")); + crypt_smime_invoke_import(tempfname, mbox); + tmp = NULL; } - - rewind(fpout); } + + rewind(fpout); } } else diff --git a/protos.h b/protos.h index 1a048d374..2d52c1ab1 100644 --- a/protos.h +++ b/protos.h @@ -397,4 +397,7 @@ int ci_send_message(int flags, struct Header *msg, char *tempfile, struct Contex int wcscasecmp(const wchar_t *a, const wchar_t *b); #endif +bool message_is_tagged(struct Context *ctx, int index); +bool message_is_visible(struct Context *ctx, int index); + #endif /* _MUTT_PROTOS_H */ diff --git a/send.c b/send.c index 41bd0ec00..cd1caf2e3 100644 --- a/send.c +++ b/send.c @@ -739,12 +739,10 @@ static void make_reference_headers(struct Envelope *curenv, if (!curenv) { - struct Header *h = NULL; - for (int i = 0; i < ctx->vcount; i++) + for (int i = 0; i < ctx->msgcount; i++) { - h = ctx->hdrs[ctx->v2r[i]]; - if (h->tagged) - mutt_add_to_reference_headers(env, h->env); + if (message_is_tagged(ctx, i)) + mutt_add_to_reference_headers(env, ctx->hdrs[i]->env); } } else @@ -767,13 +765,15 @@ static int envelope_defaults(struct Envelope *env, struct Context *ctx, if (!cur) { tag = true; - for (int i = 0; i < ctx->vcount; i++) - if (ctx->hdrs[ctx->v2r[i]]->tagged) - { - cur = ctx->hdrs[ctx->v2r[i]]; - curenv = cur->env; - break; - } + for (int i = 0; i < ctx->msgcount; i++) + { + if (!message_is_tagged(ctx, i)) + continue; + + cur = ctx->hdrs[i]; + curenv = cur->env; + break; + } if (!cur) { @@ -803,12 +803,12 @@ static int envelope_defaults(struct Envelope *env, struct Context *ctx, #endif if (tag) { - struct Header *h = NULL; - - for (int i = 0; i < ctx->vcount; i++) + for (int i = 0; i < ctx->msgcount; i++) { - h = ctx->hdrs[ctx->v2r[i]]; - if (h->tagged && mutt_fetch_recips(env, h->env, flags) == -1) + if (!message_is_tagged(ctx, i)) + continue; + + if (mutt_fetch_recips(env, ctx->hdrs[i]->env, flags) == -1) return -1; } } @@ -848,7 +848,6 @@ static int generate_body(FILE *tempfp, struct Header *msg, int flags, struct Context *ctx, struct Header *cur) { int i; - struct Header *h = NULL; struct Body *tmp = NULL; if (flags & SENDREPLY) @@ -862,18 +861,17 @@ static int generate_body(FILE *tempfp, struct Header *msg, int flags, mutt_message(_("Including quoted message...")); if (!cur) { - for (i = 0; i < ctx->vcount; i++) + for (i = 0; i < ctx->msgcount; i++) { - h = ctx->hdrs[ctx->v2r[i]]; - if (h->tagged) + if (!message_is_tagged(ctx, i)) + continue; + + if (include_reply(ctx, ctx->hdrs[i], tempfp) == -1) { - if (include_reply(ctx, h, tempfp) == -1) - { - mutt_error(_("Could not include all requested messages!")); - return -1; - } - fputc('\n', tempfp); + mutt_error(_("Could not include all requested messages!")); + return -1; } + fputc('\n', tempfp); } } else @@ -902,19 +900,19 @@ static int generate_body(FILE *tempfp, struct Header *msg, int flags, } else { - for (i = 0; i < ctx->vcount; i++) + for (i = 0; i < ctx->msgcount; i++) { - if (ctx->hdrs[ctx->v2r[i]]->tagged) + if (!message_is_tagged(ctx, i)) + continue; + + tmp = mutt_make_message_attach(ctx, ctx->hdrs[i], 0); + if (last) { - tmp = mutt_make_message_attach(ctx, ctx->hdrs[ctx->v2r[i]], 0); - if (last) - { - last->next = tmp; - last = tmp; - } - else - last = msg->content = tmp; + last->next = tmp; + last = tmp; } + else + last = msg->content = tmp; } } } @@ -923,9 +921,13 @@ static int generate_body(FILE *tempfp, struct Header *msg, int flags, if (cur) include_forward(ctx, cur, tempfp); else - for (i = 0; i < ctx->vcount; i++) - if (ctx->hdrs[ctx->v2r[i]]->tagged) - include_forward(ctx, ctx->hdrs[ctx->v2r[i]], tempfp); + { + for (i = 0; i < ctx->msgcount; i++) + { + if (message_is_tagged(ctx, i)) + include_forward(ctx, ctx->hdrs[i], tempfp); + } + } } else if (i == -1) return -1; @@ -1201,11 +1203,10 @@ int mutt_compose_to_sender(struct Header *hdr) msg->env = mutt_new_envelope(); if (!hdr) { - for (int i = 0; i < Context->vcount; i++) + for (int i = 0; i < Context->msgcount; i++) { - hdr = Context->hdrs[Context->v2r[(i)]]; - if (hdr->tagged) - rfc822_append(&msg->env->to, hdr->env->from, 0); + if (message_is_tagged(Context, i)) + rfc822_append(&msg->env->to, Context->hdrs[i]->env->from, 0); } } else @@ -2192,10 +2193,13 @@ int ci_send_message(int flags, struct Header *msg, char *tempfile, mutt_set_flag(ctx, cur, MUTT_REPLIED, is_reply(cur, msg)); else if (!(flags & SENDPOSTPONED) && ctx && ctx->tagged) { - for (i = 0; i < ctx->vcount; i++) - if (ctx->hdrs[ctx->v2r[i]]->tagged) - mutt_set_flag(ctx, ctx->hdrs[ctx->v2r[i]], MUTT_REPLIED, - is_reply(ctx->hdrs[ctx->v2r[i]], msg)); + for (i = 0; i < ctx->msgcount; i++) + { + if (message_is_tagged(ctx, i)) + { + mutt_set_flag(ctx, ctx->hdrs[i], MUTT_REPLIED, is_reply(ctx->hdrs[i], msg)); + } + } } } diff --git a/sendlib.c b/sendlib.c index ab0d8c116..36fd6fbe8 100644 --- a/sendlib.c +++ b/sendlib.c @@ -2759,7 +2759,7 @@ static int _mutt_bounce_message(FILE *fp, struct Header *h, struct Address *to, { /* Try to bounce each message out, aborting if we get any failures. */ for (int i = 0; i < Context->msgcount; i++) - if (Context->hdrs[i]->tagged) + if (message_is_tagged(Context, i)) ret |= _mutt_bounce_message(fp, Context->hdrs[i], to, resent_from, env_from); return ret; } diff --git a/thread.c b/thread.c index ac41fc673..97e67b3b7 100644 --- a/thread.c +++ b/thread.c @@ -1472,9 +1472,9 @@ int mutt_link_threads(struct Header *cur, struct Header *last, struct Context *c if (!last) { - for (int i = 0; i < ctx->vcount; i++) - if (ctx->hdrs[Context->v2r[i]]->tagged) - changed |= link_threads(cur, ctx->hdrs[Context->v2r[i]], ctx); + for (int i = 0; i < ctx->msgcount; i++) + if (message_is_tagged(ctx, i)) + changed |= link_threads(cur, ctx->hdrs[i], ctx); } else changed = link_threads(cur, last, ctx); -- 2.40.0