]> code.citadel.org Git - citadel.git/blob - citadel/mailinglist.c
Changed all of the proprietary strucmp() and struncmp() calls to the more
[citadel.git] / citadel / mailinglist.c
1 /*
2  * mailinglist.c
3  *
4  * This program is designed to be a filter which allows two-way interaction
5  * between a traditional e-mail mailing list and a Citadel room.
6  *
7  * It only handles the outbound side.  The inbound side is handled by the
8  * Citadel e-mail gateway.  You should subscribe rooms to lists using the
9  * "room_roomname@node.dom" type address.
10  * 
11  * Since some listprocs only accept postings from subscribed addresses, the
12  * messages which this program converts will all appear to be from the room
13  * address; however, the full name of the sender is set to the Citadel user
14  * name of the real message author.
15  * 
16  * To prevent loops, this program only sends messages originating on the local
17  * system.  Therefore it is not possible to carry a two-way mailing list room
18  * on a Citadel network.
19  */
20
21 #include <stdlib.h>
22 #include <unistd.h>
23 #include <stdio.h>
24 #include <syslog.h>
25 #include "citadel.h"
26
27 void LoadInternetConfig();
28 void get_config();
29 struct config config;
30
31 char ALIASES[128];
32 char CIT86NET[128];
33 char SENDMAIL[128];
34 char FALLBACK[128];
35 char GW_DOMAIN[128];
36 char TABLEFILE[128];
37 char OUTGOING_FQDN[128];
38 int RUN_NETPROC = 1;
39
40 /* 
41  * Consult the mailinglists table to find out where we should send the
42  * mailing list postings to.
43  */
44 void xref(room,listaddr)                /* xref table */
45 char room[]; 
46 char listaddr[]; {
47         FILE *fp;
48         int a;
49         char buf[128];
50         
51         strcpy(listaddr, "");
52         fp=fopen(TABLEFILE, "r");
53         while (fgets(buf,128,fp)!=NULL) {
54                 buf[strlen(buf)-1]=0;
55                 for (a=0; a<strlen(buf); ++a) {
56                         if ( (buf[a]==',') && (!strcasecmp(&buf[a+1],room)) ) {
57                                 strcpy(listaddr,buf);
58                                 listaddr[a] = 0;
59                                 }
60                         }
61                 }
62         fclose(fp);
63         return;
64         }
65
66
67 /*
68  * The main loop.  We don't need any command-line parameters to this program.
69  */
70 void main() {
71
72         char header[3];
73         char fields[32][1024];
74         int num_fields;
75         int ch, p, a;
76         int in_header;
77         int is_good;
78         char listaddr[512];
79         char mailcmd[256];
80         FILE *nm;
81         char tempfile[64];
82
83         get_config();
84         LoadInternetConfig();
85         sprintf(tempfile, "/tmp/mlist.%d", getpid() );
86
87         while(1) {
88
89                 /* seek to the next message */
90                 is_good = 0;
91                 do {
92                         if (feof(stdin)) {
93                                 unlink(tempfile);
94                                 exit(0);
95                                 }
96                         } while (getc(stdin) != 255);
97
98                 header[0] = 255;
99                 header[1] = getc(stdin);
100                 header[2] = getc(stdin);
101                 in_header = 1;
102                 num_fields = 0;
103
104                 do {
105                         fields[num_fields][0] = getc(stdin);
106                         if (fields[num_fields][0] != 'M') {
107                                 p = 1;
108                                 do {
109                                         ch = getc(stdin);
110                                         fields[num_fields][p++] = ch;
111                                         } while ((ch!=0) && (!feof(stdin)));
112                                 if (fields[num_fields][0] == 'N') {
113                                         if (!strcmp(&fields[num_fields][1],
114                                                 NODENAME)) {
115                                                         is_good = 1;
116                                                         }
117                                         }
118                                 if (fields[num_fields][0] == 'O') {
119                                         xref(&fields[num_fields][1], listaddr);
120                                         }
121                                 if (fields[num_fields][0]!='R') ++num_fields;
122                                 }
123                         else {
124                                 /* flush the message out to the next program */
125
126                                 nm =  fopen(tempfile, "wb");
127                                 fprintf(nm, "%c%c%c",
128                                         header[0], header[1], header[2]);
129                                 for (a=0; a<num_fields; ++a) {
130                                         fprintf(nm, "%s%c", &fields[a][0], 0);
131                                         }
132                                 fprintf(nm, "R%s%c", listaddr, 0);
133                         
134                                 putc('M', nm);
135                                 do {
136                                         ch = getc(stdin);
137                                         putc(ch, nm);
138                                         } while ((ch!=0) && (!feof(stdin)));
139                                 in_header = 0;
140                                 fclose(nm);
141                                 if (is_good) {
142                                         sprintf(mailcmd, "exec netmailer %s mlist", tempfile);
143                                         system(mailcmd);
144                                         is_good = 0;
145                                         }
146                                 }
147                         } while (in_header);
148                 }
149         }