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