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