Commit 6682c0df 6682c0dfa63411d1c92a8e2de660d72979102662 by Sergey Poznyakoff

Initialization module.

1 parent 98a5981e
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 /* Initialize MH applications. */
19
20 #include <mh.h>
21 #include <pwd.h>
22
23 void
24 mh_init ()
25 {
26 list_t bookie;
27 registrar_get_list (&bookie);
28 list_append (bookie, mh_record);
29 list_append (bookie, mbox_record);
30 list_append (bookie, path_record);
31 list_append (bookie, pop_record);
32 list_append (bookie, imap_record);
33 /* Possible supported mailers. */
34 list_append (bookie, sendmail_record);
35 list_append (bookie, smtp_record);
36 }
37
38
39 static char *my_name;
40 static char *my_email;
41
42 /* FIXME: this lacks domain name part! */
43 void
44 mh_get_my_name (char *name)
45 {
46 char hostname[256];
47
48 if (!name)
49 {
50 struct passwd *pw = getpwuid (getuid ());
51 if (!pw)
52 {
53 mh_error ("can't determine my username");
54 return;
55 }
56 name = pw->pw_name;
57 }
58
59 my_name = strdup (name);
60 gethostname(hostname, sizeof(hostname));
61 hostname[sizeof(hostname)-1] = 0;
62 my_email = xmalloc (strlen (name) + strlen (hostname) + 2);
63 sprintf (my_email, "%s@%s", name, hostname);
64 }
65
66
67 int
68 mh_is_my_name (char *name)
69 {
70 if (!my_email)
71 mh_get_my_name (NULL);
72 return strcasecmp (name, my_email) == 0;
73 }
74