<<< Date Index >>>     <<< Thread Index >>>

For 1.5.10: [PATCH] Introduce collapse_flagged



Hello TLR,
this patch introduces the variable collapse_flagged which defaults to
the old behaviour and makes it possible to tell mutt to don't collapse
threads which have a flagged message in when using collapse-all. I use
this patch quiet a while and am unaware of any pending bugs. - So I
consider it ready for upstream.

Greetings,
        Thomas
Index: curs_main.c
===================================================================
--- 9723d742df0391c60be9467f85e6c3f12afd585c/curs_main.c  (mode:100644 
sha1:ff55f1869b953acb2ec816569470e4adb3421c1d)
+++ 48b16fbb949f850bada8ad8d912bd10d45cc94de/curs_main.c  (mode:100644 
sha1:b5c5275ead8882ed37205b92b2bc88f7799c2ac8)
@@ -103,6 +103,11 @@
 #define CURHDR Context->hdrs[Context->v2r[menu->current]]
 #define OLDHDR Context->hdrs[Context->v2r[menu->oldcurrent]]
 #define UNREAD(h) mutt_thread_contains_unread (Context, h)
+#define FLAGGED(h) mutt_thread_contains_flagged (Context, h)
+
+#define CHECK_IF_TO_COLLAPSE(header) \
+  ((option (OPTCOLLAPSEUNREAD)  || !UNREAD (header)) && \
+   (option (OPTCOLLAPSEFLAGGED) || FLAGGED(header) == 0))
 
 extern const char *ReleaseDate;
 extern size_t UngetCount;
@@ -1614,14 +1619,14 @@
          if (option (OPTUNCOLLAPSEJUMP))
            menu->current = mutt_thread_next_unread (Context, CURHDR);
        }
-       else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
+        else if CHECK_IF_TO_COLLAPSE(CURHDR)
        {
          menu->current = mutt_collapse_thread (Context, CURHDR);
          mutt_set_virtual (Context);
        }
        else
        {
-         mutt_error _("Thread contains unread messages.");
+          mutt_error _("Thread contains unread or flagged messages.");
          break;
        }
 
@@ -1646,8 +1651,10 @@
          
          if (CURHDR->collapsed)
            final = mutt_uncollapse_thread (Context, CURHDR);
-         else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
+          else if CHECK_IF_TO_COLLAPSE(CURHDR)
+          {
            final = mutt_collapse_thread (Context, CURHDR);
+          }
          else
            final = CURHDR->virtual;
          
@@ -1665,9 +1672,11 @@
            {
              if (h->collapsed)
                mutt_uncollapse_thread (Context, h);
-             else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
+              else if CHECK_IF_TO_COLLAPSE(h)
+              {
                mutt_collapse_thread (Context, h);
            }
+            }
            top = top->next;
          }
          
Index: init.h
===================================================================
--- 9723d742df0391c60be9467f85e6c3f12afd585c/init.h  (mode:100644 
sha1:9bb00e4d734c544bc2fed04e75ba20b0854f17e0)
+++ 48b16fbb949f850bada8ad8d912bd10d45cc94de/init.h  (mode:100644 
sha1:0b5d8465ee4c75b869c82bc258a66272bf40e922)
@@ -300,6 +300,12 @@
   ** When \fIunset\fP, Mutt will not collapse a thread if it contains any
   ** unread messages.
   */
+  { "collapse_flagged",        DT_BOOL, R_NONE, OPTCOLLAPSEFLAGGED, 1 },
+  /*
+  ** .pp
+  ** When \fIunset\fP, Mutt will not collapse a thread if it contains any
+  ** flagged messages.
+  */
   { "uncollapse_jump",         DT_BOOL, R_NONE, OPTUNCOLLAPSEJUMP, 0 },
   /*
   ** .pp
Index: mutt.h
===================================================================
--- 9723d742df0391c60be9467f85e6c3f12afd585c/mutt.h  (mode:100644 
sha1:dc92151f77ef686e199671e361c97ec614f19ce9)
+++ 48b16fbb949f850bada8ad8d912bd10d45cc94de/mutt.h  (mode:100644 
sha1:94dfb4f352681f9f2755c454cc25321dc8321b4f)
@@ -181,6 +181,7 @@
 #define M_THREAD_GET_HIDDEN    (1<<2)
 #define M_THREAD_UNREAD                (1<<3)
 #define M_THREAD_NEXT_UNREAD   (1<<4)
+#define M_THREAD_FLAGGED       (1<<5)
 
 enum
 {
@@ -336,6 +337,7 @@
   OPTBOUNCEDELIVERED,
   OPTCHECKNEW,
   OPTCOLLAPSEUNREAD,
+  OPTCOLLAPSEFLAGGED,
   OPTCONFIRMAPPEND,
   OPTCONFIRMCREATE,
   OPTDELETEUNTAG,
Index: protos.h
===================================================================
--- 9723d742df0391c60be9467f85e6c3f12afd585c/protos.h  (mode:100644 
sha1:3cda50538b733826e37cd35734e68755173f080c)
+++ 48b16fbb949f850bada8ad8d912bd10d45cc94de/protos.h  (mode:100644 
sha1:011d63023a7f1d718f90d87a4933c6f50d0fb1de)
@@ -56,6 +56,7 @@
 #define mutt_uncollapse_thread(x,y) _mutt_traverse_thread 
(x,y,M_THREAD_UNCOLLAPSE)
 #define mutt_get_hidden(x,y)_mutt_traverse_thread (x,y,M_THREAD_GET_HIDDEN) 
 #define mutt_thread_contains_unread(x,y) _mutt_traverse_thread 
(x,y,M_THREAD_UNREAD)
+#define mutt_thread_contains_flagged(x,y) _mutt_traverse_thread 
(x,y,M_THREAD_FLAGGED)
 #define mutt_thread_next_unread(x,y) 
_mutt_traverse_thread(x,y,M_THREAD_NEXT_UNREAD)
 int _mutt_traverse_thread (CONTEXT *ctx, HEADER *hdr, int flag);
 
Index: thread.c
===================================================================
--- 9723d742df0391c60be9467f85e6c3f12afd585c/thread.c  (mode:100644 
sha1:286266515f04a41ca137f34c76397e2af134e3a5)
+++ 48b16fbb949f850bada8ad8d912bd10d45cc94de/thread.c  (mode:100644 
sha1:7d6a623999d36c98149d18e1d837c8f9edc5ebe8)
@@ -1123,7 +1123,7 @@
   THREAD *thread, *top;
   HEADER *roothdr = NULL;
   int final, reverse = (Sort & SORT_REVERSE), minmsgno;
-  int num_hidden = 0, new = 0, old = 0;
+  int num_hidden = 0, new = 0, old = 0, flagged = 0;
   int min_unread_msgno = INT_MAX, min_unread = cur->virtual;
 #define CHECK_LIMIT (!ctx->pattern || cur->limited)
 
@@ -1156,6 +1156,11 @@
     }
   }
 
+  if (cur->flagged && CHECK_LIMIT)
+  {
+    flagged = 1;
+  }
+
   if (cur->virtual == -1 && CHECK_LIMIT)
     num_hidden++;
 
@@ -1182,6 +1187,8 @@
       return (num_hidden);
     else if (flag & M_THREAD_NEXT_UNREAD)
       return (min_unread);
+    else if (flag & M_THREAD_FLAGGED)
+      return (flagged);
   }
   
   FOREVER
@@ -1233,6 +1240,11 @@
        }
       }
 
+      if (cur->flagged && CHECK_LIMIT)
+      {
+        flagged = 1;
+      }
+
       if (cur->virtual == -1 && CHECK_LIMIT)
        num_hidden++;
     }
@@ -1268,6 +1280,8 @@
     return (num_hidden+1);
   else if (flag & M_THREAD_NEXT_UNREAD)
     return (min_unread);
+  else if (flag & M_THREAD_FLAGGED)
+    return (flagged);
 
   return (0);
 #undef CHECK_LIMIT