Commit 926bc7a9 926bc7a99755dc3ed99a39a999caf7016f558de6 by Sergey Poznyakoff

Honour "metoo" variable. Try to determine user's full email address.

1 parent 20b323c9
...@@ -16,8 +16,11 @@ ...@@ -16,8 +16,11 @@
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ 16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17 17
18 #include "mail.h" 18 #include "mail.h"
19 #include <pwd.h>
19 20
20 static list_t alternate_names = NULL; 21 static list_t alternate_names = NULL;
22 static char *my_email;
23 static char *my_name;
21 24
22 /* 25 /*
23 * alt[ernates] name... 26 * alt[ernates] name...
...@@ -43,8 +46,49 @@ mail_alt (int argc, char **argv) ...@@ -43,8 +46,49 @@ mail_alt (int argc, char **argv)
43 return 0; 46 return 0;
44 } 47 }
45 48
49 char *
50 mail_whoami ()
51 {
52 return my_name;
53 }
54
55 /* FIXME: this lacks domain name part! */
56 void
57 mail_set_my_name (char *name)
58 {
59 char hostname[256];
60
61 if (!name)
62 {
63 struct passwd *pw = getpwuid(getuid());
64 if (!pw)
65 {
66 util_error("can't determine my username");
67 exit (1);
68 }
69 name = pw->pw_name;
70 }
71
72 my_name = strdup (name);
73 gethostname(hostname, sizeof(hostname));
74 hostname[sizeof(hostname)-1] = 0;
75 my_email = malloc (strlen (name) + strlen (hostname) + 2);
76 if (!my_email)
77 {
78 util_error("not enough memory");
79 abort ();
80 }
81 sprintf (my_email, "%s@%s", name, hostname);
82 }
83
46 int 84 int
47 mail_is_alt_name (char *name) 85 mail_is_my_name (char *name)
48 { 86 {
87 if (util_find_env("metoo")->set)
88 return 0;
89 if (strchr(name, '@') == NULL && strcasecmp (name, my_name) == 0)
90 return 1;
91 if (strcasecmp (name, my_email) == 0)
92 return 1;
49 return util_slist_lookup (alternate_names, name); 93 return util_slist_lookup (alternate_names, name);
50 } 94 }
......