861aeb5c2bd194cd5f6ed703c6253b0f7bf981ed
[citadel.git] / citadel / internetmail.c
1 /*
2  * $Id$
3  *
4  * Internet mail configurator for Citadel/UX
5  * see copyright.doc for copyright information
6  *
7  */
8
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <stdio.h>
12 #include <fcntl.h>
13 #include <time.h>
14 #include <string.h>
15 #include <ctype.h>
16 #include <syslog.h>
17 #include "citadel.h"
18
19 extern struct config config;
20
21 char metoo[10][128];
22 int mecount = 0;
23
24 extern char ALIASES[128];
25 extern char CIT86NET[128];
26 extern char SENDMAIL[128];
27 extern char FALLBACK[128];
28 extern char GW_DOMAIN[128];
29 extern char TABLEFILE[128];
30 extern int RUN_NETPROC;
31
32 void StripLeadingAndTrailingWhitespace(char *str)
33 {
34         if (strlen(str) == 0)
35                 return;
36         while (isspace(str[0]))
37                 strcpy(str, &str[1]);
38         while (isspace(str[strlen(str) - 1]))
39                 str[strlen(str) - 1] = 0;
40 }
41
42 void LoadInternetConfig(void)
43 {
44         char ParamName[SIZ], ParamValue[SIZ], buf[SIZ];
45         FILE *conf;
46         int a, eqpos;
47
48
49         conf = fopen("network/internetmail.config", "r");
50         if (conf == NULL) {
51                 syslog(LOG_NOTICE, "Couldn't load internetmail.config");
52                 exit(1);
53         }
54         while (fgets(buf, sizeof buf, conf) != NULL) {
55                 if (strlen(buf) > 0)
56                         buf[strlen(buf) - 1] = 0;
57                 strcpy(ParamName, "");
58                 strcpy(ParamValue, "");
59                 if (buf[0] != '#') {
60                         eqpos = (-1);
61                         for (a = strlen(buf); a >= 0; --a) {
62                                 if (buf[a] == '=')
63                                         eqpos = a;
64                         }
65                         if (eqpos >= 0) {
66                                 strcpy(ParamName, buf);
67                                 ParamName[eqpos] = 0;
68                                 strcpy(ParamValue, &buf[eqpos + 1]);
69                         }
70                         StripLeadingAndTrailingWhitespace(ParamName);
71                         StripLeadingAndTrailingWhitespace(ParamValue);
72
73                         if (!strcasecmp(ParamName, "aliases"))
74                                 strcpy(ALIASES, ParamValue);
75                         if (!strcasecmp(ParamName, "cit86net spoolin"))
76                                 strcpy(CIT86NET, ParamValue);
77                         if (!strcasecmp(ParamName, "sendmail"))
78                                 strcpy(SENDMAIL, ParamValue);
79                         if (!strcasecmp(ParamName, "fallback"))
80                                 strcpy(FALLBACK, ParamValue);
81                         if (!strcasecmp(ParamName, "gateway domain"))
82                                 strcpy(GW_DOMAIN, ParamValue);
83                         if (!strcasecmp(ParamName, "table file"))
84                                 strcpy(TABLEFILE, ParamValue);
85                         if (!strcasecmp(ParamName, "deliver local"))
86                                 strcpy(metoo[mecount++], ParamValue);
87                         if (!strcasecmp(ParamName, "run netproc"))
88                                 RUN_NETPROC = atoi(ParamValue);
89                 }
90         }
91         fclose(conf);
92 }
93
94
95 /* 
96  * returns nonzero if the specified host is listed as local
97  */
98 int IsHostLocal(char *WhichHost)
99 {
100         int a;
101
102         if (!strcasecmp(WhichHost, FQDN))
103                 return (1);
104
105         if (mecount > 0) {
106                 for (a = 0; a < mecount; ++a) {
107                         if (!strcasecmp(WhichHost, metoo[a]))
108                                 return (1);
109                 }
110         }
111         return (0);
112 }