# HG changeset patch
# User Jiri Denemark <ji...@mamuti.net>
# Date 1362434347 -3600
# Branch HEAD
# Node ID a5f8b3b34a5a1780850c85687d22a1883083aacb
# Parent  4c16c0d1ba9e0d81608a0fbccebd08daa28d76f5
Add support for changing X-Label

Mutt supports ~y pattern which matches X-Label content but does not provide an
easy way to change this header. This adds two new functions called set-label
and clear-label for index and pager for changing X-Label header.

diff --git a/OPS b/OPS
--- a/OPS
+++ b/OPS
@@ -172,6 +172,8 @@
 OP_UNDELETE "undelete the current entry"
 OP_UNDELETE_THREAD "undelete all messages in thread"
 OP_UNDELETE_SUBTHREAD "undelete all messages in subthread"
+OP_SET_LABEL "set x-label header"
+OP_CLEAR_LABEL "clear x-label header"
 OP_VERSION "show the Mutt version number and date"
 OP_VIEW_ATTACH "view attachment using mailcap entry if necessary"
 OP_VIEW_ATTACHMENTS "show MIME attachments"
diff --git a/commands.c b/commands.c
--- a/commands.c
+++ b/commands.c
@@ -502,6 +502,25 @@
                      PipeSep);
 }
 
+void mutt_set_label (HEADER *h, int clear)
+{
+  char buffer[LONG_STRING];
+
+  if (clear)
+    FREE (&h->env->x_label);
+  else
+  {
+    buffer[0] = 0;
+    if (mutt_get_field (_("Label message: "), buffer, sizeof (buffer), 0) != 0
+        || !buffer[0])
+      return;
+
+    mutt_str_replace (&h->env->x_label, buffer);
+  }
+
+  h->env->label_changed = h->changed = 1;
+}
+
 void mutt_print_message (HEADER *h)
 {
 
diff --git a/copy.c b/copy.c
--- a/copy.c
+++ b/copy.c
@@ -98,6 +98,9 @@
            (ascii_strncasecmp ("Status:", buf, 7) == 0 ||
             ascii_strncasecmp ("X-Status:", buf, 9) == 0))
          continue;
+       if ((flags & CH_UPDATE_LABEL) &&
+           ascii_strncasecmp ("X-Label:", buf, 8) == 0)
+         continue;
        if ((flags & (CH_UPDATE_LEN | CH_XMIT | CH_NOLEN)) &&
            (ascii_strncasecmp ("Content-Length:", buf, 15) == 0 ||
             ascii_strncasecmp ("Lines:", buf, 6) == 0))
@@ -198,6 +201,9 @@
          (ascii_strncasecmp ("Status:", buf, 7) == 0 ||
           ascii_strncasecmp ("X-Status:", buf, 9) == 0))
        continue;
+      if ((flags & CH_UPDATE_LABEL) &&
+          ascii_strncasecmp ("X-Label:", buf, 8) == 0)
+        continue;
       if ((flags & (CH_UPDATE_LEN | CH_XMIT | CH_NOLEN)) &&
          (ascii_strncasecmp ("Content-Length:", buf, 15) == 0 ||
           ascii_strncasecmp ("Lines:", buf, 6) == 0))
@@ -333,6 +339,7 @@
        CH_NOQFROM      ignore ">From " line
        CH_UPDATE_IRT   update the In-Reply-To: header
        CH_UPDATE_REFS  update the References: header
+       CH_UPDATE_LABEL update the X-Label: header
 
    prefix
        string to use if CH_PREFIX is set
@@ -345,7 +352,8 @@
 
   if (h->env)
     flags |= (h->env->irt_changed ? CH_UPDATE_IRT : 0)
-      | (h->env->refs_changed ? CH_UPDATE_REFS : 0);
+      | (h->env->refs_changed ? CH_UPDATE_REFS : 0)
+      | (h->env->label_changed ? CH_UPDATE_LABEL : 0);
   
   if (mutt_copy_hdr (in, out, h->offset, h->content->offset, flags, prefix) == 
-1)
     return -1;
@@ -404,6 +412,9 @@
     }
   }
 
+  if ((flags & CH_UPDATE_LABEL) && (h->env->x_label))
+    fprintf (out, "X-Label: %s\n", h->env->x_label);
+
   if (flags & CH_UPDATE_LEN &&
       (flags & CH_NOLEN) == 0)
   {
diff --git a/copy.h b/copy.h
--- a/copy.h
+++ b/copy.h
@@ -53,6 +53,7 @@
 #define CH_UPDATE_IRT     (1<<16) /* update In-Reply-To: */
 #define CH_UPDATE_REFS    (1<<17) /* update References: */
 #define CH_DISPLAY        (1<<18) /* display result to user */
+#define CH_UPDATE_LABEL   (1<<19) /* update X-Label: */
 
 
 int mutt_copy_hdr (FILE *, FILE *, LOFF_T, LOFF_T, int, const char *);
diff --git a/curs_main.c b/curs_main.c
--- a/curs_main.c
+++ b/curs_main.c
@@ -2185,6 +2185,33 @@
        }
        break;
 
+      case OP_SET_LABEL:
+      case OP_CLEAR_LABEL:
+       CHECK_MSGCOUNT;
+       CHECK_VISIBLE;
+       CHECK_READONLY;
+
+       if (op == OP_CLEAR_LABEL)
+       {
+         mutt_set_label (CURHDR, 1);
+         mutt_message _("Label cleared");
+       }
+       else
+       {
+         mutt_set_label (CURHDR, 0);
+         mutt_message _("Label changed");
+       }
+       Context->changed = 1;
+
+       if (menu->menu == MENU_PAGER)
+       {
+         op = OP_DISPLAY_MESSAGE;
+         continue;
+       }
+       else
+         menu->redraw |= REDRAW_CURRENT;
+       break;
+
       case OP_VERSION:
        mutt_version ();
        break;
diff --git a/functions.h b/functions.h
--- a/functions.h
+++ b/functions.h
@@ -159,6 +159,8 @@
   { "next-unread",             OP_MAIN_NEXT_UNREAD,            NULL },
   { "previous-unread",         OP_MAIN_PREV_UNREAD,            NULL },
   { "parent-message",          OP_MAIN_PARENT_MESSAGE,         "P" },
+  { "set-label",               OP_SET_LABEL,                   NULL },
+  { "clear-label",             OP_CLEAR_LABEL,                 NULL },
 
 
   { "extract-keys",            OP_EXTRACT_KEYS,                "\013" },
@@ -259,6 +261,8 @@
   { "previous-line",   OP_PREV_LINE,                   NULL },
   { "bottom",          OP_PAGER_BOTTOM,                NULL },
   { "parent-message",  OP_MAIN_PARENT_MESSAGE,         "P" },
+  { "set-label",       OP_SET_LABEL,                   NULL },
+  { "clear-label",     OP_CLEAR_LABEL,                 NULL },
 
 
 
diff --git a/mh.c b/mh.c
--- a/mh.c
+++ b/mh.c
@@ -1613,7 +1613,8 @@
   HEADER *h = ctx->hdrs[msgno];
 
   if (h->attach_del || 
-      (h->env && (h->env->refs_changed || h->env->irt_changed)))
+      (h->env &&
+       (h->env->refs_changed || h->env->irt_changed || h->env->label_changed)))
     if (mh_rewrite_message (ctx, msgno) != 0)
       return -1;
 
@@ -1625,7 +1626,8 @@
   HEADER *h = ctx->hdrs[msgno];
 
   if (h->attach_del || 
-      (h->env && (h->env->refs_changed || h->env->irt_changed)))
+      (h->env &&
+       (h->env->refs_changed || h->env->irt_changed || h->env->label_changed)))
   {
     /* when doing attachment deletion/rethreading, fall back to the MH case. */
     if (mh_rewrite_message (ctx, msgno) != 0)
diff --git a/mutt.h b/mutt.h
--- a/mutt.h
+++ b/mutt.h
@@ -595,6 +595,7 @@
 
   unsigned int irt_changed : 1; /* In-Reply-To changed to link/break threads */
   unsigned int refs_changed : 1; /* References changed to break thread */
+  unsigned int label_changed : 1; /* X-Label header changed */
 } ENVELOPE;
 
 typedef struct parameter
diff --git a/muttlib.c b/muttlib.c
--- a/muttlib.c
+++ b/muttlib.c
@@ -750,7 +750,10 @@
   MOVE_ELEM(message_id);
   MOVE_ELEM(supersedes);
   MOVE_ELEM(date);
-  MOVE_ELEM(x_label);
+  if (!base->label_changed)
+  {
+    MOVE_ELEM(x_label);
+  }
   if (!base->refs_changed)
   {
     MOVE_ELEM(references);
diff --git a/protos.h b/protos.h
--- a/protos.h
+++ b/protos.h
@@ -372,6 +372,7 @@
 void mutt_set_header_color(CONTEXT *, HEADER *);
 void mutt_sleep (short);
 int mutt_save_confirm (const char  *, struct stat *);
+void mutt_set_label(HEADER *, int);
 
 int mh_valid_message (const char *);
 

Reply via email to