From: Ian Zimmerman Date: Tue, 18 Apr 2017 22:01:36 +0000 (-0700) Subject: fix broken from_chars behaviour X-Git-Tag: neomutt-20170421~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=98d402507a53c2d0f0b5b7f954f7fbcb4f303b85;p=neomutt fix broken from_chars behaviour Upstream adopted and extended the from_chars feature. A couple of changes to the behaviour were introduced by the change: - '\r' wasn't being recognised - An unwanted space was being displayed Fixes #533 --- diff --git a/hdrline.c b/hdrline.c index 725086fa5..f297e36e7 100644 --- a/hdrline.c +++ b/hdrline.c @@ -155,6 +155,27 @@ enum FieldType DISP_NUM }; +/** + * get_nth_wchar - Extract one char from a multi-byte table + * @table: Multi-byte table + * @index: Select this character + * @return: String pointer to the character + * + * Extract one multi-byte character from a string table. + * If the index is invalid, then a space character will be returned. + * If the character selected is '\n' (Ctrl-M), then "" will be returned. + */ +static char *get_nth_wchar(mbchar_table *table, int index) +{ + if (!table || !table->chars || (index < 0) || (index >= table->len)) + return " "; + + if (table->chars[index][0] == '\r') + return ""; + + return table->chars[index]; +} + /** * make_from_prefix - Create a prefix for an author field * @disp: Type of field @@ -165,14 +186,19 @@ enum FieldType */ 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] = ""}; - if (!Fromchars || (disp >= Fromchars->len)) + if (!Fromchars || !Fromchars->chars || (Fromchars->len == 0)) return long_prefixes[disp]; - snprintf(padded, sizeof(padded), "%s ", Fromchars->chars[disp]); + char *pchar = get_nth_wchar(Fromchars, disp); + if (mutt_strlen(pchar) == 0) + return ""; + + snprintf(padded, sizeof(padded), "%s ", pchar); return padded; } @@ -368,27 +394,6 @@ static bool get_initials(const char *name, char *buf, int buflen) return true; } -/** - * get_nth_wchar - Extract one char from a multi-byte table - * @table: Multi-byte table - * @index: Select this character - * @return: String pointer to the character - * - * Extract one multi-byte character from a string table. - * If the index is invalid, then a space character will be returned. - * If the character selected is '\n' (Ctrl-M), then "" will be returned. - */ -static char *get_nth_wchar(mbchar_table *table, int index) -{ - if (!table || !table->chars || (index < 0) || (index >= table->len)) - return " "; - - if (table->chars[index][0] == '\n') - return ""; - - return table->chars[index]; -} - static char *apply_subject_mods(ENVELOPE *env) { if (env == NULL)