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

mutt feature request 1046 [patch]



[this is a resend; apologies if this arrives twice]

Hello. I have included a patch to support mutt feature request 1046,
'Request that the "uncolor" command work with "body"/"header" objects
in addition to "index"'.

I have not worked in the mutt source before, so please accept my
apologies for any failures to follow local convention. I'm also sorry
that I've modified one gettext string and introduced another one. And I
haven't submitted a patch to clean up the documentation. :)

If this patch is acceptable for inclusion in mutt, please let me know,
and I'll submit a patch for the documentation as well. If this patch
isn't acceptable as-is, please let me know, and I will try to address
concerns, before generating a patch for the documentation.

Feedback appreciated
--- BUILD/mutt-1.5.9/color.c.uncolor-body-header        2005-02-03 
10:47:52.000000000 -0800
+++ BUILD/mutt-1.5.9/color.c    2005-12-12 21:08:33.000000000 -0800
@@ -369,7 +369,8 @@
                         short parse_uncolor)
 {
   int object = 0, do_cache = 0;
-  COLOR_LINE *tmp, *last = NULL;
+  char *list;
+  COLOR_LINE *which, *tmp, *last = NULL;
 
   mutt_extract_token (buf, s, 0);
 
@@ -379,11 +380,21 @@
     return (-1);
   }
 
-  if (mutt_strncmp (buf->data, "index", 5) != 0)
+  list = strdup(buf->data);
+  if (!list)
   {
     snprintf (err->data, err->dsize,
-             _("%s: command valid only for index object"), 
-             parse_uncolor ? "uncolor" : "unmono");
+             _("%s: could not allocate storage for %.16s"),
+             parse_uncolor ? "uncolor" : "unmono", buf->data);
+    return (-1);
+  }
+  if (!((mutt_strncmp (list, "index", 5) == 0) ||
+              (mutt_strncmp (list, "body", 4) ==0) ||
+              (mutt_strncmp (list, "header", 7) ==0)))
+  {
+    snprintf (err->data, err->dsize,
+             _("%s: command valid only for index, body, header objects, not 
%.16s"), 
+             parse_uncolor ? "uncolor" : "unmono", buf->data);
     return (-1);
   }
   
@@ -417,12 +428,19 @@
   }
      
   
+  if (mutt_strncmp(list, "index", 5) == 0)
+    which = ColorIndexList;
+  else if (mutt_strncmp(list, "body", 4) == 0)
+    which = ColorBodyList;
+  else if (mutt_strncmp(list, "header", 7) == 0)
+    which = ColorHdrList;
+
   do
   {
     mutt_extract_token (buf, s, 0);
     if (!mutt_strcmp ("*", buf->data))
     {
-      for (tmp = ColorIndexList; tmp; )
+      for (tmp = which; tmp; )
       {
         if (!do_cache)
          do_cache = 1;
@@ -430,22 +448,33 @@
        tmp = tmp->next;
        mutt_free_color_line(&last, parse_uncolor);
       }
-      ColorIndexList = NULL;
+      if (mutt_strncmp(list, "index", 5) == 0)
+        ColorIndexList = NULL;
+      else if (mutt_strncmp(list, "body", 4) == 0)
+        ColorBodyList = NULL;
+      else if (mutt_strncmp(list, "header", 7) == 0)
+        ColorHdrList = NULL;
     }
     else
     {
-      for (last = NULL, tmp = ColorIndexList; tmp; last = tmp, tmp = tmp->next)
+      for (last = NULL, tmp = which; tmp; last = tmp, tmp = tmp->next)
       {
        if (!mutt_strcmp (buf->data, tmp->pattern))
        {
           if (!do_cache)
            do_cache = 1;
-         dprint(1,(debugfile,"Freeing pattern \"%s\" from ColorIndexList\n",
-                              tmp->pattern));
+         dprint(1,(debugfile,"Freeing pattern \"%s\" from \"%s\"\n",
+                              tmp->pattern, list ? list : "NULL"));
          if (last)
            last->next = tmp->next;
-         else
-           ColorIndexList = tmp->next;
+         else {
+           if (mutt_strncmp(list, "index", 5) == 0)
+              ColorIndexList = tmp->next;
+           else if (mutt_strncmp(list, "body", 4) == 0)
+              ColorBodyList = tmp->next;
+           else if (mutt_strncmp(list, "header", 7) == 0)
+              ColorHdrList = tmp->next;
+         }
          mutt_free_color_line(&tmp, parse_uncolor);
          break;
        }

Attachment: pgpSJhQBjUD73.pgp
Description: PGP signature