From 8e737a621f047579ca522646da8fdcd62dce68cd Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Wed, 3 May 2017 18:52:54 -0700 Subject: [PATCH] Add color commands for the compose menu headers and security status. (closes #3915). Add "color compose header" to color the From/To/Subject/etc fields in the compose menu. Add "color compose security_encrypt/sign/both/none" to color the security status of the message. --- color.c | 26 ++++++++++++++++++ compose.c | 50 +++++++++++++++++++++++++++++---- doc/manual.xml.head | 67 +++++++++++++++++++++++++++++++++++++++++++-- mutt_curses.h | 5 ++++ 4 files changed, 140 insertions(+), 8 deletions(-) diff --git a/color.c b/color.c index 073b6166e..df9cd4714 100644 --- a/color.c +++ b/color.c @@ -106,6 +106,16 @@ static const struct mapping_t Fields[] = { NULL, 0 } }; +static const struct mapping_t ComposeFields[] = +{ + { "header", MT_COLOR_COMPOSE_HEADER }, + { "security_encrypt", MT_COLOR_COMPOSE_SECURITY_ENCRYPT }, + { "security_sign", MT_COLOR_COMPOSE_SECURITY_SIGN }, + { "security_both", MT_COLOR_COMPOSE_SECURITY_BOTH }, + { "security_none", MT_COLOR_COMPOSE_SECURITY_NONE }, + { NULL, 0 } +}; + #define COLOR_QUOTE_INIT 8 static COLOR_LINE *mutt_new_color_line (void) @@ -622,6 +632,22 @@ parse_object(BUFFER *buf, BUFFER *s, int *o, int *ql, BUFFER *err) *o = MT_COLOR_QUOTED; } + else if (!ascii_strcasecmp(buf->data, "compose")) + { + if (!MoreArgs(s)) + { + strfcpy(err->data, _("Missing arguments."), err->dsize); + return -1; + } + + mutt_extract_token(buf, s, 0); + + if ((*o = mutt_getvaluebyname (buf->data, ComposeFields)) == -1) + { + snprintf (err->data, err->dsize, _("%s: no such object"), buf->data); + return (-1); + } + } else if ((*o = mutt_getvaluebyname (buf->data, Fields)) == -1) { snprintf (err->data, err->dsize, _("%s: no such object"), buf->data); diff --git a/compose.c b/compose.c index 6893ee004..386e33004 100644 --- a/compose.c +++ b/compose.c @@ -110,7 +110,9 @@ static void snd_entry (char *b, size_t blen, MUTTMENU *menu, int num) static void redraw_crypt_lines (HEADER *msg) { + SETCOLOR (MT_COLOR_COMPOSE_HEADER); mutt_window_mvprintw (MuttIndexWindow, HDR_CRYPT, 0, TITLE_FMT, "Security: "); + NORMAL_COLOR; if ((WithCrypto & (APPLICATION_PGP | APPLICATION_SMIME)) == 0) { @@ -119,13 +121,26 @@ static void redraw_crypt_lines (HEADER *msg) } if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN)) + { + SETCOLOR (MT_COLOR_COMPOSE_SECURITY_BOTH); addstr (_("Sign, Encrypt")); + } else if (msg->security & ENCRYPT) + { + SETCOLOR (MT_COLOR_COMPOSE_SECURITY_ENCRYPT); addstr (_("Encrypt")); + } else if (msg->security & SIGN) + { + SETCOLOR (MT_COLOR_COMPOSE_SECURITY_SIGN); addstr (_("Sign")); + } else + { + SETCOLOR (MT_COLOR_COMPOSE_SECURITY_NONE); addstr (_("None")); + } + NORMAL_COLOR; if ((msg->security & (ENCRYPT | SIGN))) { @@ -150,20 +165,32 @@ static void redraw_crypt_lines (HEADER *msg) if ((WithCrypto & APPLICATION_PGP) && (msg->security & APPLICATION_PGP) && (msg->security & SIGN)) - printw (TITLE_FMT "%s", _("sign as: "), PgpSignAs ? PgpSignAs : _("")); + { + SETCOLOR (MT_COLOR_COMPOSE_HEADER); + printw (TITLE_FMT, _("sign as: ")); + NORMAL_COLOR; + printw ("%s", PgpSignAs ? PgpSignAs : _("")); + } if ((WithCrypto & APPLICATION_SMIME) - && (msg->security & APPLICATION_SMIME) && (msg->security & SIGN)) { - printw (TITLE_FMT "%s", _("sign as: "), SmimeDefaultKey ? SmimeDefaultKey : _("")); + && (msg->security & APPLICATION_SMIME) && (msg->security & SIGN)) + { + SETCOLOR (MT_COLOR_COMPOSE_HEADER); + printw (TITLE_FMT, _("sign as: ")); + NORMAL_COLOR; + printw ("%s", SmimeDefaultKey ? SmimeDefaultKey : _("")); } if ((WithCrypto & APPLICATION_SMIME) && (msg->security & APPLICATION_SMIME) && (msg->security & ENCRYPT) && SmimeCryptAlg - && *SmimeCryptAlg) { - mutt_window_mvprintw (MuttIndexWindow, HDR_CRYPTINFO, 40, "%s%s", _("Encrypt with: "), - NONULL(SmimeCryptAlg)); + && *SmimeCryptAlg) + { + SETCOLOR (MT_COLOR_COMPOSE_HEADER); + mutt_window_mvprintw (MuttIndexWindow, HDR_CRYPTINFO, 40, "%s", _("Encrypt with: ")); + NORMAL_COLOR; + printw ("%s", NONULL(SmimeCryptAlg)); } } @@ -175,8 +202,10 @@ static void redraw_mix_line (LIST *chain) int c; char *t; + SETCOLOR (MT_COLOR_COMPOSE_HEADER); /* L10N: "Mix" refers to the MixMaster chain for anonymous email */ mutt_window_mvprintw (MuttIndexWindow, HDR_MIX, 0, TITLE_FMT, _("Mix: ")); + NORMAL_COLOR; if (!chain) { @@ -243,7 +272,9 @@ static void draw_envelope_addr (int line, ADDRESS *addr) buf[0] = 0; rfc822_write_address (buf, sizeof (buf), addr, 1); + SETCOLOR (MT_COLOR_COMPOSE_HEADER); mutt_window_mvprintw (MuttIndexWindow, line, 0, TITLE_FMT, Prompts[line]); + NORMAL_COLOR; mutt_paddstr (W, buf); } @@ -253,10 +284,17 @@ static void draw_envelope (HEADER *msg, char *fcc) draw_envelope_addr (HDR_TO, msg->env->to); draw_envelope_addr (HDR_CC, msg->env->cc); draw_envelope_addr (HDR_BCC, msg->env->bcc); + + SETCOLOR (MT_COLOR_COMPOSE_HEADER); mutt_window_mvprintw (MuttIndexWindow, HDR_SUBJECT, 0, TITLE_FMT, Prompts[HDR_SUBJECT]); + NORMAL_COLOR; mutt_paddstr (W, NONULL (msg->env->subject)); + draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to); + + SETCOLOR (MT_COLOR_COMPOSE_HEADER); mutt_window_mvprintw (MuttIndexWindow, HDR_FCC, 0, TITLE_FMT, Prompts[HDR_FCC]); + NORMAL_COLOR; mutt_paddstr (W, fcc); if (WithCrypto) diff --git a/doc/manual.xml.head b/doc/manual.xml.head index 289548111..9045d1e5c 100644 --- a/doc/manual.xml.head +++ b/doc/manual.xml.head @@ -2664,6 +2664,20 @@ silently truncated at the screen width, and are not wrapped. pattern +color + + + + +composeobject + + +foreground + + +background + + uncolor @@ -2727,6 +2741,18 @@ patterns. underline (highlighting underlined patterns in the body of messages) + +composeobject can be one of: + + + +header +security_encrypt +security_sign +security_both +security_none + + foreground and background can be one of the following: @@ -2841,6 +2867,17 @@ command. Usage: pattern +mono + + + + +composeobject + + +attribute + + unmono @@ -2864,8 +2901,9 @@ command. Usage: -For object, see the color -command. attribute can be one of the following: +For object and composeobject, +see the color command. attribute +can be one of the following: @@ -9502,6 +9540,20 @@ The following are the commands understood by Mutt: pattern +color + + + + +composeobject + + +foreground + + +background + + uncolor @@ -9845,6 +9897,17 @@ The following are the commands understood by Mutt: pattern +mono + + + + +composeobject + + +attribute + + unmono diff --git a/mutt_curses.h b/mutt_curses.h index 01faa1454..7373d542f 100644 --- a/mutt_curses.h +++ b/mutt_curses.h @@ -132,6 +132,11 @@ enum MT_COLOR_SB_INDICATOR, MT_COLOR_SB_SPOOLFILE, #endif + MT_COLOR_COMPOSE_HEADER, + MT_COLOR_COMPOSE_SECURITY_ENCRYPT, + MT_COLOR_COMPOSE_SECURITY_SIGN, + MT_COLOR_COMPOSE_SECURITY_BOTH, + MT_COLOR_COMPOSE_SECURITY_NONE, MT_COLOR_MAX }; -- 2.40.0