]> granicus.if.org Git - mutt/commitdiff
William Feavish's GECOS regexp patch.
authorThomas Roessler <roessler@does-not-exist.org>
Sat, 4 Dec 1999 09:37:20 +0000 (09:37 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Sat, 4 Dec 1999 09:37:20 +0000 (09:37 +0000)
alias.c
init.h
mutt_regex.h

diff --git a/alias.c b/alias.c
index 093455b7117623184dc55df3c575c3524c5cf56e..7a27b71d382ae76fe1ce1ddd4a2bde233920cc7d 100644 (file)
--- 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 2fa5385d4bf4b0c7c08eae372e6b673ad35f8394..9895783d72248724f3bb9dbfea353493e2e23a44 100644 (file)
--- 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 },
   /*
   */
index 290454a7464d0ae30ce10b795e0d1c397d9b056a..8f17d0fd1c7787630434604abb3674862b872145 100644 (file)
@@ -51,5 +51,6 @@ WHERE REGEXP Mask;
 WHERE REGEXP QuoteRegexp;
 WHERE REGEXP ReplyRegexp;
 WHERE REGEXP Smileys;
+WHERE REGEXP GecosMask;
 
 #endif /* MUTT_REGEX_H */