summaryrefslogtreecommitdiff
path: root/mail/mutt/patches/patch-af
blob: e2eb53a4cd2d56e3fa67f95fee8c600bc0322d7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
$NetBSD: patch-af,v 1.1 2000/05/20 18:41:43 kim Exp $

--- muttlib.c	2000/05/16 15:23:02	2.19
+++ muttlib.c	2000/05/20 07:46:06
@@ -33,10 +33,12 @@
 #include <stdlib.h>
 #include <sys/wait.h>
 #include <errno.h>
-#include <pwd.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 
+#define MIN(a,b) ((a) < (b) ? (a) : (b))
+#define MAX(a,b) ((a) < (b) ? (b) : (a))
+
 BODY *mutt_new_body (void)
 {
   BODY *p = (BODY *) safe_calloc (1, sizeof (BODY));
@@ -452,6 +454,46 @@
   return (s);
 }
 
+
+char *mutt_gecos_name (char *dest, size_t destlen, struct passwd *pw)
+{
+  regmatch_t pat_match[1];
+  size_t pwnl;
+  int idx;
+  char *p;
+  
+  if (!pw || !pw->pw_gecos) 
+    return NULL;
+
+  memset (dest, 0, destlen);
+  
+  if (GecosMask.rx)
+  {
+    if (regexec (GecosMask.rx, pw->pw_gecos, 1, pat_match, 0) == 0)
+      strfcpy (dest, pw->pw_gecos + pat_match[0].rm_so, 
+	       MIN (pat_match[0].rm_eo - pat_match[0].rm_so + 1, destlen));
+  }
+  else if ((p = strchr (pw->pw_gecos, ',')))
+    strfcpy (dest, pw->pw_gecos, MIN (destlen, p - pw->pw_gecos + 1));
+  else
+    strfcpy (dest, pw->pw_gecos, destlen);
+
+  pwnl = strlen (pw->pw_name);
+
+  for (idx = 0; dest[idx]; idx++)
+  {
+    if (dest[idx] == '&')
+    {
+      memmove (&dest[idx + pwnl], &dest[idx + 1],
+	       MAX(destlen - idx - pwnl - 1, 0));
+      memcpy (&dest[idx], pw->pw_name, MIN(destlen - idx - 1, pwnl));
+      dest[idx] = toupper (dest[idx]);
+    }
+  }
+      
+  return dest;
+}
+  
 
 char *mutt_get_parameter (const char *s, PARAMETER *p)
 {