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

[PATCH] add "group-replied" flag



Moin,

recently I've seen a request to have "group-replied" flag next to
"replied". Since I guessed it would be easy to implement, I had a go
for it. My patch works with mbox + maildir, but it fails with imap,
and I didn't dare to mess around with mh. Being totally unfamiliar
with the 2, I welcome any help or pointers on those 2 areas to make
it work.

In the patch you can see where/ how I naively tried to extend the
IMAP code, but it didn't work "just like that", analoguously to mbox
and maildir. Maybe you instantly see how to correct it before I
must + can delve into the depths of IMAP. ;)

-- 
© Rado S. -- You must provide YOUR effort for your goal!
EVERY effort counts: at least to show your attitude.
You're responsible for ALL you do: you get what you give.
diff -ru mutt-1.5.17/copy.c mgo/copy.c
--- mutt-1.5.17/copy.c  Tue Apr 10 19:18:26 2007
+++ mgo/copy.c  Wed Nov 14 22:43:47 2007
@@ -433,10 +433,16 @@
          return (-1);
       }
 
-      if (h->flagged || h->replied)
+      if (h->flagged || h->grouped || h->replied)
       {
        if (fputs ("X-Status: ", out) == EOF)
          return (-1);
+
+       if (h->grouped)
+       {
+         if (fputc ('G', out) == EOF)
+           return (-1);
+       }
 
        if (h->replied)
        {
diff -ru mutt-1.5.17/doc/manual.xml.head mgo/doc/manual.xml.head
--- mutt-1.5.17/doc/manual.xml.head     Thu Nov  1 20:02:58 2007
+++ mgo/doc/manual.xml.head     Sun Nov 18 13:08:21 2007
@@ -460,6 +460,14 @@
 </listitem>
 </varlistentry>
 <varlistentry>
+<term>g</term>
+<listitem>
+<para>
+message has been group-replied to
+</para>
+</listitem>
+</varlistentry>
+<varlistentry>
 <term>r</term>
 <listitem>
 <para>
@@ -3825,6 +3833,7 @@
 <row><entry>~O</entry><entry>old messages</entry></row>
 <row><entry>~p</entry><entry>message is addressed to you (consults 
alternates)</entry></row>
 <row><entry>~P</entry><entry>message is from you (consults 
alternates)</entry></row>
+<row><entry>~q</entry><entry>messages which have been group-replied 
to</entry></row>
 <row><entry>~Q</entry><entry>messages which have been replied to</entry></row>
 <row><entry>~r &lsqb;MIN&rsqb;-&lsqb;MAX&rsqb;</entry><entry>messages with 
``date-received'' in a Date range</entry></row>
 <row><entry>~R</entry><entry>read messages</entry></row>
diff -ru mutt-1.5.17/flags.c mgo/flags.c
--- mutt-1.5.17/flags.c Fri Apr 13 20:40:07 2007
+++ mgo/flags.c Sat Nov 17 17:47:11 2007
@@ -182,6 +182,37 @@
       }
       break;
 
+    case M_GROUPED:
+
+      if (!mutt_bit_isset(ctx->rights,M_ACL_WRITE))
+       return;
+
+      if (bf)
+      {
+       if (!h->grouped)
+       {
+          update = 1;
+         h->grouped = 1;
+         if (!h->read)
+         {
+           h->read = 1;
+           if (upd_ctx) ctx->unread--;
+           if (!h->old)
+             if (upd_ctx) ctx->new--;
+         }
+         h->changed = 1;
+         if (upd_ctx) ctx->changed = 1;
+       }
+      }
+      else if (h->grouped)
+      {
+        update = 1;
+       h->grouped = 0;
+       h->changed = 1;
+       if (upd_ctx) ctx->changed = 1;
+      }
+      break;
+
     case M_REPLIED:
 
       if (!mutt_bit_isset(ctx->rights,M_ACL_WRITE))
@@ -326,7 +357,7 @@
   int i, flag;
   event_t event;
 
-  mvprintw (LINES - 1, 0, "%s? (D/N/O/r/*/!): ", bf ? _("Set flag") : _("Clear 
flag"));
+  mvprintw (LINES - 1, 0, "%s? (D/N/O/g/r/*/!): ", bf ? _("Set flag") : 
_("Clear flag"));
   clrtoeol ();
 
   event = mutt_getch();
@@ -358,6 +389,11 @@
       else
        mutt_tag_set_flag (M_READ, !bf);
       flag = M_OLD;
+      break;
+
+    case 'g':
+    case 'G':
+      flag = M_GROUPED;
       break;
 
     case 'r':
diff -ru mutt-1.5.17/hdrline.c mgo/hdrline.c
--- mutt-1.5.17/hdrline.c       Wed Oct 31 18:48:52 2007
+++ mgo/hdrline.c       Wed Nov 14 22:38:56 2007
@@ -572,6 +572,8 @@
        ch = '*';
       else if (hdr->flagged)
        ch = '!';
+      else if (hdr->grouped)
+       ch = 'g';
       else if (hdr->replied)
        ch = 'r';
       else if (hdr->read && (ctx && ctx->msgnotreadyet != hdr->msgno))
@@ -651,7 +653,7 @@
       snprintf (buf2, sizeof (buf2),
                "%c%c%c", (THREAD_NEW ? 'n' : (THREAD_OLD ? 'o' : 
                ((hdr->read && (ctx && ctx->msgnotreadyet != hdr->msgno))
-               ? (hdr->replied ? 'r' : ' ') : (hdr->old ? 'O' : 'N')))),
+               ? (hdr->grouped ? 'g' : (hdr->replied ? 'r' : ' ')) : (hdr->old 
? 'O' : 'N')))),
                hdr->deleted ? 'D' : (hdr->attach_del ? 'd' : ch),
                hdr->tagged ? '*' :
                (hdr->flagged ? '!' :
diff -ru mutt-1.5.17/imap/imap.c mgo/imap/imap.c
--- mutt-1.5.17/imap/imap.c     Wed Oct 31 21:56:52 2007
+++ mgo/imap/imap.c     Sun Nov 18 12:50:57 2007
@@ -913,6 +913,10 @@
           if (hdrs[n]->read != HEADER_DATA(hdrs[n])->read)
             match = invert ^ hdrs[n]->read;
          break;
+        case M_GROUPED:
+          if (hdrs[n]->grouped != HEADER_DATA(hdrs[n])->grouped)
+            match = invert ^ hdrs[n]->grouped;
+         break;
         case M_REPLIED:
           if (hdrs[n]->replied != HEADER_DATA(hdrs[n])->replied)
             match = invert ^ hdrs[n]->replied;
@@ -968,6 +972,8 @@
     return 1;
   if (h->flagged != hd->flagged)
     return 1;
+  if (h->grouped != hd->grouped)
+    return 1;
   if (h->replied != hd->replied)
     return 1;
   if (h->deleted != hd->deleted)
@@ -1005,6 +1011,8 @@
                  "Old ", flags, sizeof (flags));
   imap_set_flag (idata, M_ACL_WRITE, hdr->flagged,
                 "\\Flagged ", flags, sizeof (flags));
+  imap_set_flag (idata, M_ACL_WRITE, hdr->grouped,
+                "Grouped ", flags, sizeof (flags));
   imap_set_flag (idata, M_ACL_WRITE, hdr->replied,
                 "\\Answered ", flags, sizeof (flags));
   imap_set_flag (idata, M_ACL_DELETE, hdr->deleted,
@@ -1024,6 +1032,7 @@
     imap_set_flag (idata, M_ACL_WRITE, 1, "Old ", flags, sizeof (flags));
     imap_set_flag (idata, M_ACL_WRITE, 1, "\\Flagged ", flags, sizeof (flags));
     imap_set_flag (idata, M_ACL_WRITE, 1, "\\Answered ", flags, sizeof 
(flags));
+    imap_set_flag (idata, M_ACL_WRITE, 1, "Grouped ", flags, sizeof (flags));
     imap_set_flag (idata, M_ACL_DELETE, 1, "\\Deleted ", flags, sizeof 
(flags));
 
     mutt_remove_trailing_ws (flags);
@@ -1210,6 +1219,7 @@
   rc += sync_helper (idata, &cmd, M_ACL_WRITE, M_FLAG, "\\Flagged");
   rc += sync_helper (idata, &cmd, M_ACL_WRITE, M_OLD, "Old");
   rc += sync_helper (idata, &cmd, M_ACL_SEEN, M_READ, "\\Seen");
+  rc += sync_helper (idata, &cmd, M_ACL_WRITE, M_GROUPED, "Grouped");
   rc += sync_helper (idata, &cmd, M_ACL_WRITE, M_REPLIED, "\\Answered");
 
   if (oldsort != Sort)
diff -ru mutt-1.5.17/imap/message.c mgo/imap/message.c
--- mutt-1.5.17/imap/message.c  Thu Apr 12 22:44:40 2007
+++ mgo/imap/message.c  Sun Nov 18 13:24:42 2007
@@ -185,6 +185,7 @@
           ctx->hdrs[idx]->old = h.data->old;
           ctx->hdrs[idx]->deleted = h.data->deleted;
           ctx->hdrs[idx]->flagged = h.data->flagged;
+          ctx->hdrs[idx]->grouped = h.data->grouped;
           ctx->hdrs[idx]->replied = h.data->replied;
           ctx->hdrs[idx]->changed = h.data->changed;
           /*  ctx->hdrs[msgno]->received is restored from mutt_hcache_restore 
*/
@@ -272,6 +273,7 @@
       ctx->hdrs[idx]->old = h.data->old;
       ctx->hdrs[idx]->deleted = h.data->deleted;
       ctx->hdrs[idx]->flagged = h.data->flagged;
+      ctx->hdrs[idx]->grouped = h.data->grouped;
       ctx->hdrs[idx]->replied = h.data->replied;
       ctx->hdrs[idx]->changed = h.data->changed;
       ctx->hdrs[idx]->received = h.received;
@@ -560,7 +562,8 @@
   FILE *fp;
   char buf[LONG_STRING];
   char mbox[LONG_STRING];
-  char mailbox[LONG_STRING]; 
+  char mailbox[LONG_STRING];
+  char *joinstatus;
   size_t len;
   progress_t progressbar;
   size_t sent;
@@ -600,12 +603,20 @@
                      M_PROGRESS_SIZE, NetInc, len);
 
   imap_munge_mbox_name (mbox, sizeof (mbox), mailbox);
-  snprintf (buf, sizeof (buf), "APPEND %s (%s%s%s%s%s) {%lu}", mbox,
-           msg->flags.read    ? "\\Seen"      : "",
-           msg->flags.read && (msg->flags.replied || msg->flags.flagged) ? " " 
: "",
-           msg->flags.replied ? "\\Answered" : "",
-           msg->flags.replied && msg->flags.flagged ? " " : "",
-           msg->flags.flagged ? "\\Flagged"  : "",
+
+  snprintf (mailbox, sizeof (mailbox), "%s%s%s%s",
+           msg->flags.read    ? "\\Seen "    : "",
+           msg->flags.flagged ? "\\Flagged "  : "",
+           msg->flags.grouped ? "Grouped "  : "",
+           msg->flags.replied ? "\\Answered " : "");
+
+  joinstatus = mailbox;
+       if (*joinstatus) {
+               while (*joinstatus) { joinstatus++; }
+               if (*(joinstatus-1)==' ') { *(joinstatus-1)=0; }
+       }
+
+  snprintf (buf, sizeof (buf), "APPEND %s (%s) {%lu}", mbox, mailbox,
            (unsigned long) len);
 
   imap_cmd_start (idata, buf);
@@ -996,6 +1007,7 @@
   mutt_set_flag (ctx, h, M_READ, hd->read);
   mutt_set_flag (ctx, h, M_DELETE, hd->deleted);
   mutt_set_flag (ctx, h, M_FLAG, hd->flagged);
+  mutt_set_flag (ctx, h, M_GROUPED, hd->grouped);
   mutt_set_flag (ctx, h, M_REPLIED, hd->replied);
 
   /* this message is now definitively *not* changed (mutt_set_flag
@@ -1165,7 +1177,7 @@
   s++;
 
   mutt_free_list (&hd->keywords);
-  hd->deleted = hd->flagged = hd->replied = hd->read = hd->old = 0;
+  hd->deleted = hd->flagged = hd->grouped = hd->replied = hd->read = hd->old = 
0;
 
   /* start parsing */
   while (*s && *s != ')')
@@ -1179,6 +1191,11 @@
     {
       s += 8;
       hd->flagged = 1;
+    }
+    else if (ascii_strncasecmp ("grouped", s, 7) == 0)
+    {
+      s += 7;
+      hd->grouped = 1;
     }
     else if (ascii_strncasecmp ("\\answered", s, 9) == 0)
     {
diff -ru mutt-1.5.17/imap/message.h mgo/imap/message.h
--- mutt-1.5.17/imap/message.h  Fri Mar  2 19:44:44 2007
+++ mgo/imap/message.h  Wed Nov 14 21:01:16 2007
@@ -31,6 +31,7 @@
   unsigned int old : 1;
   unsigned int deleted : 1;
   unsigned int flagged : 1;
+  unsigned int grouped : 1;
   unsigned int replied : 1;
   unsigned int changed : 1;
 
diff -ru mutt-1.5.17/init.c mgo/init.c
--- mutt-1.5.17/init.c  Mon Sep 17 23:24:22 2007
+++ mgo/init.c  Sun Nov  4 14:21:01 2007
@@ -2889,6 +2889,8 @@
     Shell = safe_strdup ((p = getenv ("SHELL")) ? p : "/bin/sh");
   }
 
+  Tempdir = safe_strdup ((p = getenv ("TMPDIR")) ? p : "/tmp");
+
 #ifdef DEBUG
   /* Start up debugging mode if requested */
   if (debuglevel > 0)
@@ -2942,8 +2944,6 @@
     /* Default search path from RFC1524 */
     MailcapPath = safe_strdup ("~/.mailcap:" PKGDATADIR "/mailcap:" SYSCONFDIR 
"/mailcap:/etc/mailcap:/usr/etc/mailcap:/usr/local/etc/mailcap");
   }
-
-  Tempdir = safe_strdup ((p = getenv ("TMPDIR")) ? p : "/tmp");
 
   p = getenv ("VISUAL");
   if (!p)
diff -ru mutt-1.5.17/mailbox.h mgo/mailbox.h
--- mutt-1.5.17/mailbox.h       Fri Mar  2 19:44:44 2007
+++ mgo/mailbox.h       Wed Nov 14 22:14:46 2007
@@ -49,6 +49,7 @@
   struct {
     unsigned read : 1;
     unsigned flagged : 1;
+    unsigned grouped : 1;
     unsigned replied : 1;
   } flags;
   time_t received;     /* the time at which this message was received */
diff -ru mutt-1.5.17/mbox.c mgo/mbox.c
--- mutt-1.5.17/mbox.c  Fri Mar  2 19:44:44 2007
+++ mgo/mbox.c  Wed Nov 14 22:36:32 2007
@@ -1178,6 +1178,7 @@
           * and we don't want to lose _those_ changes
           */
          mutt_set_flag (ctx, ctx->hdrs[i], M_FLAG, old_hdrs[j]->flagged);
+         mutt_set_flag (ctx, ctx->hdrs[i], M_GROUPED, old_hdrs[j]->grouped);
          mutt_set_flag (ctx, ctx->hdrs[i], M_REPLIED, old_hdrs[j]->replied);
          mutt_set_flag (ctx, ctx->hdrs[i], M_OLD, old_hdrs[j]->old);
          mutt_set_flag (ctx, ctx->hdrs[i], M_READ, old_hdrs[j]->read);
diff -ru mutt-1.5.17/mh.c mgo/mh.c
--- mutt-1.5.17/mh.c    Fri Apr 13 20:40:07 2007
+++ mgo/mh.c    Sun Nov 18 13:32:19 2007
@@ -546,6 +546,7 @@
 
   h->flagged = 0;
   h->read = 0;
+  h->grouped = 0;
   h->replied = 0;
 
   if ((p = strrchr (path, ':')) != NULL && mutt_strncmp (p + 1, "2,", 2) == 0)
@@ -569,6 +570,11 @@
        h->read = 1;
        break;
 
+      case 'G':                /* group-replied */
+
+       h->grouped = 1;
+       break;
+
       case 'R':                /* replied */
 
        h->replied = 1;
@@ -848,7 +854,7 @@
              (debugfile,
               "%s:%d Adding header structure. Flags: %s%s%s%s%s\n", __FILE__,
               __LINE__, md->h->flagged ? "f" : "", md->h->deleted ? "D" : "",
-              md->h->replied ? "r" : "", md->h->old ? "O" : "",
+              md->h->grouped ? "g" : "", md->h->replied ? "r" : "", md->h->old 
? "O" : "",
               md->h->read ? "R" : ""));
       if (ctx->msgcount == ctx->hdrmax)
        mx_alloc_memory (ctx);
@@ -1157,12 +1163,13 @@
    * test even though there is no associated flag.
    */
   
-  if (hdr && (hdr->flagged || hdr->replied || hdr->read || hdr->deleted || 
hdr->old || hdr->maildir_flags))
+  if (hdr && (hdr->flagged || hdr->grouped|| hdr->replied || hdr->read || 
hdr->deleted || hdr->old || hdr->maildir_flags))
   {
     char tmp[LONG_STRING];
     snprintf (tmp, sizeof (tmp),
-             "%s%s%s%s%s",
+             "%s%s%s%s%s%s",
              hdr->flagged ? "F" : "",
+             hdr->grouped ? "G" : "",
              hdr->replied ? "R" : "",
              hdr->read ? "S" : "", hdr->deleted ? "T" : "",
              NONULL(hdr->maildir_flags));
@@ -1740,6 +1747,8 @@
    * through it */
   if (o->flagged != n->flagged)
     mutt_set_flag (ctx, o, M_FLAG, n->flagged);
+  if (o->grouped != n->grouped)
+    mutt_set_flag (ctx, o, M_GROUPED, n->grouped);
   if (o->replied != n->replied)
     mutt_set_flag (ctx, o, M_REPLIED, n->replied);
   if (o->read != n->read)
diff -ru mutt-1.5.17/mutt.h mgo/mutt.h
--- mutt-1.5.17/mutt.h  Tue Aug 28 19:44:16 2007
+++ mgo/mutt.h  Wed Nov 14 21:00:49 2007
@@ -195,6 +195,7 @@
   M_NONE,
   M_NEW,
   M_OLD,
+  M_GROUPED,
   M_REPLIED,
   M_READ,
   M_UNREAD,
@@ -718,6 +719,7 @@
   unsigned int read : 1;
   unsigned int expired : 1;            /* already expired? */
   unsigned int superseded : 1;                 /* got superseded? */
+  unsigned int grouped : 1;
   unsigned int replied : 1;
   unsigned int subject_changed : 1;    /* used for threading */
   unsigned int threaded : 1;           /* used for threading */
diff -ru mutt-1.5.17/mx.c mgo/mx.c
--- mutt-1.5.17/mx.c    Wed Jul 11 19:52:55 2007
+++ mgo/mx.c    Wed Nov 14 22:35:41 2007
@@ -1270,6 +1270,7 @@
   if (hdr)
   {
     msg->flags.flagged = hdr->flagged;
+    msg->flags.grouped = hdr->grouped;
     msg->flags.replied = hdr->replied;
     msg->flags.read    = hdr->read;
     msg->received = hdr->received;
diff -ru mutt-1.5.17/parse.c mgo/parse.c
--- mutt-1.5.17/parse.c Fri Mar  2 19:44:44 2007
+++ mgo/parse.c Wed Nov 14 22:35:20 2007
@@ -1201,6 +1201,9 @@
        {
          switch(*p)
          {
+           case 'g':
+           hdr->grouped = 1;
+           break;
            case 'r':
            hdr->replied = 1;
            break;
@@ -1238,6 +1241,9 @@
        {
          switch (*p)
          {
+           case 'G':
+           hdr->grouped = 1;
+           break;
            case 'A':
            hdr->replied = 1;
            break;
diff -ru mutt-1.5.17/pattern.c mgo/pattern.c
--- mutt-1.5.17/pattern.c       Wed Sep  5 20:28:05 2007
+++ mgo/pattern.c       Wed Nov 14 22:33:01 2007
@@ -80,6 +80,7 @@
   { 'O', M_OLD,                        0,              NULL },
   { 'p', M_PERSONAL_RECIP,     0,              NULL },
   { 'P', M_PERSONAL_FROM,      0,              NULL },
+  { 'q', M_GROUPED,            0,              NULL },
   { 'Q', M_REPLIED,            0,              NULL },
   { 'r', M_DATE_RECEIVED,      0,              eat_date },
   { 'R', M_READ,               0,              NULL },
@@ -1114,8 +1115,10 @@
       return (pat->not ? h->old || h->read : !(h->old || h->read));
     case M_UNREAD:
       return (pat->not ? h->read : !h->read);
+    case M_GROUPED:
+      return (pat->not ^ h->grouped);
     case M_REPLIED:
-      return (pat->not ^ h->replied);
+      return ((pat->not ^ h->replied) || (pat->not ^ h->grouped));
     case M_OLD:
       return (pat->not ? (!h->old || h->read) : (h->old && !h->read));
     case M_READ:
diff -ru mutt-1.5.17/send.c mgo/send.c
--- mutt-1.5.17/send.c  Thu Jul 26 21:43:39 2007
+++ mgo/send.c  Sat Nov 17 17:24:40 2007
@@ -1259,7 +1259,7 @@
       killfrom = 1;
     }
 
-    if ((flags & SENDREPLY) && cur)
+    if ((flags & (SENDREPLY|SENDGROUPREPLY)) && cur)
     {
       /* change setting based upon message we are replying to */
       mutt_message_hook (ctx, cur, M_REPLYHOOK);
@@ -1269,7 +1269,10 @@
        * user can use ~Q in a send-hook to know when reply-hook's are also
        * being used.
        */
-      msg->replied = 1;
+      if (flags & SENDREPLY)
+             msg->replied = 1;
+      else
+             msg->grouped = 1;
     }
 
     /* change settings based upon recipients */
@@ -1282,7 +1285,7 @@
      * this message was erroneously get the 'R'eplied flag when stored in
      * a maildir-style mailbox.
      */
-    msg->replied = 0;
+    msg->grouped = msg->replied = 0;
 
     /* $use_from and/or $from might have changed in a send-hook */
     if (killfrom)
@@ -1781,7 +1784,10 @@
   if (flags & SENDREPLY)
   {
     if (cur && ctx)
-      mutt_set_flag (ctx, cur, M_REPLIED, 1);
+      if (flags & SENDGROUPREPLY)
+        mutt_set_flag (ctx, cur, M_GROUPED, 1);
+      else
+        mutt_set_flag (ctx, cur, M_REPLIED, 1);
     else if (!(flags & SENDPOSTPONED) && ctx && ctx->tagged)
     {
       for (i = 0; i < ctx->vcount; i++)