Now, citmail.c doesn't attempt to read the userlog directly. This is a
[citadel.git] / citadel / citmail.c
1 /*
2  * citmail.c v4.0
3  *
4  * This program may be used as a local mail delivery agent, which will allow
5  * all Citadel users to receive Internet e-mail.  To enable this functionality,
6  * you must tell sendmail, smail, or whatever mailer you are using, that this
7  * program is your local mail delivery agent.  This program is a direct
8  * replacement for lmail, deliver, or whatever.
9  *
10  * Usage:
11  *
12  * citmail <recipient>       - Deliver a message
13  * citmail -t <recipient>    - Address test mode (will not deliver)
14  * citmail -i                - Run as an SMTP daemon (typically from inetd)
15  *
16  */
17
18 #include "sysdep.h"
19 #include <stdlib.h>
20 #include <unistd.h>
21 #include <stdio.h>
22 #include <fcntl.h>
23 #include <ctype.h>
24 #include <string.h>
25 #include <time.h>
26 #include <pwd.h>
27 #include <errno.h>
28 #include <syslog.h>
29 #include "citadel.h"
30
31 #define LOCAL 0
32 #define REMOTE 1
33 #define UUCP 2
34 #define CCITADEL 3
35
36 #undef tolower
37 #define tolower(x) isupper(x) ? (x+'a'-'A') : x
38
39 char *monthdesc[] = {   "Jan","Feb","Mar","Apr","May","Jun",
40                         "Jul","Aug","Sep","Oct","Nov","Dec" };
41
42
43
44 void LoadInternetConfig();
45 void get_config();
46 int IsHostLocal();
47 struct config config;
48
49 char ALIASES[128];
50 char CIT86NET[128];
51 char SENDMAIL[128];
52 char FALLBACK[128];
53 char GW_DOMAIN[128];
54 char TABLEFILE[128];
55 char OUTGOING_FQDN[128];
56 int RUN_NETPROC = 1;
57
58 int struncmp(lstr,rstr,l)
59 char lstr[],rstr[]; {
60         int pos = 0;
61         char lc,rc;
62         while (1) {
63                 if (pos==l) return(0);
64                 lc=tolower(lstr[pos]);
65                 rc=tolower(rstr[pos]);
66                 if ((lc==0)&&(rc==0)) return(0);
67                 if (lc<rc) return(-1);
68                 if (lc>rc) return(1);
69                 pos=pos+1;
70                 }
71         }
72
73 long conv_date(sdbuf)
74 char sdbuf[]; {
75         int a,b,cpos,tend,tval;
76         long now;
77         struct tm *tmbuf;
78         char dbuf[128];
79
80         strcpy(dbuf,sdbuf);
81         time(&now);
82         tmbuf = (struct tm *)localtime(&now);
83
84         /* get rid of + or - timezone mods */
85         for (a=0; a<strlen(dbuf); ++a) 
86                 if ((dbuf[a]=='+')||(dbuf[a]=='-'))
87                         do {
88                                 strcpy(&dbuf[a],&dbuf[a+1]);
89                                 } while ((dbuf[a]!=32)&&(dbuf[a]!=0));
90
91         /* try and extract the time by looking for colons */
92         cpos = (-1);
93         for (a=strlen(dbuf); a>=0; --a)
94                 if ((dbuf[a]==':')&&(atoi(&dbuf[a-1])!=0)) cpos=a;
95         if (cpos>=0) {
96                 cpos = cpos - 2;
97                 tend = strlen(dbuf);
98                 for (a=tend; a>=cpos; --a) if (dbuf[a]==' ') tend=a;
99
100                 tmbuf->tm_hour = atoi(&dbuf[cpos]);
101                 tmbuf->tm_min = atoi(&dbuf[cpos+3]);
102                 tmbuf->tm_sec = atoi(&dbuf[cpos+6]);
103
104                 do {
105                         strcpy(&dbuf[cpos],&dbuf[cpos+1]);
106                         } while ((dbuf[cpos]!=32)&&(dbuf[cpos]!=0));
107                 }
108
109         /* next try to extract a month */
110         
111         tval = (-1);
112         for (a=0; a<strlen(dbuf); ++a)
113                 for (b=0; b<12; ++b)
114                         if (!strncmp(&dbuf[a],monthdesc[b],3)) {
115                                 tval = b;
116                                 cpos = a;
117                                 }
118         if (tval >= 0) {
119                 tmbuf->tm_mon = tval;
120                 strcpy(&dbuf[cpos],&dbuf[cpos+3]);
121                 }
122
123         /* now the year */
124
125         for (a=0; a<strlen(dbuf); ++a)
126                 if ((atoi(&dbuf[a])>=1900) && (dbuf[a]!=32)) {
127                         tmbuf->tm_year = atoi(&dbuf[a]) - 1900;
128                         strcpy(&dbuf[a],&dbuf[a+4]);
129                         }
130
131         /* whatever's left is the mday (hopefully) */
132
133         for (a=0; a<strlen(dbuf); ++a)
134                 if ((dbuf[a]!=32)&&(atoi(&dbuf[a])>=1)&&(atoi(&dbuf[a])<=31)
135                    && ( (a==0)||(dbuf[a-1]==' ') ) ) {
136                         tmbuf->tm_mday = atoi(&dbuf[a]);
137                         strcpy(&dbuf[a],&dbuf[a+2]);
138                         }
139
140         return((long)mktime(tmbuf));
141         }
142
143
144 #ifdef NO_STRERROR
145 /*
146  * replacement strerror() for systems that don't have it
147  */
148 char *strerror(e)
149 int e; {
150         static char buf[32];
151
152         sprintf(buf,"errno = %d",e);
153         return(buf);
154         }
155 #endif
156
157 int haschar(st,ch)
158 char st[];
159 int ch; {
160         int a,b;
161         b=0;
162         for (a=0; a<strlen(st); ++a) if (st[a]==ch) ++b;
163         return(b);
164         }
165
166 void strip_trailing_whitespace(buf)
167 char buf[]; {
168         while(isspace(buf[strlen(buf)-1]))
169                 buf[strlen(buf)-1]=0;
170         }
171
172 /* strip leading and trailing spaces */
173 void striplt(buf)
174 char buf[]; {
175         while ( (strlen(buf)>0) && (buf[0]==32) ) strcpy(buf,&buf[1]);
176         while (buf[strlen(buf)-1] == 32) buf[strlen(buf)-1] = 0;
177         }
178
179
180 /*
181  * Check to see if a given FQDN really maps to a Citadel network node
182  */
183 void host_alias(char host[]) {
184
185         int a;
186
187         /* What name is the local host known by? */
188         /* if (!strucmp(host, config.c_fqdn)) { */
189         if (IsHostLocal(host)) {
190                 strcpy(host, config.c_nodename);
191                 return;
192                 }
193
194         /* Other hosts in the gateway domain? */
195         for (a=0; a<strlen(host); ++a) {
196                 if ((host[a]=='.') && (!strucmp(&host[a+1], GW_DOMAIN))) {
197                         host[a] = 0;
198                         for (a=0; a<strlen(host); ++a) {
199                                 if (host[a]=='.') host[a] = 0;
200                                 }
201                         return;
202                         }
203                 }
204
205         /* Otherwise, do nothing... */
206         }
207
208
209
210 /*
211  * Split an RFC822-style address into userid, host, and full name
212  */
213 void process_rfc822_addr(rfc822,user,node,name)
214 char rfc822[];
215 char user[];
216 char node[];
217 char name[];  {
218         int a;
219
220         /* extract full name - first, it's From minus <userid> */
221         strcpy(name,rfc822);
222         for (a=0; a<strlen(name); ++a) if (name[a]=='<') {
223                 do {
224                         strcpy(&name[a],&name[a+1]);
225                         } while ( (strlen(name) > 0) && (name[a]!='>') );
226                 strcpy(&name[a],&name[a+1]);
227                 }
228
229         /* strip anything to the left of a bang */
230         while ( (strlen(name)>0) && (haschar(name,'!')>0) ) 
231                 strcpy(name,&name[1]);
232
233         /* and anything to the right of a @ or % */
234         for (a=0; a<strlen(name); ++a) {
235                 if (name[a]=='@') name[a]=0;
236                 if (name[a]=='%') name[a]=0;
237                 }
238
239         /* but if there are parentheses, that changes the rules... */
240         if ( (haschar(rfc822,'(') == 1) && (haschar(rfc822,')') == 1) ) {
241                 strcpy(name,rfc822);
242                 while ( (strlen(name) > 0) && (name[0]!='(') ) {
243                         strcpy(&name[0],&name[1]);
244                         }
245                 strcpy(&name[0],&name[1]);
246                 for (a=0; a<strlen(name); ++a)
247                          if (name[a]==')') name[a]=0;
248                 }
249
250         /* but if there are a set of quotes, that supersedes everything */
251         if (haschar(rfc822,34)==2) {
252                 strcpy(name,rfc822);
253                 while ( (strlen(name) > 0) && (name[0]!=34) ) {
254                         strcpy(&name[0],&name[1]);
255                         }
256                 strcpy(&name[0],&name[1]);
257                 for (a=0; a<strlen(name); ++a)
258                         if (name[a]==34) name[a]=0;
259                 }
260
261         /* extract user id */
262         strcpy(user,rfc822);
263
264         /* first get rid of anything in parens */
265         for (a=0; a<strlen(user); ++a) if (user[a]=='(') {
266                 do {
267                         strcpy(&user[a],&user[a+1]);
268                         } while ( (strlen(user) > 0) && (user[a]!=')') );
269                 strcpy(&user[a],&user[a+1]);
270                 }
271
272         /* if there's a set of angle brackets, strip it down to that */
273         if ( (haschar(user,'<') == 1) && (haschar(user,'>') == 1) ) {
274                 while ( (strlen(user) > 0) && (user[0]!='<') ) {
275                         strcpy(&user[0],&user[1]);
276                         }
277                 strcpy(&user[0],&user[1]);
278                 for (a=0; a<strlen(user); ++a)
279                          if (user[a]=='>') user[a]=0;
280                 }
281
282         /* strip anything to the left of a bang */
283         while ( (strlen(user)>0) && (haschar(user,'!')>0) ) 
284                 strcpy(user,&user[1]);
285
286         /* and anything to the right of a @ or % */
287         for (a=0; a<strlen(user); ++a) {
288                 if (user[a]=='@') user[a]=0;
289                 if (user[a]=='%') user[a]=0;
290                 }
291
292
293         
294         /* extract node name */
295         strcpy(node, rfc822);
296
297         /* first get rid of anything in parens */
298         for (a=0; a<strlen(node); ++a) if (node[a]=='(') {
299                 do {
300                         strcpy(&node[a],&node[a+1]);
301                         } while ( (strlen(node) > 0) && (node[a]!=')') );
302                 strcpy(&node[a],&node[a+1]);
303                 }
304
305         /* if there's a set of angle brackets, strip it down to that */
306         if ( (haschar(node,'<') == 1) && (haschar(node,'>') == 1) ) {
307                 while ( (strlen(node) > 0) && (node[0]!='<') ) {
308                         strcpy(&node[0],&node[1]);
309                         }
310                 strcpy(&node[0],&node[1]);
311                 for (a=0; a<strlen(node); ++a)
312                          if (node[a]=='>') node[a]=0;
313                 }
314
315         /* strip anything to the left of a @ */
316         while ( (strlen(node)>0) && (haschar(node,'@')>0) ) 
317                 strcpy(node,&node[1]);
318
319         /* strip anything to the left of a % */
320         while ( (strlen(node)>0) && (haschar(node,'%')>0) ) 
321                 strcpy(node,&node[1]);
322
323         /* reduce multiple system bang paths to node!user */
324         while ( (strlen(node)>0) && (haschar(node,'!')>1) ) 
325                 strcpy(node,&node[1]);
326
327         /* now get rid of the user portion of a node!user string */
328         for (a=0; a<strlen(node); ++a) if (node[a]=='!') node[a]=0;
329
330
331
332         /* strip leading and trailing spaces in all strings */
333         striplt(user);
334         striplt(node);
335         striplt(name);
336         }
337
338 /*
339  * Copy line by line, ending at EOF or a "." 
340  */
341 void loopcopy(FILE *to, FILE *from) {
342         char buf[1024];
343         char *r;
344         
345         while (1) {
346                 r = fgets(buf, sizeof(buf), from);
347                 if (r == NULL) return;
348                 strip_trailing_whitespace(buf);
349                 if (!strcmp(buf, ".")) return;
350                 fprintf(to, "%s\n", buf);
351                 }
352         }
353
354
355 /*
356  * pipe message through netproc
357  */
358 void do_citmail(char recp[], int dtype) {
359
360         long now;
361         FILE *temp;
362         int a;
363         char buf[128];
364         char from[512];
365         char userbuf[256];
366         char frombuf[256];
367         char nodebuf[256];
368         char destsys[256];
369         char subject[256];
370
371
372         if (dtype==REMOTE) {
373
374                 /* get the Citadel node name out of the path */
375                 strncpy(destsys, recp, sizeof(destsys) );
376                 for (a=0; a<strlen(destsys); ++a) {
377                         if ((destsys[a]=='!')||(destsys[a]=='.')) {
378                                 destsys[a]=0;
379                                 }
380                         }
381
382                 /* chop the system name out, so we're left with a user */
383                 while (haschar(recp,'!')) strcpy(recp,&recp[1]);
384
385                 /* now convert underscores to spaces */
386                 for (a=0; a<strlen(recp); ++a) if (recp[a]=='_') recp[a]=' ';
387
388                 }
389
390         time(&now);
391         sprintf(from, "postmaster@%s", config.c_nodename);
392
393         sprintf(buf, "./network/spoolin/citmail.%d", getpid());
394         temp = fopen(buf,"w");
395
396         putc(255,temp); putc(MES_NORMAL,temp); putc(1,temp);
397         strcpy(subject,"");
398         strcpy(nodebuf, config.c_nodename);
399         do {
400                 if (fgets(buf,128,stdin) == NULL) strcpy(buf, ".");
401                 strip_trailing_whitespace(buf);
402
403                 if (!strncmp(buf,"Subject: ",9)) strcpy(subject,&buf[9]);
404                 if (!strncmp(buf,"Date: ",6)) now = conv_date(&buf[6]);
405                 if (!strncmp(buf,"From: ",6)) strcpy(from, &buf[6]);
406                 } while ( (strcmp(buf, ".")) && (strcmp(buf, "")) );
407
408         process_rfc822_addr(from, userbuf, nodebuf, frombuf);
409
410         /* now convert it to Citadel format */
411         fprintf(temp,"P%s@%s%c", userbuf, nodebuf, 0);
412         fprintf(temp,"E%s%c", userbuf, 0);
413         fprintf(temp,"T%ld%c", now, 0);
414         fprintf(temp,"A%s%c", frombuf, 0);
415         fprintf(temp,"OMail%c", 0);
416         fprintf(temp,"N%s%c", nodebuf, 0);
417         if (dtype==REMOTE) {
418                 fprintf(temp,"D%s%c", destsys, 0);
419                 }
420         fprintf(temp,"R%s%c", recp, 0);
421         if (strlen(subject)>0) {
422                 fprintf(temp,"U%s%c", subject, 0);
423                 }
424         putc('M',temp);
425         if (strcmp(buf, ".")) loopcopy(temp, stdin);
426         putc(0,temp);
427         fclose(temp);
428         }
429
430 void do_roommail(recp)  /* pipe public message through netproc */
431 char recp[]; {
432         long now;
433         FILE *temp;
434         int a;
435         char buf[128],userbuf[128],frombuf[128],nodebuf[128];
436         char subject[128], from[256];
437
438         strcpy(subject,"");
439         sprintf(from, "postmaster@%s", config.c_nodename);
440         strcpy(recp,&recp[5]);
441         for (a=0; a<strlen(recp); ++a) if (recp[a]=='_') recp[a]=32;
442         time(&now);
443
444
445         sprintf(buf,"./network/spoolin/citmail.%d",getpid());
446         temp = fopen(buf,"w");
447
448         putc(255,temp); putc(MES_NORMAL,temp); putc(1,temp);
449         strcpy(frombuf,"Internet Mail Gateway");
450         strcpy(nodebuf, config.c_nodename);
451         do {
452                 if (fgets(buf,128,stdin) == NULL) strcpy(buf, ".");
453                 strip_trailing_whitespace(buf);
454
455                 if (!strncmp(buf,"Subject: ",9)) strcpy(subject,&buf[9]);
456                 if (!strncmp(buf,"Date: ",6)) now = conv_date(&buf[6]);
457                 if (!strncmp(buf,"From: ",6)) strcpy(from, &buf[6]);
458                 } while ( (strcmp(buf, ".")) && (strcmp(buf, "")) );
459
460         process_rfc822_addr(from, userbuf, nodebuf, frombuf);
461
462         fprintf(temp,"P%s@%s",userbuf,nodebuf); putc(0,temp);
463         fprintf(temp,"T%ld",now); putc(0,temp);
464         fprintf(temp,"A%s",frombuf); putc(0,temp);
465         fprintf(temp,"O%s",recp); putc(0,temp);
466         fprintf(temp,"N%s",nodebuf); putc(0,temp);
467         if (strlen(subject)>0) {
468                 fprintf(temp,"U%s",subject); putc(0,temp);
469                 }
470         putc('M',temp);
471         if (strcmp(buf, ".")) loopcopy(temp, stdin);
472         putc(0,temp);
473         fclose(temp);
474         }
475
476 void do_uudecode(target)
477 char *target;  {
478         static char buf[1024];
479         FILE *fp;
480         
481         sprintf(buf,"cd %s; uudecode",target);
482
483         fp=popen(buf,"w");
484         if (fp==NULL) return;
485         while (fgets(buf,1024,stdin)!=NULL) {
486                 fprintf(fp,"%s",buf);
487                 }
488         pclose(fp);
489
490         }
491
492 void do_fallback(recp)
493 char recp[]; {
494         static char buf[1024];
495         FILE *fp;
496         
497         sprintf(buf, FALLBACK, recp);
498         fp=popen(buf,"w");
499         if (fp==NULL) fp = popen("cat >/dev/null", "w");
500         loopcopy(fp, stdin);
501         pclose(fp);
502         }
503
504 int alias(name)
505 char *name; {
506         FILE *fp;
507         int a;
508         char abuf[256];
509         
510         fp=fopen(ALIASES,"r");
511         if (fp==NULL) {
512                 syslog(LOG_ERR,"cannot open %s: %s",ALIASES,strerror(errno));
513                 return(2);
514                 }
515
516         while (fgets(abuf,256,fp)!=NULL) {
517                 strip_trailing_whitespace(abuf);
518                 for (a=0; a<strlen(abuf); ++a) {
519                         if (abuf[a]==',') {
520                                 abuf[a]=0;
521                                 if (!strucmp(name,abuf)) {
522                                         strcpy(name,&abuf[a+1]);
523                                         }
524                                 }
525                         }
526                 }
527         fclose(fp);
528         return(0);
529         }
530
531
532 void deliver(char recp[], int is_test, int deliver_to_ignet) {
533
534         /* various ways we can deliver mail... */
535
536         if (deliver_to_ignet) {
537                 syslog(LOG_NOTICE,"to Citadel network user %s",recp);
538                 if (is_test == 0) do_citmail(recp, REMOTE);
539                 }
540
541         else if (!strcmp(recp,"uudecode")) {
542                 syslog(LOG_NOTICE,"uudecoding to bit bucket directory");
543                 if (is_test == 0) do_uudecode(config.c_bucket_dir);
544                 }
545
546         else if (!strcmp(recp,"cit86net")) {
547                 syslog(LOG_NOTICE,"uudecoding to Cit86net spool");
548                 if (is_test == 0) {
549                         do_uudecode(CIT86NET);
550                         system("exec ./BatchTranslate86");
551                         }
552                 }
553
554         else if (!strcmp(recp,"null")) {
555                 syslog(LOG_NOTICE,"zapping nulled message");
556                 }
557
558         else if (!struncmp(recp,"room_",5)) {
559                 syslog(LOG_NOTICE,"to room %s",recp);
560                 if (is_test == 0) do_roommail(recp);
561                 }
562
563         else {
564                 /* Otherwise, we treat the recipient as the name of a local
565                  * Citadel user.  If the username doesn't exist, we still
566                  * deliver it to Citadel -- netproc will handle the bounce.
567                  */
568                 syslog(LOG_NOTICE,"to Citadel user %s",recp);
569                 if (is_test == 0) do_citmail(recp, LOCAL);
570                 }
571
572         }
573
574
575
576 void main(argc,argv)
577 int argc;
578 char *argv[]; {
579         int is_test = 0;
580         int deliver_to_ignet = 0;
581         int smtp = 0;
582         static char recp[1024], buf[1024];
583         static char user[1024], node[1024], name[1024];
584         int a;
585
586         openlog("citmail", LOG_PID, LOG_USER);
587         get_config();
588         LoadInternetConfig();
589
590         if (!strcmp(argv[1],"-t")) {
591                 is_test = 1;
592                 syslog(LOG_NOTICE,"test mode - will not deliver");
593                 }
594         if (!strcmp(argv[1], "-i")) {
595                 smtp = 1;
596                 syslog(LOG_NOTICE,"started as an SMTP daemon");
597                 }
598
599
600         if (smtp) {
601                 strcpy(recp, "");
602                 }
603         else if (is_test == 0) {
604                 strcpy(recp,argv[1]);
605                 }
606         else {
607                 strcpy(recp,argv[2]);
608                 }
609
610
611         if (smtp) {
612                 /*** SMTP delivery mode ***/
613
614                 printf("200 Citadel/UX SMTP gateway ready.\n");
615         
616                 do {
617                         fflush(stdout);
618                         fflush(stderr);
619                         fgets(buf, 1024, stdin);
620                         while ( (strlen(buf)>0) && (buf[strlen(buf)-1]>0) && (buf[strlen(buf)-1]<32) ) {
621                                 buf[strlen(buf)-1] = 0;
622                                 }
623
624                         /* null-pad to allow some lazy compares */
625                         buf[strlen(buf)+1] = 0;
626                         buf[strlen(buf)+2] = 0;
627                         buf[strlen(buf)+3] = 0;
628         
629                         if (!struncmp(buf, "QUIT", 4)) {
630                                 printf("221 Later, dude.\n");
631                                 }
632                         else if (!struncmp(buf, "HELP", 4)) {
633                                 printf("214 You think _you_ need help?\n");
634                                 }
635                         else if (!struncmp(buf, "HELO", 4)) {
636                                 printf("250 Howdy ho, Mr. Hankey!\n");
637                                 }
638                         else if (!struncmp(buf, "MAIL", 4)) {
639                                 printf("250 Sure, whatever...\n");
640                                 }
641
642
643                         else if (!struncmp(buf, "RCPT To: ", 9)) {
644                                 if (strlen(recp) > 0) {
645                                         printf("571 Multiple recipients not supported.\n");
646                                         }
647                                 else {
648                                         strcpy(recp, &buf[9]);
649                                         if (haschar(recp, ',')) {
650                                                 printf("571 Multiple recipients not supported.\n");
651                                                 strcpy(recp, "");
652                                                 }
653                                         else {
654                                                 syslog(LOG_NOTICE,"recp: %s",recp);
655                                                 for (a=0; a<2; ++a) {
656                                                         alias(recp);
657                                                         }
658
659                                                 /* did we alias it back to a remote address? */
660                                                 if (    (haschar(recp,'%'))
661                                                 ||      (haschar(recp,'@'))
662                                                 ||      (haschar(recp,'!')) ) {
663         
664                                                         process_rfc822_addr(recp, user, node, name);
665                                                         host_alias(node);
666                 
667                                                         /* If there are dots, it's an Internet host, so feed it
668                                                         * back to an external mail transport agent such as sendmail.
669                                                         */
670                                                         if (haschar(node, '.')) {
671                                                                 printf("571 Away with thee, spammer!\n");
672                                                                 strcpy(recp, "");
673                                                                 }
674                 
675                                                         /* Otherwise, we're dealing with Citadel mail. */
676                                                         else {
677                                                                 sprintf(recp, "%s!%s", node, user);
678                                                                 deliver_to_ignet = 1;
679                                                                 printf("250 IGnet recipient.\n");
680                                                                 }
681                                                         }
682                                                 else {
683                                                         printf("250 Local recipient.\n");
684                                                         }
685         
686                                                 }
687         
688                                         }
689                                 }
690
691
692
693                         else if (!struncmp(buf, "RCPT", 4)) {
694                                 printf("501 Only 'To:' commands are supported.\n");
695                                 }
696                         else if (!struncmp(buf, "DATA", 4)) {
697                                 if (strlen(recp) > 0) {
698                                         printf("354 Sock it to me, baby...\n");
699                                         fflush(stdout);
700                                         deliver(recp, is_test, deliver_to_ignet);
701                                         printf("250 Cool beans!\n");
702                                         }
703                                 else {
704                                         printf("503 No recipient has been specified.\n");
705                                         }
706                                 }
707                         else {
708                                 printf("500 Huh?\n");
709                                 }
710         
711                         } while (struncmp(buf,"QUIT",4));
712                 }
713
714         else {
715                 /*** Non-SMTP delivery mode ***/
716                 syslog(LOG_NOTICE,"recp: %s",recp);
717                 for (a=0; a<2; ++a) {
718                         alias(recp);
719                         }
720         
721                 /* did we alias it back to a remote address? */
722                 if (    (haschar(recp,'%'))
723                 ||      (haschar(recp,'@'))
724                 ||      (haschar(recp,'!')) ) {
725         
726                         process_rfc822_addr(recp, user, node, name);
727                         host_alias(node);
728                 
729                         /* If there are dots, it's an Internet host, so feed it
730                         * back to an external mail transport agent such as sendmail.
731                         */
732                         if (haschar(node, '.')) {
733                                 sprintf(buf, SENDMAIL, recp);
734                                 system(buf);
735                                 exit(0);
736                                 }
737         
738                         /* Otherwise, we're dealing with Citadel mail. */
739                         else {
740                                 sprintf(recp, "%s!%s", node, user);
741                                 deliver_to_ignet = 1;
742                                 }
743         
744                         }
745         
746                 deliver(recp, is_test, deliver_to_ignet);
747                 }
748         
749         closelog();
750         if (RUN_NETPROC) execlp("./netproc","netproc",NULL);
751         exit(0);
752         }
753