]> granicus.if.org Git - neomutt/commitdiff
feature: $from_chars highlights differences in authorship
authorIan Zimmerman <itz@primate.net>
Fri, 2 Dec 2016 13:14:26 +0000 (13:14 +0000)
committerRichard Russon <rich@flatcap.org>
Fri, 2 Dec 2016 13:17:05 +0000 (13:17 +0000)
This adds a new variable $from_chars which works like $to_chars.
It will add a character prefix to the %F or %L field in $index_format.
The character is determined by the contents of the To/Cc/Bcc fields.

globals.h
hdrline.c
init.h

index 74aa66c51e1716aee305ed978e7b38cfeb7e1a1e..8f556eba5325140931b7398b5990bea509cd02ef 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -54,6 +54,7 @@ WHERE char *EscChar;
 WHERE char *FolderFormat;
 WHERE char *ForwFmt;
 WHERE char *Fqdn;
+WHERE char *Fromchars;
 WHERE char *HdrFmt;
 WHERE char *HistFile;
 WHERE char *Homedir;
index 0c0032c55fe5b188ce31c1eb840e6555b10b272b..04159f2f51efa7cfb69cde082d82be160a9c6dc7 100644 (file)
--- a/hdrline.c
+++ b/hdrline.c
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 1996-2000,2002,2007 Michael R. Elkins <me@mutt.org>
  * Copyright (C) 2016 Richard Russon <rich@flatcap.org>
+ * Copyright (C) 2016 Ian Zimmerman <itz@primate.net>
  * 
  *     This program is free software; you can redistribute it and/or modify
  *     it under the terms of the GNU General Public License as published by
@@ -61,7 +62,7 @@ int mutt_is_subscribed_list (ADDRESS *addr)
  * return 1.  Otherwise, simply return 0.
  */
 static int
-check_for_mailing_list (ADDRESS *adr, char *pfx, char *buf, int buflen)
+check_for_mailing_list (ADDRESS *adr, const char *pfx, char *buf, int buflen)
 {
   for (; adr; adr = adr->next)
   {
@@ -176,30 +177,104 @@ char *get_nth_wchar (char *ustr, int index)
   return buffer;
 }
 
-static void make_from (ENVELOPE *hdr, char *buf, size_t len, int do_lists)
+enum FieldType
 {
+  DISP_TO,
+  DISP_CC,
+  DISP_BCC,
+  DISP_FROM,
+  DISP_NUM
+};
+
+/**
+ * make_from_prefix - Create a prefix for an author field
+ * @disp:   Type of field
+ * @return: Prefix string (do not free() it)
+ *
+ * If $from_chars is set, pick an appropriate character from it.
+ * If not, use the default prefix: "To", "Cc", etc
+ */
+static const char *make_from_prefix(enum FieldType disp)
+{
+  static char padded[8];
+  static const char *long_prefixes[DISP_NUM] =
+  {
+    [DISP_TO]   = "To ",
+    [DISP_CC]   = "Cc ",
+    [DISP_BCC]  = "Bcc ",
+    [DISP_FROM] = ""
+  };
+
+  if (!Fromchars || (*Fromchars == '\0'))
+    return long_prefixes[disp];
+
+  char *prefix = get_nth_wchar (Fromchars, disp);
+  if (!prefix || (prefix[0] == '\0'))
+      return prefix;
+
+  snprintf (padded, sizeof(padded), "%s ", prefix);
+  return padded;
+}
+
+/**
+ * make_from - Generate a From: field (with optional prefix)
+ * @env:      Envelope of the email
+ * @buf:      Buffer to store the result
+ * @len:      Size of the buffer
+ * @do_lists: Should we check for mailing lists?
+ *
+ * Generate the %F or %L field in $index_format.
+ * This is the author, or recipient of the email.
+ *
+ * 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 (ENVELOPE *env, char *buf, size_t len, int do_lists)
+{
+  if (!env || !buf)
+    return;
+
   int me;
+  enum FieldType disp;
+  ADDRESS *name;
 
-  me = mutt_addr_is_user (hdr->from);
+  me = mutt_addr_is_user (env->from);
 
   if (do_lists || me)
   {
-    if (check_for_mailing_list (hdr->to, "To ", buf, len))
+    if (check_for_mailing_list (env->to, make_from_prefix(DISP_TO), buf, len))
       return;
-    if (check_for_mailing_list (hdr->cc, "Cc ", buf, len))
+    if (check_for_mailing_list (env->cc, make_from_prefix(DISP_CC), buf, len))
       return;
   }
 
-  if (me && hdr->to)
-    snprintf (buf, len, "To %s", mutt_get_name (hdr->to));
-  else if (me && hdr->cc)
-    snprintf (buf, len, "Cc %s", mutt_get_name (hdr->cc));
-  else if (me && hdr->bcc)
-    snprintf (buf, len, "Bcc %s", mutt_get_name (hdr->bcc));
-  else if (hdr->from)
-    strfcpy (buf, mutt_get_name (hdr->from), len);
+  if (me && env->to)
+  {
+    disp = DISP_TO;
+    name = env->to;
+  }
+  else if (me && env->cc)
+  {
+    disp = DISP_CC;
+    name = env->cc;
+  }
+  else if (me && env->bcc)
+  {
+    disp = DISP_BCC;
+    name = env->bcc;
+  }
+  else if (env->from)
+  {
+    disp = DISP_FROM;
+    name = env->from;
+  }
   else
-    *buf = 0;
+  {
+    *buf = '\0';
+    return;
+  }
+
+  snprintf (buf, len, "%s%s", make_from_prefix(disp), mutt_get_name (name));
 }
 
 static void make_from_addr (ENVELOPE *hdr, char *buf, size_t len, int do_lists)
diff --git a/init.h b/init.h
index 6163dc7e982b99064db36fe58a271baa418c5c3d..4818062c8ccf554e7c641764c77c2a11285a21e6 100644 (file)
--- a/init.h
+++ b/init.h
@@ -1005,6 +1005,30 @@ struct option_t MuttVars[] = {
   ** .pp
   ** This setting defaults to the contents of the environment variable \fC$$$EMAIL\fP.
   */
+  { "from_chars",              DT_STR,  R_BOTH, UL &Fromchars, UL 0 },
+  /*
+  ** .pp
+  ** Controls the character used to prefix the %F and %L fields in the
+  ** index.
+  ** .dl
+  ** .dt \fBCharacter\fP .dd \fBDescription\fP
+  ** .dt 1 .dd Mail is written by you and has a To address, or has a known mailing list in the To address.
+  ** .dt 2 .dd Mail is written by you and has a Cc address, or has a known mailing list in the Cc address.
+  ** .dt 3 .dd Mail is written by you and has a Bcc address.
+  ** .dt 4 .dd All remaining cases.
+  ** .de
+  ** .pp
+  ** If this is empty or unset (default), the traditional long "To ",
+  ** "Cc " and "Bcc " prefixes are used.  If set but too short to
+  ** include a character for a particular case, a single space will be
+  ** prepended to the field.  To prevent any prefix at all from being
+  ** added in a particular case, use the special value CR (aka ^M)
+  ** for the corresponding character.
+  ** .pp
+  ** This slightly odd interface is necessitated by mutt's handling of
+  ** string variables; one cannot tell a variable that is unset from one
+  ** that is set to the empty string.
+  */
   { "gecos_mask",      DT_RX,   R_NONE, UL &GecosMask, UL "^[^,]*" },
   /*
   ** .pp