From bf5a271200174642196d0870435bf1b3b02bee03 Mon Sep 17 00:00:00 2001 From: Thomas Roessler Date: Sat, 4 Dec 1999 09:37:20 +0000 Subject: [PATCH] William Feavish's GECOS regexp patch. --- alias.c | 21 ++++++++++++++++----- init.h | 9 +++++++++ mutt_regex.h | 1 + 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/alias.c b/alias.c index 093455b7..7a27b71d 100644 --- a/alias.c +++ b/alias.c @@ -83,14 +83,25 @@ static ADDRESS *mutt_expand_aliases_r (ADDRESS *a, LIST **expn) else { struct passwd *pw = getpwnam (a->mailbox); - char buffer[256], *p; if (pw) { - strfcpy (buffer, pw->pw_gecos, sizeof (buffer)); - if ((p = strchr (buffer, ','))) - *p = 0; - a->personal = safe_strdup (buffer); + regmatch_t pat_match[1]; + + /* Use regular expression to parse Gecos field. This result of the + * parsing will be used as the personal ID string when the alias is + * expaned. + */ + if (regexec (GecosMask.rx, pw->pw_gecos, 1, pat_match, 0) == 0) + { + /* Malloc enough for the matching pattern + terminating NULL */ + a->personal = safe_malloc ((pat_match[0].rm_eo - + pat_match[0].rm_so) + 1); + + strfcpy (a->personal, pw->pw_gecos + pat_match[0].rm_so, + pat_match[0].rm_eo - pat_match[0].rm_so + 1); + } + #ifdef EXACT_ADDRESS FREE (&a->val); #endif diff --git a/init.h b/init.h index 2fa5385d..9895783d 100644 --- a/init.h +++ b/init.h @@ -531,6 +531,15 @@ struct option_t MuttVars[] = { ** can be overridden using my_hdr (including from send-hooks) and ** ``$reverse_name''. */ + { "gecos_mask", DT_RX, R_NONE, UL &GecosMask, UL "^[^,]*" }, + /* + ** .pp + ** A regular expression used by mutt to parse the GECOS field of a password + ** entry when expanding the alias. By default the regular expression is set + ** to "^[^,]*" which will return the string up to the first "," encountered. + ** If the GECOS field contains a string like "lastname, firstname" then you + ** should set the gecos_regexp=".*". + */ { "hdr_format", DT_SYN, R_NONE, UL "index_format", 0 }, /* */ diff --git a/mutt_regex.h b/mutt_regex.h index 290454a7..8f17d0fd 100644 --- a/mutt_regex.h +++ b/mutt_regex.h @@ -51,5 +51,6 @@ WHERE REGEXP Mask; WHERE REGEXP QuoteRegexp; WHERE REGEXP ReplyRegexp; WHERE REGEXP Smileys; +WHERE REGEXP GecosMask; #endif /* MUTT_REGEX_H */ -- 2.49.0