]> granicus.if.org Git - neomutt/commitdiff
mutt_change_flag: factor out Context
authorRichard Russon <rich@flatcap.org>
Fri, 11 Jan 2019 11:58:51 +0000 (11:58 +0000)
committerRichard Russon <rich@flatcap.org>
Fri, 8 Feb 2019 14:34:07 +0000 (14:34 +0000)
flags.c
index.c
pager.c
protos.h

diff --git a/flags.c b/flags.c
index a1f65b7033ecca8ab5f3ca1fc51ba4fcb68d31ab..8b62a2e963b2f4ac3577ab40292da4192e721fbf 100644 (file)
--- a/flags.c
+++ b/flags.c
@@ -348,15 +348,22 @@ void mutt_set_flag_update(struct Mailbox *m, struct Email *e, int flag, bool bf,
 }
 
 /**
- * mutt_tag_set_flag - Set flag on tagged messages
+ * mutt_emails_set_flag - Set flag on messages
+ * @param m    Mailbox
+ * @param el   List of Emails to flag
  * @param flag Flag to set, e.g. #MUTT_DELETE
  * @param bf   true: set the flag; false: clear the flag
  */
-void mutt_tag_set_flag(int flag, int bf)
+void mutt_emails_set_flag(struct Mailbox *m, struct EmailList *el, int flag, int bf)
 {
-  for (int i = 0; i < Context->mailbox->msg_count; i++)
-    if (message_is_tagged(Context, i))
-      mutt_set_flag(Context->mailbox, Context->mailbox->emails[i], flag, bf);
+  if (!m || !el || STAILQ_EMPTY(el))
+    return;
+
+  struct EmailNode *en = NULL;
+  STAILQ_FOREACH(en, el, entries)
+  {
+    mutt_set_flag(m, en->email, flag, bf);
+  }
 }
 
 /**
@@ -419,13 +426,17 @@ done:
 
 /**
  * mutt_change_flag - Change the flag on a Message
- * @param e  Email
+ * @param m  Mailbox
+ * @param el List of Emails to change
  * @param bf true: set the flag; false: clear the flag
  * @retval  0 Success
  * @retval -1 Failure
  */
-int mutt_change_flag(struct Email *e, int bf)
+int mutt_change_flag(struct Mailbox *m, struct EmailList *el, int bf)
 {
+  if (!m || !el || STAILQ_EMPTY(el))
+    return -1;
+
   int i, flag;
   struct Event event;
 
@@ -452,12 +463,7 @@ int mutt_change_flag(struct Email *e, int bf)
     case 'd':
     case 'D':
       if (!bf)
-      {
-        if (e)
-          mutt_set_flag(Context->mailbox, e, MUTT_PURGE, bf);
-        else
-          mutt_tag_set_flag(MUTT_PURGE, bf);
-      }
+        mutt_emails_set_flag(m, el, MUTT_PURGE, bf);
       flag = MUTT_DELETE;
       break;
 
@@ -468,10 +474,7 @@ int mutt_change_flag(struct Email *e, int bf)
 
     case 'o':
     case 'O':
-      if (e)
-        mutt_set_flag(Context->mailbox, e, MUTT_READ, !bf);
-      else
-        mutt_tag_set_flag(MUTT_READ, !bf);
+      mutt_emails_set_flag(m, el, MUTT_READ, !bf);
       flag = MUTT_OLD;
       break;
 
@@ -493,10 +496,6 @@ int mutt_change_flag(struct Email *e, int bf)
       return -1;
   }
 
-  if (e)
-    mutt_set_flag(Context->mailbox, e, flag, bf);
-  else
-    mutt_tag_set_flag(flag, bf);
-
+  mutt_emails_set_flag(m, el, flag, bf);
   return 0;
 }
diff --git a/index.c b/index.c
index f7bb36ac1345c6beb416bc3a82e7982c331d2775..c15f765678b234f91c7fa11cd778b532c9a60831 100644 (file)
--- a/index.c
+++ b/index.c
@@ -2855,13 +2855,16 @@ int mutt_index_menu(void)
 
       case OP_MAIN_SET_FLAG:
       case OP_MAIN_CLEAR_FLAG:
-
+      {
         CHECK_MSGCOUNT;
         CHECK_VISIBLE;
         CHECK_READONLY;
         /* CHECK_ACL(MUTT_ACL_WRITE); */
 
-        if (mutt_change_flag(tag ? NULL : CUR_EMAIL, (op == OP_MAIN_SET_FLAG)) == 0)
+        struct EmailList el = STAILQ_HEAD_INITIALIZER(el);
+        el_add_tagged(&el, Context, CUR_EMAIL, tag);
+
+        if (mutt_change_flag(Context->mailbox, &el, (op == OP_MAIN_SET_FLAG)) == 0)
         {
           menu->redraw |= REDRAW_STATUS;
           if (tag)
@@ -2880,7 +2883,9 @@ int mutt_index_menu(void)
           else
             menu->redraw |= REDRAW_CURRENT;
         }
+        el_free(&el);
         break;
+      }
 
       case OP_MAIN_COLLAPSE_THREAD:
         CHECK_MSGCOUNT;
@@ -2956,27 +2961,28 @@ int mutt_index_menu(void)
 
       case OP_PURGE_MESSAGE:
       case OP_DELETE:
-
+      {
         CHECK_MSGCOUNT;
         CHECK_VISIBLE;
         CHECK_READONLY;
         /* L10N: CHECK_ACL */
         CHECK_ACL(MUTT_ACL_DELETE, _("Cannot delete message"));
 
+        struct EmailList el = STAILQ_HEAD_INITIALIZER(el);
+        el_add_tagged(&el, Context, CUR_EMAIL, tag);
+
+        mutt_emails_set_flag(Context->mailbox, &el, MUTT_DELETE, 1);
+        mutt_emails_set_flag(Context->mailbox, &el, MUTT_PURGE, (op == OP_PURGE_MESSAGE));
+        if (DeleteUntag)
+          mutt_emails_set_flag(Context->mailbox, &el, MUTT_TAG, 0);
+        el_free(&el);
+
         if (tag)
         {
-          mutt_tag_set_flag(MUTT_DELETE, 1);
-          mutt_tag_set_flag(MUTT_PURGE, (op == OP_PURGE_MESSAGE));
-          if (DeleteUntag)
-            mutt_tag_set_flag(MUTT_TAG, 0);
           menu->redraw |= REDRAW_INDEX;
         }
         else
         {
-          mutt_set_flag(Context->mailbox, CUR_EMAIL, MUTT_DELETE, 1);
-          mutt_set_flag(Context->mailbox, CUR_EMAIL, MUTT_PURGE, (op == OP_PURGE_MESSAGE));
-          if (DeleteUntag)
-            mutt_set_flag(Context->mailbox, CUR_EMAIL, MUTT_TAG, 0);
           if (Resolve)
           {
             menu->current = ci_next_undeleted(menu->current);
@@ -2998,6 +3004,7 @@ int mutt_index_menu(void)
         }
         menu->redraw |= REDRAW_STATUS;
         break;
+      }
 
       case OP_DELETE_THREAD:
       case OP_DELETE_SUBTHREAD:
@@ -3451,23 +3458,26 @@ int mutt_index_menu(void)
         break;
 
       case OP_UNDELETE:
-
+      {
         CHECK_MSGCOUNT;
         CHECK_VISIBLE;
         CHECK_READONLY;
         /* L10N: CHECK_ACL */
         CHECK_ACL(MUTT_ACL_DELETE, _("Cannot undelete message"));
 
+        struct EmailList el = STAILQ_HEAD_INITIALIZER(el);
+        el_add_tagged(&el, Context, CUR_EMAIL, tag);
+
+        mutt_emails_set_flag(Context->mailbox, &el, MUTT_DELETE, 0);
+        mutt_emails_set_flag(Context->mailbox, &el, MUTT_PURGE, 0);
+        el_free(&el);
+
         if (tag)
         {
-          mutt_tag_set_flag(MUTT_DELETE, 0);
-          mutt_tag_set_flag(MUTT_PURGE, 0);
           menu->redraw |= REDRAW_INDEX;
         }
         else
         {
-          mutt_set_flag(Context->mailbox, CUR_EMAIL, MUTT_DELETE, 0);
-          mutt_set_flag(Context->mailbox, CUR_EMAIL, MUTT_PURGE, 0);
           if (Resolve && menu->current < Context->mailbox->vcount - 1)
           {
             menu->current++;
@@ -3476,8 +3486,10 @@ int mutt_index_menu(void)
           else
             menu->redraw |= REDRAW_CURRENT;
         }
+
         menu->redraw |= REDRAW_STATUS;
         break;
+      }
 
       case OP_UNDELETE_THREAD:
       case OP_UNDELETE_SUBTHREAD:
diff --git a/pager.c b/pager.c
index ed3569b0c2e21ec4cee17cae62e9ea8385c241dc..339676ea92ea8a298b9b0554a15d0a6129f92711 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -3006,17 +3006,23 @@ int mutt_pager(const char *banner, const char *fname, int flags, struct Pager *e
 
       case OP_MAIN_SET_FLAG:
       case OP_MAIN_CLEAR_FLAG:
+      {
         CHECK_MODE(IsEmail(extra));
         CHECK_READONLY;
 
-        if (mutt_change_flag(extra->email, (ch == OP_MAIN_SET_FLAG)) == 0)
+        struct EmailList el = STAILQ_HEAD_INITIALIZER(el);
+        el_add_email(&el, extra->email);
+
+        if (mutt_change_flag(Context->mailbox, &el, (ch == OP_MAIN_SET_FLAG)) == 0)
           pager_menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
         if (extra->email->deleted && Resolve)
         {
           ch = -1;
           rc = OP_MAIN_NEXT_UNDELETED;
         }
+        el_free(&el);
         break;
+      }
 
       case OP_DELETE_THREAD:
       case OP_DELETE_SUBTHREAD:
index b206b4a275799e0ecf6311aae98568197ec1e6d3..88d9361bd5322858bb5a955864fe2b8bb95434a5 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -65,8 +65,8 @@ void mutt_make_help(char *d, size_t dlen, const char *txt, int menu, int op);
 void mutt_set_flag_update(struct Mailbox *m, struct Email *e, int flag, bool bf, bool upd_mbox);
 #define mutt_set_flag(a, b, c, d) mutt_set_flag_update(a, b, c, d, true)
 void mutt_signal_init(void);
-void mutt_tag_set_flag(int flag, int bf);
-int mutt_change_flag(struct Email *e, int bf);
+void mutt_emails_set_flag(struct Mailbox *m, struct EmailList *el, int flag, int bf);
+int mutt_change_flag(struct Mailbox *m, struct EmailList *el, int bf);
 
 int mutt_complete(char *buf, size_t buflen);
 int mutt_prepare_template(FILE *fp, struct Mailbox *m, struct Email *newhdr, struct Email *e, bool resend);