/*
- * citmail.c v4.0
+ * citmail.c v4.1
*
* This program may be used as a local mail delivery agent, which will allow
* all Citadel users to receive Internet e-mail. To enable this functionality,
#include <pwd.h>
#include <errno.h>
#include <syslog.h>
+#include <limits.h>
#include "citadel.h"
+#include "config.h"
+#include "internetmail.h"
#define LOCAL 0
#define REMOTE 1
char *monthdesc[] = { "Jan","Feb","Mar","Apr","May","Jun",
"Jul","Aug","Sep","Oct","Nov","Dec" };
-
-
-void LoadInternetConfig();
-void get_config();
-int IsHostLocal();
-struct config config;
-
char ALIASES[128];
char CIT86NET[128];
char SENDMAIL[128];
char OUTGOING_FQDN[128];
int RUN_NETPROC = 1;
-long conv_date(sdbuf)
-char sdbuf[]; {
+
+long conv_date(char *sdbuf)
+{
int a,b,cpos,tend,tval;
long now;
struct tm *tmbuf;
/*
* replacement strerror() for systems that don't have it
*/
-char *strerror(e)
-int e; {
+char *strerror(int e)
+{
static char buf[32];
sprintf(buf,"errno = %d",e);
}
#endif
-int haschar(st,ch)
-char st[];
-int ch; {
+int haschar(char *st, int ch)
+{
int a,b;
b=0;
for (a=0; a<strlen(st); ++a) if (st[a]==ch) ++b;
return(b);
}
-void strip_trailing_whitespace(buf)
-char buf[]; {
+void strip_trailing_whitespace(char *buf)
+{
while(isspace(buf[strlen(buf)-1]))
buf[strlen(buf)-1]=0;
}
/* strip leading and trailing spaces */
-void striplt(buf)
-char buf[]; {
+void striplt(char *buf)
+{
while ( (strlen(buf)>0) && (buf[0]==32) ) strcpy(buf,&buf[1]);
while (buf[strlen(buf)-1] == 32) buf[strlen(buf)-1] = 0;
}
/*
* Split an RFC822-style address into userid, host, and full name
*/
-void process_rfc822_addr(rfc822,user,node,name)
-char rfc822[];
-char user[];
-char node[];
-char name[]; {
+void process_rfc822_addr(char *rfc822, char *user, char *node, char *name)
+{
int a;
/* extract full name - first, it's From minus <userid> */
char nodebuf[256];
char destsys[256];
char subject[256];
+ char targetroom[256];
if (dtype==REMOTE) {
/* chop the system name out, so we're left with a user */
while (haschar(recp,'!')) strcpy(recp,&recp[1]);
+ }
- /* now convert underscores to spaces */
- for (a=0; a<strlen(recp); ++a) if (recp[a]=='_') recp[a]=' ';
+ /* Convert underscores to spaces */
+ for (a=0; a<strlen(recp); ++a) if (recp[a]=='_') recp[a]=' ';
+ /* Are we delivering to a room instead of a user? */
+ if (!strncasecmp(recp, "room ", 5)) {
+ strcpy(targetroom, &recp[5]);
+ strcpy(recp, "");
+ }
+ else {
+ strcpy(targetroom, "Mail");
}
time(&now);
/* now convert it to Citadel format */
fprintf(temp,"P%s@%s%c", userbuf, nodebuf, 0);
- fprintf(temp,"E%s%c", userbuf, 0);
fprintf(temp,"T%ld%c", now, 0);
- fprintf(temp,"A%s%c", frombuf, 0);
- fprintf(temp,"OMail%c", 0);
+ fprintf(temp,"A%s%c", userbuf, 0);
+
+ if (strlen(targetroom) > 0) {
+ fprintf(temp, "O%s%c", targetroom, 0);
+ }
+ else {
+ fprintf(temp, "OMail%c", 0);
+ }
+
fprintf(temp,"N%s%c", nodebuf, 0);
+ fprintf(temp,"H%s%c", frombuf, 0);
if (dtype==REMOTE) {
fprintf(temp,"D%s%c", destsys, 0);
}
- fprintf(temp,"R%s%c", recp, 0);
- if (strlen(subject)>0) {
- fprintf(temp,"U%s%c", subject, 0);
- }
- putc('M',temp);
- if (strcmp(buf, ".")) loopcopy(temp, stdin);
- putc(0,temp);
- fclose(temp);
- }
-
-void do_roommail(recp) /* pipe public message through netproc */
-char recp[]; {
- long now;
- FILE *temp;
- int a;
- char buf[128],userbuf[128],frombuf[128],nodebuf[128];
- char subject[128], from[256];
-
- strcpy(subject,"");
- sprintf(from, "postmaster@%s", config.c_nodename);
- strcpy(recp,&recp[5]);
- for (a=0; a<strlen(recp); ++a) if (recp[a]=='_') recp[a]=32;
- time(&now);
-
-
- sprintf(buf,"./network/spoolin/citmail.%d",getpid());
- temp = fopen(buf,"w");
-
- putc(255,temp); putc(MES_NORMAL,temp); putc(1,temp);
- strcpy(frombuf,"Internet Mail Gateway");
- strcpy(nodebuf, config.c_nodename);
- do {
- if (fgets(buf,128,stdin) == NULL) strcpy(buf, ".");
- strip_trailing_whitespace(buf);
-
- if (!strncmp(buf,"Subject: ",9)) strcpy(subject,&buf[9]);
- if (!strncmp(buf,"Date: ",6)) now = conv_date(&buf[6]);
- if (!strncmp(buf,"From: ",6)) strcpy(from, &buf[6]);
- } while ( (strcmp(buf, ".")) && (strcmp(buf, "")) );
- process_rfc822_addr(from, userbuf, nodebuf, frombuf);
+ if (strlen(recp) > 0) {
+ fprintf(temp,"R%s%c", recp, 0);
+ }
- fprintf(temp,"P%s@%s",userbuf,nodebuf); putc(0,temp);
- fprintf(temp,"T%ld",now); putc(0,temp);
- fprintf(temp,"A%s",frombuf); putc(0,temp);
- fprintf(temp,"O%s",recp); putc(0,temp);
- fprintf(temp,"N%s",nodebuf); putc(0,temp);
if (strlen(subject)>0) {
- fprintf(temp,"U%s",subject); putc(0,temp);
+ fprintf(temp,"U%s%c", subject, 0);
}
putc('M',temp);
if (strcmp(buf, ".")) loopcopy(temp, stdin);
fclose(temp);
}
-void do_uudecode(target)
-char *target; {
+
+void do_uudecode(char *target)
+{
static char buf[1024];
FILE *fp;
}
-void do_fallback(recp)
-char recp[]; {
- static char buf[1024];
- FILE *fp;
-
- sprintf(buf, FALLBACK, recp);
- fp=popen(buf,"w");
- if (fp==NULL) fp = popen("cat >/dev/null", "w");
- loopcopy(fp, stdin);
- pclose(fp);
- }
-
-int alias(name)
-char *name; {
+int alias(char *name)
+{
FILE *fp;
int a;
char abuf[256];
syslog(LOG_NOTICE,"zapping nulled message");
}
- else if (!strncasecmp(recp,"room_",5)) {
- syslog(LOG_NOTICE,"to room %s",recp);
- if (is_test == 0) do_roommail(recp);
- }
-
else {
- /* Otherwise, we treat the recipient as the name of a local
- * Citadel user. If the username doesn't exist, we still
- * deliver it to Citadel -- netproc will handle the bounce.
+ /* Otherwise, the user is local (or an unknown name was
+ * specified, in which case we let netproc handle the bounce)
*/
- syslog(LOG_NOTICE,"to Citadel user %s",recp);
+ syslog(LOG_NOTICE,"to Citadel recipient %s",recp);
if (is_test == 0) do_citmail(recp, LOCAL);
}
-void main(argc,argv)
-int argc;
-char *argv[]; {
+void main(int argc, char **argv)
+{
int is_test = 0;
int deliver_to_ignet = 0;
int smtp = 0;