]> granicus.if.org Git - neomutt/commitdiff
add %Fp expando for plain from address
authorx3nb63 <25959223+x3nb63@users.noreply.github.com>
Fri, 27 Jul 2018 18:42:50 +0000 (20:42 +0200)
committerRichard Russon <rich@flatcap.org>
Thu, 4 Oct 2018 09:22:54 +0000 (10:22 +0100)
format_flags.h
hdrline.c
hook.c
init.h

index 9a8299ea8d5ac339b103281a8476e48a093ef9e1..35213f3b2fc0642c5dcaec1427c332eb12dc817e 100644 (file)
@@ -37,7 +37,8 @@ enum FormatFlag
   MUTT_FORMAT_STAT_FILE   = (1 << 4), /**< used by attach_format_str */
   MUTT_FORMAT_ARROWCURSOR = (1 << 5), /**< reserve space for arrow_cursor */
   MUTT_FORMAT_INDEX       = (1 << 6), /**< this is a main index entry */
-  MUTT_FORMAT_NOFILTER    = (1 << 7)  /**< do not allow filtering on this pass */
+  MUTT_FORMAT_NOFILTER    = (1 << 7), /**< do not allow filtering on this pass */
+  MUTT_FORMAT_PLAIN       = (1 << 8), /**< do not prepend DISP_TO, DISP_CC ... */
 };
 
 /**
index f1178ccee4249a8a59d03dd5ec8cbc5b714e192d..d4782e173d6e699a8135b7203bf213052cfcd40a 100644 (file)
--- a/hdrline.c
+++ b/hdrline.c
@@ -213,6 +213,7 @@ enum FieldType
   DISP_CC,
   DISP_BCC,
   DISP_FROM,
+  DISP_PLAIN,
   DISP_NUM
 };
 
@@ -250,10 +251,8 @@ static const char *make_from_prefix(enum FieldType disp)
   /* need 2 bytes at the end, one for the space, another for NUL */
   static char padded[8];
   static const char *long_prefixes[DISP_NUM] = {
-    [DISP_TO] = "To ",
-    [DISP_CC] = "Cc ",
-    [DISP_BCC] = "Bcc ",
-    [DISP_FROM] = "",
+    [DISP_TO] = "To ", [DISP_CC] = "Cc ", [DISP_BCC] = "Bcc ",
+    [DISP_FROM] = "",  [DISP_PLAIN] = "",
   };
 
   if (!FromChars || !FromChars->chars || (FromChars->len == 0))
@@ -280,7 +279,8 @@ static const char *make_from_prefix(enum FieldType disp)
  * The field can optionally be prefixed by a character from $from_chars.
  * If $from_chars is not set, the prefix will be, "To", "Cc", etc
  */
-static void make_from(struct Envelope *env, char *buf, size_t buflen, bool do_lists)
+static void make_from(struct Envelope *env, char *buf, size_t buflen,
+                      bool do_lists, enum FormatFlag flags)
 {
   if (!env || !buf)
     return;
@@ -301,7 +301,7 @@ static void make_from(struct Envelope *env, char *buf, size_t buflen, bool do_li
 
   if (me && env->to)
   {
-    disp = DISP_TO;
+    disp = (flags & MUTT_FORMAT_PLAIN) ? DISP_PLAIN : DISP_TO;
     name = env->to;
   }
   else if (me && env->cc)
@@ -480,6 +480,7 @@ static bool thread_is_old(struct Context *ctx, struct Email *e)
  * | \%e     | Current message number in thread
  * | \%E     | Number of messages in current thread
  * | \%F     | Author name, or recipient name if the message is from you
+ * | \%Fp    | Like %F, but plain. No contextual formatting is applied to recipient name
  * | \%f     | Sender (address + real name), either From: or Return-Path:
  * | \%g     | Message tags (e.g. notmuch tags/imap flags)
  * | \%Gx    | Individual message tag (e.g. notmuch tags/imap flags)
@@ -845,13 +846,19 @@ static const char *index_format_str(char *buf, size_t buflen, size_t col, int co
     case 'F':
       if (!optional)
       {
+        const bool is_plain = (src[0] == 'p');
         colorlen = add_index_color(buf, buflen, flags, MT_COLOR_INDEX_AUTHOR);
-        make_from(e->env, tmp, sizeof(tmp), false);
+        make_from(e->env, tmp, sizeof(tmp), false, (is_plain ? MUTT_FORMAT_PLAIN : 0));
         mutt_format_s(buf + colorlen, buflen - colorlen, prec, tmp);
         add_index_color(buf + colorlen, buflen - colorlen, flags, MT_COLOR_INDEX);
+
+        if (is_plain)
+          src++;
       }
       else if (mutt_addr_is_user(e->env->from))
+      {
         optional = 0;
+      }
       break;
 
     case 'g':
@@ -975,7 +982,7 @@ static const char *index_format_str(char *buf, size_t buflen, size_t col, int co
       if (!optional)
       {
         colorlen = add_index_color(buf, buflen, flags, MT_COLOR_INDEX_AUTHOR);
-        make_from(e->env, tmp, sizeof(tmp), true);
+        make_from(e->env, tmp, sizeof(tmp), true, flags);
         mutt_format_s(buf + colorlen, buflen - colorlen, prec, tmp);
         add_index_color(buf + colorlen, buflen - colorlen, flags, MT_COLOR_INDEX);
       }
diff --git a/hook.c b/hook.c
index a46ab5e0f93a597655a95857244abae7077e0742..26b719a99a6877ac6c218dd422dcc38232de577d 100644 (file)
--- a/hook.c
+++ b/hook.c
@@ -502,7 +502,7 @@ static int addr_hook(char *path, size_t pathlen, int type, struct Context *ctx,
       if ((mutt_pattern_exec(hook->pattern, 0, ctx, e, &cache) > 0) ^
           hook->regex.not)
       {
-        mutt_make_string(path, pathlen, hook->command, ctx, e);
+        mutt_make_string_flags(path, pathlen, hook->command, ctx, e, MUTT_FORMAT_PLAIN);
         return 0;
       }
     }
diff --git a/init.h b/init.h
index 69263e1bf5dc3acb1e07a73b7ac6793d45e0d3f8..13b85fb03b3f29137e78dfb3f72cc7da8b71ebab 100644 (file)
--- a/init.h
+++ b/init.h
@@ -1628,6 +1628,7 @@ struct ConfigDef MuttVars[] = {
   ** .dt %e .dd Current message number in thread
   ** .dt %E .dd Number of messages in current thread
   ** .dt %F .dd Author name, or recipient name if the message is from you
+  ** .dt %Fp .dd Like %F, but plain. No contextual formatting is applied to recipient name
   ** .dt %f .dd Sender (address + real name), either From: or Return-Path:
   ** .dt %g .dd Newsgroup name (if compiled with NNTP support)
   ** .dt %g .dd Message tags (e.g. notmuch tags/imap flags)