]> granicus.if.org Git - neomutt/commitdiff
fix actions on tagged messages (#823)
authorRichard Russon <rich@flatcap.org>
Tue, 24 Oct 2017 12:27:21 +0000 (13:27 +0100)
committerGitHub <noreply@github.com>
Tue, 24 Oct 2017 12:27:21 +0000 (13:27 +0100)
Many actions aren't performed on all tagged messages if the messages are
within a collapsed thread.

13 files changed:
commands.c
compose.c
curs_lib.c
curs_main.c
editmsg.c
flags.c
headers.c
imap/message.c
ncrypt/crypt.c
protos.h
send.c
sendlib.c
thread.c

index ff12b91a69aaf69c4e7faa144e4ef38a83139458..3a1b43d74e3bd499e61d2e682b4c54fe10d72e26 100644 (file)
@@ -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;
 }
index 4ac7c4e5a34c492b25788ec176cd734caaac15f3..b91ab0dc980470af9c582401011a9615b74cb684 100644 (file)
--- 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;
index 2810cfb271f8f8063f194c7ef0d6cc880e7942e0..08fbdecd8703a3e2b59437a46e40b9ccda40817f 100644 (file)
 #include <wchar.h>
 #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;
+}
index eb34ffb0ef7a6d624dd99c015dd6aa24c17e01bb..7c4d7db86f0bb5df584dfc5dda3c709a51ae2bb5 100644 (file)
@@ -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
index 33de5a5d764ffa4dc61342cc1b3e9378ed9804a5..456536820c2595862aeecb4b342f6835235cc0b1 100644 (file)
--- 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 ef8c18d2c69740942edf6ab13ae2c53984df00da..1419b3553089589022b910ba18dca051681d0a3a 100644 (file)
--- 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)
index 2418c3cd2aa6f67df910e24ba19cb7228262d66e..05c4fe9998e0115814269fea2a8f83aab8b5a436 100644 (file)
--- 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 */
+      }
     }
   }
 
index 1b35fa8f9971e1f3e50e2585c23f7e43b9ae8b60..2c6530be3a009e72ff76bdd898af0edb6ce83410 100644 (file)
@@ -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
index 9ac94c4d04b87219313031747c2775fb4b27ee46..63df292f0a5517dffaaa924a4e8519b7496f611f 100644 (file)
@@ -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
index 1a048d37419cbfa2fa58317485005d65cb1ce18d..2d52c1ab10674ff8146d1929575526bc850917a1 100644 (file)
--- 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 41bd0ec0015bbadd38f7d1789f72481359a860a1..cd1caf2e3a7e3d13e491542ed35747c5399b0c36 100644 (file)
--- 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));
+        }
+      }
     }
   }
 
index ab0d8c11696a5a2a1ae732283cd35b5e4ab05491..36fd6fbe88a420dac942b75708765952ba50a0f4 100644 (file)
--- 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;
   }
index ac41fc673e68ee1a73bc13d2ff00cafe2d15a810..97e67b3b758365d61eece3d846f63086f5ad7e02 100644 (file)
--- 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);