Tue Aug 18 00:42:33 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
[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 char metoo[10][128];
20 int mecount = 0;
21
22 extern char ALIASES[128];
23 extern char CIT86NET[128];
24 extern char SENDMAIL[128];
25 extern char FALLBACK[128];
26 extern char GW_DOMAIN[128];
27 extern char TABLEFILE[128];
28 extern int RUN_NETPROC;
29
30 void StripLeadingAndTrailingWhitespace(char *str) {
31         if (strlen(str) == 0) return;
32         while (isspace(str[0])) strcpy(str, &str[1]);
33         while (isspace(str[strlen(str)-1])) str[strlen(str)-1] = 0;
34         }
35
36 void LoadInternetConfig(void) {
37         char ParamName[256], ParamValue[256], buf[256];
38         FILE *conf;
39         int a, eqpos;
40
41
42         conf = fopen("network/internetmail.config", "r");
43         if (conf == NULL) {
44                 syslog(LOG_NOTICE, "Couldn't load internetmail.config");
45                 exit(1);
46                 }
47
48         while (fgets(buf, 256, conf) != NULL) {
49                 if (strlen(buf) > 0) buf[strlen(buf) - 1] = 0;
50                 strcpy(ParamName, "");
51                 strcpy(ParamValue, "");
52                 if (buf[0] != '#') {
53                         eqpos = (-1);
54                         for (a=strlen(buf); a>=0; --a) {
55                                 if (buf[a] == '=') eqpos = a;
56                                 }
57                         if (eqpos >= 0) {
58                                 strcpy(ParamName, buf);
59                                 ParamName[eqpos] = 0;
60                                 strcpy(ParamValue, &buf[eqpos+1]);
61                                 }
62
63                         StripLeadingAndTrailingWhitespace(ParamName);
64                         StripLeadingAndTrailingWhitespace(ParamValue);
65
66                         if (!strcasecmp(ParamName, "aliases"))
67                                 strcpy(ALIASES, ParamValue);
68                         if (!strcasecmp(ParamName, "cit86net spoolin"))
69                                 strcpy(CIT86NET, ParamValue);
70                         if (!strcasecmp(ParamName, "sendmail"))
71                                 strcpy(SENDMAIL, ParamValue);
72                         if (!strcasecmp(ParamName, "fallback"))
73                                 strcpy(FALLBACK, ParamValue);
74                         if (!strcasecmp(ParamName, "gateway domain"))
75                                 strcpy(GW_DOMAIN, ParamValue);
76                         if (!strcasecmp(ParamName, "table file"))
77                                 strcpy(TABLEFILE, ParamValue);
78                         if (!strcasecmp(ParamName, "deliver local"))
79                                 strcpy(metoo[mecount++], ParamValue);
80                         if (!strcasecmp(ParamName, "run netproc")) 
81                                 RUN_NETPROC = atoi(ParamValue);
82                         }
83                 }
84         fclose(conf);
85         }
86
87
88 /* 
89  * returns nonzero if the specified host is listed as local
90  */
91 int IsHostLocal(char *WhichHost) {
92         int a;
93
94         if (!strcasecmp(WhichHost, FQDN)) return(1);
95
96         if (mecount > 0) {
97                 for (a=0; a<mecount; ++a) {
98                         if (!strcasecmp(WhichHost, metoo[a])) return(1);
99                         }
100                 }
101         
102         return(0);
103         }