* serv_smtp.c: implement RFC2920 ESMTP "pipelining" extension on the server
[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
14 #if TIME_WITH_SYS_TIME
15 # include <sys/time.h>
16 # include <time.h>
17 #else
18 # if HAVE_SYS_TIME_H
19 #  include <sys/time.h>
20 # else
21 #  include <time.h>
22 # endif
23 #endif
24
25 #include <string.h>
26 #include <ctype.h>
27 #include <syslog.h>
28 #include "citadel.h"
29
30 extern struct config config;
31
32 char metoo[10][128];
33 int mecount = 0;
34
35 extern char ALIASES[128];
36 extern char CIT86NET[128];
37 extern char SENDMAIL[128];
38 extern char FALLBACK[128];
39 extern char GW_DOMAIN[128];
40 extern char TABLEFILE[128];
41 extern int RUN_NETPROC;
42
43 void StripLeadingAndTrailingWhitespace(char *str)
44 {
45         if (strlen(str) == 0)
46                 return;
47         while (isspace(str[0]))
48                 strcpy(str, &str[1]);
49         while (isspace(str[strlen(str) - 1]))
50                 str[strlen(str) - 1] = 0;
51 }
52
53 void LoadInternetConfig(void)
54 {
55         char ParamName[SIZ], ParamValue[SIZ], buf[SIZ];
56         FILE *conf;
57         int a, eqpos;
58
59
60         conf = fopen("network/internetmail.config", "r");
61         if (conf == NULL) {
62                 syslog(LOG_NOTICE, "Couldn't load internetmail.config");
63                 exit(1);
64         }
65         while (fgets(buf, sizeof buf, conf) != NULL) {
66                 if (strlen(buf) > 0)
67                         buf[strlen(buf) - 1] = 0;
68                 strcpy(ParamName, "");
69                 strcpy(ParamValue, "");
70                 if (buf[0] != '#') {
71                         eqpos = (-1);
72                         for (a = strlen(buf); a >= 0; --a) {
73                                 if (buf[a] == '=')
74                                         eqpos = a;
75                         }
76                         if (eqpos >= 0) {
77                                 strcpy(ParamName, buf);
78                                 ParamName[eqpos] = 0;
79                                 strcpy(ParamValue, &buf[eqpos + 1]);
80                         }
81                         StripLeadingAndTrailingWhitespace(ParamName);
82                         StripLeadingAndTrailingWhitespace(ParamValue);
83
84                         if (!strcasecmp(ParamName, "aliases"))
85                                 strcpy(ALIASES, ParamValue);
86                         if (!strcasecmp(ParamName, "cit86net spoolin"))
87                                 strcpy(CIT86NET, ParamValue);
88                         if (!strcasecmp(ParamName, "sendmail"))
89                                 strcpy(SENDMAIL, ParamValue);
90                         if (!strcasecmp(ParamName, "fallback"))
91                                 strcpy(FALLBACK, ParamValue);
92                         if (!strcasecmp(ParamName, "gateway domain"))
93                                 strcpy(GW_DOMAIN, ParamValue);
94                         if (!strcasecmp(ParamName, "table file"))
95                                 strcpy(TABLEFILE, ParamValue);
96                         if (!strcasecmp(ParamName, "deliver local"))
97                                 strcpy(metoo[mecount++], ParamValue);
98                         if (!strcasecmp(ParamName, "run netproc"))
99                                 RUN_NETPROC = atoi(ParamValue);
100                 }
101         }
102         fclose(conf);
103 }
104
105
106 /* 
107  * returns nonzero if the specified host is listed as local
108  */
109 int IsHostLocal(char *WhichHost)
110 {
111         int a;
112
113         if (!strcasecmp(WhichHost, FQDN))
114                 return (1);
115
116         if (mecount > 0) {
117                 for (a = 0; a < mecount; ++a) {
118                         if (!strcasecmp(WhichHost, metoo[a]))
119                                 return (1);
120                 }
121         }
122         return (0);
123 }