A while ago [1], I wrote:
> The prefix in the index indicating an address is a destination rather
> than a source seems to be hardcoded to To, Cc or Bcc depending on the
> header where it occurs. But these take up precious screen space. I'd
> like them to be configurable, so I can change them to some Unicode
> arrow characters or even to the empty string.
The attached patch _partly_ addresses this. It allows you to use choose
one of the following:
1. The traditional behavior, "To ", "Cc " and "Bcc ". Of course this is
the default.
2. A single character, ASCII only (!) prefix for each case. I find ">",
"+" and "-" most natural, but this is configurable.
3. No prefix at all, which can be selected for each case separately.
I couldn't think of a way to use only one new option _and_ safely allow
utf-8 arrow thingies, but this scratches my itch, so here it is.
P.S. I know this belongs on the dev list, but I don't want to subscribe
there. Don't punish me too severely!
[1]
http://article.gmane.org/gmane.mail.mutt.user/43136
--
Please *no* private copies of mailing list or newsgroup messages.
Rule 420: All persons more than eight miles high to leave the court.
diff --git a/globals.h b/globals.h
index 57fa497..22ff445 100644
--- a/globals.h
+++ b/globals.h
@@ -52,6 +52,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;
diff --git a/hdrline.c b/hdrline.c
index 21adc28..e0bef67 100644
--- a/hdrline.c
+++ b/hdrline.c
@@ -103,30 +103,75 @@ static int first_mailing_list (char *buf, size_t buflen, ADDRESS *a)
return 0;
}
+enum {
+ DISP_TO,
+ DISP_CC,
+ DISP_BCC,
+ DISP_NONE
+};
+
+static void make_from_prefix(int disp, char* buf, int fmt)
+{
+ static const char *long_prefixes[] = {"To ", "Cc ", "Bcc ", ""};
+ static const int long_prefixes_lengths[] = {3, 3, 4, 0};
+ int len;
+
+ if (Fromchars == NULL || *Fromchars == '\0') {
+ memcpy(buf, long_prefixes[disp], long_prefixes_lengths[disp] + 1);
+ len = long_prefixes_lengths[disp];
+ }
+ else if (strlen(Fromchars) <= disp) {
+ buf[0] = ' ';
+ buf[1] = '\0';
+ len = 1;
+ }
+ else if (Fromchars[disp] == '\r') {
+ buf[0] = '\0';
+ len = 0;
+ }
+ else {
+ buf[0] = Fromchars[disp];
+ buf[1] = '\0';
+ len = 1;
+ }
+
+ if (fmt)
+ memcpy(buf + len, "%s", 3);
+}
+
static void make_from (ENVELOPE *hdr, char *buf, size_t len, int do_lists)
{
- int me;
+ int me, disp;
+ char prefix[20];
+ ADDRESS* name_hdr[] = {hdr->to, hdr->cc, hdr->bcc, hdr->from};
me = mutt_addr_is_user (hdr->from);
if (do_lists || me)
{
- if (check_for_mailing_list (hdr->to, "To ", buf, len))
+ make_from_prefix(DISP_TO, prefix, 0);
+ if (check_for_mailing_list (hdr->to, prefix, buf, len))
return;
- if (check_for_mailing_list (hdr->cc, "Cc ", buf, len))
+ make_from_prefix(DISP_CC, prefix, 0);
+ if (check_for_mailing_list (hdr->cc, prefix, buf, len))
return;
}
if (me && hdr->to)
- snprintf (buf, len, "To %s", mutt_get_name (hdr->to));
+ disp = DISP_TO;
else if (me && hdr->cc)
- snprintf (buf, len, "Cc %s", mutt_get_name (hdr->cc));
+ disp = DISP_CC;
else if (me && hdr->bcc)
- snprintf (buf, len, "Bcc %s", mutt_get_name (hdr->bcc));
+ disp = DISP_BCC;
else if (hdr->from)
- strfcpy (buf, mutt_get_name (hdr->from), len);
- else
- *buf = 0;
+ disp = DISP_NONE;
+ else {
+ *buf = '\0';
+ return;
+ }
+
+ make_from_prefix(disp, prefix, 1);
+ snprintf (buf, len, prefix, mutt_get_name (name_hdr[disp]));
}
static void make_from_addr (ENVELOPE *hdr, char *buf, size_t len, int do_lists)
diff --git a/init.h b/init.h
index 0adf360..8d94425 100644
--- a/init.h
+++ b/init.h
@@ -871,6 +871,29 @@ 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. The first character is the one used when the mail is
+ ** written by you and has a To address, or has a known mailing list in
+ ** the To address. The second is used when the mail is written by you
+ ** and has a Cc address, or has a known mailing list in the Cc
+ ** address. The third is used when the mail is written by you and has
+ ** a Bcc address. Lastly, the fourth character is used to prefix the
+ ** field in all remaining cases.
+ ** .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