* Replaced citmail.c with a new one that simply SMTP-forwards to Citadel
authorArt Cancro <ajc@citadel.org>
Thu, 6 Jan 2000 03:50:35 +0000 (03:50 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 6 Jan 2000 03:50:35 +0000 (03:50 +0000)
* Started outbound SMTP queue work

citadel/ChangeLog
citadel/Makefile.in
citadel/citmail.c
citadel/internet_addressing.c
citadel/msgbase.c
citadel/msgbase.h
citadel/serv_pop3.c
citadel/serv_smtp.c
citadel/server.h
citadel/sysconfig.h

index d7a4f794b3837c52962397f85a8e74526c11e196..677f6ed4132c06e3f2607bf71ec38fb11ff2539c 100644 (file)
@@ -1,4 +1,8 @@
 $Log$
+Revision 1.435  2000/01/06 03:50:34  ajc
+* Replaced citmail.c with a new one that simply SMTP-forwards to Citadel
+* Started outbound SMTP queue work
+
 Revision 1.434  1999/12/30 04:56:29  ajc
 * Got initial SMTP delivery working in a very specific situation (delivery
   to a single, local user)
@@ -1514,3 +1518,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
        * Initial CVS import 
+
index 7c603374216f008678d5b17b0b2f60be99ff8779..bc76559e9159f78c72bfd54853f9e9099ca91e0a 100644 (file)
@@ -188,14 +188,13 @@ netproc: netproc.o config.o ipc_c_tcp.o tools.o $(LIBOBJS)
        $(CC) netproc.o config.o ipc_c_tcp.o tools.o \
        $(LIBOBJS) $(LDFLAGS) -o netproc $(NETLIBS) $(GDBM)
 
-citmail: citmail.o config.o internetmail.o parsedate.o $(LIBOBJS)
+citmail: citmail.o
        @echo "*"
        @echo "*                 ###### IMPORTANT ######"
        @echo "* To allow Citadel users to receive Internet mail, you must"
        @echo "* set this program to be your local mail delivery agent."
        @echo "*"
-       $(CC) citmail.o config.o internetmail.o parsedate.o \
-               $(LIBOBJS) $(LDFLAGS) -o citmail
+       $(CC) citmail.o $(LDFLAGS) -o citmail
 
 mailinglist: mailinglist.o config.o internetmail.o
        $(CC) mailinglist.o config.o internetmail.o $(LDFLAGS) -o mailinglist
index fcaf20a263c1caf57b0a469066ef1c30fa6a1835..ff0ea65864db82088f462a841ec03158ea337669 100644 (file)
 /*
- * citmail.c v4.2
- * $Id$
- *
- * 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,
- * you must tell sendmail, smail, or whatever mailer you are using, that this
- * program is your local mail delivery agent.  This program is a direct
- * replacement for lmail, deliver, or whatever.
+ * 
+ * Completely reworked version of "citmail"
+ * This program attempts to act like a local MDA if you're using sendmail or
+ * some other non-Citadel MTA.  It basically just forwards the message to
+ * the Citadel SMTP listener on some non-standard port.
  *
- * Usage:
- *
- * citmail <recipient>       - Deliver a message
- * citmail -t <recipient>    - Address test mode (will not deliver)
+ * $Id$
  *
  */
 
 #include "sysdep.h"
 #include <stdlib.h>
 #include <unistd.h>
-#include <stdio.h>
-#include <fcntl.h>
 #include <ctype.h>
+#include <stdio.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
 #include <string.h>
-#include <time.h>
 #include <pwd.h>
 #include <errno.h>
-#include <syslog.h>
-#include <limits.h>
+#include <stdarg.h>
 #include "citadel.h"
-#include "config.h"
-#include "internetmail.h"
+#include "citadel_decls.h"
+#include "ipc.h"
+#ifndef HAVE_SNPRINTF
+#include "snprintf.h"
+#endif
 
+#ifndef INADDR_NONE
+#define INADDR_NONE 0xffffffff
+#endif
 
-extern time_t parsedate(char *p);
+int serv_sock;
 
 
-/* message delivery classes */
-enum {
-       DELIVER_LOCAL,
-       DELIVER_REMOTE,
-       DELIVER_INTERNET,
-       DELIVER_CCITADEL
-};
-       
+void strip_trailing_nonprint(char *buf)
+{
+        while ( (strlen(buf)>0) && (!isprint(buf[strlen(buf) - 1])) )
+                buf[strlen(buf) - 1] = 0;
+}
 
-#undef tolower
-#define tolower(x) isupper(x) ? (x+'a'-'A') : x
 
-char *monthdesc[] =
-{"Jan", "Feb", "Mar", "Apr", "May", "Jun",
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
 
-char ALIASES[128];
-char CIT86NET[128];
-char SENDMAIL[128];
-char FALLBACK[128];
-char GW_DOMAIN[128];
-char TABLEFILE[128];
-char OUTGOING_FQDN[128];
-int RUN_NETPROC = 1;
 
 
 
-#ifndef HAVE_STRERROR
-/*
- * replacement strerror() for systems that don't have it
- */
-char *strerror(int e)
+void timeout(int signum)
 {
-       static char buf[32];
-
-       snprintf(buf, sizeof buf, "errno = %d", e);
-       return (buf);
+       exit(signum);
 }
-#endif
 
-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(char *buf)
+int connectsock(char *host, char *service, char *protocol)
 {
-       while (isspace(buf[strlen(buf) - 1]))
-               buf[strlen(buf) - 1] = 0;
-}
+       struct hostent *phe;
+       struct servent *pse;
+       struct protoent *ppe;
+       struct sockaddr_in sin;
+       int s, type;
+
+       memset(&sin, 0, sizeof(sin));
+       sin.sin_family = AF_INET;
+
+       pse = getservbyname(service, protocol);
+       if (pse) {
+               sin.sin_port = pse->s_port;
+       } else if ((sin.sin_port = htons((u_short) atoi(service))) == 0) {
+               fprintf(stderr, "Can't get %s service entry: %s\n",
+                       service, strerror(errno));
+               exit(3);
+       }
+       phe = gethostbyname(host);
+       if (phe) {
+               memcpy(&sin.sin_addr, phe->h_addr, phe->h_length);
+       } else if ((sin.sin_addr.s_addr = inet_addr(host)) == INADDR_NONE) {
+               fprintf(stderr, "Can't get %s host entry: %s\n",
+                       host, strerror(errno));
+               exit(3);
+       }
+       if ((ppe = getprotobyname(protocol)) == 0) {
+               fprintf(stderr, "Can't get %s protocol entry: %s\n",
+                       protocol, strerror(errno));
+               exit(3);
+       }
+       if (!strcmp(protocol, "udp")) {
+               type = SOCK_DGRAM;
+       } else {
+               type = SOCK_STREAM;
+       }
 
-/* strip leading and trailing spaces */
-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;
-}
+       s = socket(PF_INET, type, ppe->p_proto);
+       if (s < 0) {
+               fprintf(stderr, "Can't create socket: %s\n", strerror(errno));
+               exit(3);
+       }
+       signal(SIGALRM, timeout);
+       alarm(30);
+
+       if (connect(s, (struct sockaddr *) &sin, sizeof(sin)) < 0) {
+               fprintf(stderr, "can't connect to %s.%s: %s\n",
+                       host, service, strerror(errno));
+               exit(3);
+       }
+       alarm(0);
+       signal(SIGALRM, SIG_IGN);
 
+       return (s);
+}
 
 /*
- * Check to see if a given FQDN really maps to a Citadel network node
+ * convert service and host entries into a six-byte numeric in the format
+ * expected by a SOCKS v4 server
  */
-void host_alias(char host[])
+void numericize(char *buf, char *host, char *service, char *protocol)
 {
-
-       int a;
-
-       /* What name is the local host known by? */
-       /* if (!strcasecmp(host, config.c_fqdn)) { */
-       if (IsHostLocal(host)) {
-               strcpy(host, config.c_nodename);
-               return;
+       struct hostent *phe;
+       struct servent *pse;
+       struct sockaddr_in sin;
+
+       memset(&sin, 0, sizeof(sin));
+       sin.sin_family = AF_INET;
+
+       pse = getservbyname(service, protocol);
+       if (pse) {
+               sin.sin_port = pse->s_port;
+       } else if ((sin.sin_port = htons((u_short) atoi(service))) == 0) {
+               fprintf(stderr, "Can't get %s service entry: %s\n",
+                       service, strerror(errno));
+               exit(3);
        }
-       /* Other hosts in the gateway domain? */
-       for (a = 0; a < strlen(host); ++a) {
-               if ((host[a] == '.') && (!strcasecmp(&host[a + 1], GW_DOMAIN))) {
-                       host[a] = 0;
-                       for (a = 0; a < strlen(host); ++a) {
-                               if (host[a] == '.')
-                                       host[a] = 0;
-                       }
-                       return;
-               }
+       buf[1] = (((sin.sin_port) & 0xFF00) >> 8);
+       buf[0] = ((sin.sin_port) & 0x00FF);
+
+       phe = gethostbyname(host);
+       if (phe) {
+               memcpy(&sin.sin_addr, phe->h_addr, phe->h_length);
+       } else if ((sin.sin_addr.s_addr = inet_addr(host)) == INADDR_NONE) {
+               fprintf(stderr, "Can't get %s host entry: %s\n",
+                       host, strerror(errno));
+               exit(3);
        }
-
-       /* Otherwise, do nothing... */
+       buf[5] = ((sin.sin_addr.s_addr) & 0xFF000000) >> 24;
+       buf[4] = ((sin.sin_addr.s_addr) & 0x00FF0000) >> 16;
+       buf[3] = ((sin.sin_addr.s_addr) & 0x0000FF00) >> 8;
+       buf[2] = ((sin.sin_addr.s_addr) & 0x000000FF);
 }
 
-
-
 /*
- * Split an RFC822-style address into userid, host, and full name
+ * input binary data from socket
  */
-void process_rfc822_addr(char *rfc822, char *user, char *node, char *name)
+void serv_read(char *buf, int bytes)
 {
-       int a;
-
-       /* extract full name - first, it's From minus <userid> */
-       strcpy(name, rfc822);
-       for (a = 0; a < strlen(name); ++a)
-               if (name[a] == '<') {
-                       do {
-                               strcpy(&name[a], &name[a + 1]);
-                       } while ((strlen(name) > 0) && (name[a] != '>'));
-                       strcpy(&name[a], &name[a + 1]);
-               }
-       /* strip anything to the left of a bang */
-       while ((strlen(name) > 0) && (haschar(name, '!') > 0))
-               strcpy(name, &name[1]);
-
-       /* and anything to the right of a @ or % */
-       for (a = 0; a < strlen(name); ++a) {
-               if (name[a] == '@')
-                       name[a] = 0;
-               if (name[a] == '%')
-                       name[a] = 0;
-       }
-
-       /* but if there are parentheses, that changes the rules... */
-       if ((haschar(rfc822, '(') == 1) && (haschar(rfc822, ')') == 1)) {
-               strcpy(name, rfc822);
-               while ((strlen(name) > 0) && (name[0] != '(')) {
-                       strcpy(&name[0], &name[1]);
-               }
-               strcpy(&name[0], &name[1]);
-               for (a = 0; a < strlen(name); ++a)
-                       if (name[a] == ')')
-                               name[a] = 0;
-       }
-       /* but if there are a set of quotes, that supersedes everything */
-       if (haschar(rfc822, 34) == 2) {
-               strcpy(name, rfc822);
-               while ((strlen(name) > 0) && (name[0] != 34)) {
-                       strcpy(&name[0], &name[1]);
-               }
-               strcpy(&name[0], &name[1]);
-               for (a = 0; a < strlen(name); ++a)
-                       if (name[a] == 34)
-                               name[a] = 0;
-       }
-       /* extract user id */
-       strcpy(user, rfc822);
-
-       /* first get rid of anything in parens */
-       for (a = 0; a < strlen(user); ++a)
-               if (user[a] == '(') {
-                       do {
-                               strcpy(&user[a], &user[a + 1]);
-                       } while ((strlen(user) > 0) && (user[a] != ')'));
-                       strcpy(&user[a], &user[a + 1]);
-               }
-       /* if there's a set of angle brackets, strip it down to that */
-       if ((haschar(user, '<') == 1) && (haschar(user, '>') == 1)) {
-               while ((strlen(user) > 0) && (user[0] != '<')) {
-                       strcpy(&user[0], &user[1]);
-               }
-               strcpy(&user[0], &user[1]);
-               for (a = 0; a < strlen(user); ++a)
-                       if (user[a] == '>')
-                               user[a] = 0;
-       }
-       /* strip anything to the left of a bang */
-       while ((strlen(user) > 0) && (haschar(user, '!') > 0))
-               strcpy(user, &user[1]);
-
-       /* and anything to the right of a @ or % */
-       for (a = 0; a < strlen(user); ++a) {
-               if (user[a] == '@')
-                       user[a] = 0;
-               if (user[a] == '%')
-                       user[a] = 0;
-       }
+       int len, rlen;
 
-
-
-       /* extract node name */
-       strcpy(node, rfc822);
-
-       /* first get rid of anything in parens */
-       for (a = 0; a < strlen(node); ++a)
-               if (node[a] == '(') {
-                       do {
-                               strcpy(&node[a], &node[a + 1]);
-                       } while ((strlen(node) > 0) && (node[a] != ')'));
-                       strcpy(&node[a], &node[a + 1]);
-               }
-       /* if there's a set of angle brackets, strip it down to that */
-       if ((haschar(node, '<') == 1) && (haschar(node, '>') == 1)) {
-               while ((strlen(node) > 0) && (node[0] != '<')) {
-                       strcpy(&node[0], &node[1]);
+       len = 0;
+       while (len < bytes) {
+               rlen = read(serv_sock, &buf[len], bytes - len);
+               if (rlen < 1) {
+                       return;
                }
-               strcpy(&node[0], &node[1]);
-               for (a = 0; a < strlen(node); ++a)
-                       if (node[a] == '>')
-                               node[a] = 0;
+               len = len + rlen;
        }
-       /* strip anything to the left of a @ */
-       while ((strlen(node) > 0) && (haschar(node, '@') > 0))
-               strcpy(node, &node[1]);
-
-       /* strip anything to the left of a % */
-       while ((strlen(node) > 0) && (haschar(node, '%') > 0))
-               strcpy(node, &node[1]);
-
-       /* reduce multiple system bang paths to node!user */
-       while ((strlen(node) > 0) && (haschar(node, '!') > 1))
-               strcpy(node, &node[1]);
-
-       /* now get rid of the user portion of a node!user string */
-       for (a = 0; a < strlen(node); ++a)
-               if (node[a] == '!')
-                       node[a] = 0;
-
-
-
-       /* strip leading and trailing spaces in all strings */
-       striplt(user);
-       striplt(node);
-       striplt(name);
 }
 
+
 /*
- * Copy line by line, ending at EOF or a "." 
+ * send binary to server
  */
-void loopcopy(FILE * to, FILE * from)
+void serv_write(char *buf, int nbytes)
 {
-       char buf[1024];
-       char *r;
-
-       while (1) {
-               r = fgets(buf, sizeof(buf), from);
-               if (r == NULL)
-                       return;
-               strip_trailing_whitespace(buf);
-               if (!strcmp(buf, "."))
+       int bytes_written = 0;
+       int retval;
+       while (bytes_written < nbytes) {
+               retval = write(serv_sock, &buf[bytes_written],
+                              nbytes - bytes_written);
+               if (retval < 1) {
                        return;
-               fprintf(to, "%s\n", buf);
+               }
+               bytes_written = bytes_written + retval;
        }
 }
 
 
 
 /*
- * pipe message through netproc
+ * input string from socket - implemented in terms of serv_read()
  */
-void do_citmail(char recp[], int dtype)
+void serv_gets(char *buf)
 {
-
-       time_t now;
-       FILE *temp;
-       int a;
-       int format_type = 0;
-       char buf[128];
-       char from[512];
-       char userbuf[256];
-       char frombuf[256];
-       char nodebuf[256];
-       char destsys[256];
-       char subject[256];
-       long message_id = 0L;
-       char targetroom[256];
-       char content_type[256];
-       char *extra_headers = NULL;
-
-
-       if (dtype == DELIVER_REMOTE) {
-
-               /* get the Citadel node name out of the path */
-               strncpy(destsys, recp, sizeof(destsys));
-               for (a = 0; a < strlen(destsys); ++a) {
-                       if ((destsys[a] == '!') || (destsys[a] == '.')) {
-                               destsys[a] = 0;
-                       }
-               }
-
-               /* chop the system name out, so we're left with a user */
-               while (haschar(recp, '!'))
-                       strcpy(recp, &recp[1]);
+       int i;
+
+       /* Read one character at a time.
+        */
+       for (i = 0;; i++) {
+               serv_read(&buf[i], 1);
+               if (buf[i] == '\n' || i == 255)
+                       break;
        }
-       /* 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, MAILROOM);
-       }
-
-       time(&now);
-       snprintf(from, sizeof from, "postmaster@%s", config.c_nodename);
-
-       snprintf(buf, sizeof buf, "./network/spoolin/citmail.%d", getpid());
-       temp = fopen(buf, "w");
-
-       strcpy(subject, "");
-       strcpy(nodebuf, config.c_nodename);
-       strcpy(content_type, "text/plain");
-
-       do {
-               if (fgets(buf, 128, stdin) == NULL)
-                       strcpy(buf, ".");
-               strip_trailing_whitespace(buf);
-
-               if (!strncasecmp(buf, "Subject: ", 9))
-                       strcpy(subject, &buf[9]);
-               else if (!strncasecmp(buf, "Date: ", 6)) {
-                       now = parsedate(&buf[6]);
-                       if (now < 0L) now = time(NULL);
-               }
-               else if (!strncasecmp(buf, "From: ", 6))
-                       strcpy(from, &buf[6]);
-               else if (!strncasecmp(buf, "Content-type: ", 14))
-                       strcpy(content_type, &buf[14]);
-               else if (!strncasecmp(buf, "From ", 5)) {       /* ignore */
-               } else {
-                       if (extra_headers == NULL) {
-                               extra_headers = malloc(strlen(buf) + 2);
-                               strcpy(extra_headers, "");
-                       } else {
-                               extra_headers = realloc(extra_headers,
-                                                       (strlen(extra_headers) + strlen(buf) + 2));
-                       }
-                       strcat(extra_headers, buf);
-                       strcat(extra_headers, "\n");
-               }
-       } while ((strcmp(buf, ".")) && (strcmp(buf, "")));
-
-       process_rfc822_addr(from, userbuf, nodebuf, frombuf);
-
-       if (!strncasecmp(content_type, "text/plain", 10))
-               format_type = 1;        /* plain ASCII message */
-       else
-               format_type = 4;        /* MIME message */
 
-       /* now convert it to Citadel format */
+       /* If we got a long line, discard characters until the newline.
+        */
+       if (i == 255)
+               while (buf[i] != '\n')
+                       serv_read(&buf[i], 1);
 
-       /* Header bytes */
-       putc(255, temp);        /* 0xFF = start-of-message byte */
-       putc(MES_NORMAL, temp); /* Non-anonymous message */
-       putc(format_type, temp);        /* Format type */
-
-       /* Origination */
-       fprintf(temp, "P%s@%s%c", userbuf, nodebuf, 0);
-       if (message_id)
-               fprintf(temp, "I%ld%c", message_id, 0);
-       fprintf(temp, "T%ld%c", (long)now, 0);
-       fprintf(temp, "A%s%c", userbuf, 0);
-
-       /* Destination */
-       if (strlen(targetroom) > 0) {
-               fprintf(temp, "O%s%c", targetroom, 0);
-       } else {
-               fprintf(temp, "O%s%c", MAILROOM, 0);
-       }
-
-       fprintf(temp, "N%s%c", nodebuf, 0);
-       fprintf(temp, "H%s%c", frombuf, 0);
-       if (dtype == DELIVER_REMOTE) {
-               fprintf(temp, "D%s%c", destsys, 0);
-       }
-       if (strlen(recp) > 0) {
-               fprintf(temp, "R%s%c", recp, 0);
-       }
-       /* Subject and text */
-       if (strlen(subject) > 0) {
-               fprintf(temp, "U%s%c", subject, 0);
-       }
-       putc('M', temp);
-       if (format_type == 4) {
-               fprintf(temp, "Content-type: %s\n", content_type);
-               if (extra_headers != NULL)
-                       fprintf(temp, "%s", extra_headers);
-               fprintf(temp, "\n");
-       }
-       if (extra_headers != NULL)
-               free(extra_headers);
-       if (strcmp(buf, "."))
-               loopcopy(temp, stdin);
-       putc(0, temp);
-       fclose(temp);
+       /* Strip all trailing nonprintables (crlf)
+        */
+       buf[i] = 0;
+       strip_trailing_nonprint(buf);
 }
 
 
-void do_uudecode(char *target)
+/*
+ * send line to server - implemented in terms of serv_write()
+ */
+void serv_puts(char *buf)
 {
-       static char buf[1024];
-       FILE *fp;
-
-       snprintf(buf, sizeof buf, "cd %s; uudecode", target);
-
-       fp = popen(buf, "w");
-       if (fp == NULL)
-               return;
-       while (fgets(buf, 1024, stdin) != NULL) {
-               fprintf(fp, "%s", buf);
-       }
-       pclose(fp);
-
+       /* printf("< %s\n", buf); */
+       serv_write(buf, strlen(buf));
+       serv_write("\n", 1);
 }
 
-int alias(char *name)
-{
-       FILE *fp;
-       int a;
-       char abuf[256];
 
-       fp = fopen(ALIASES, "r");
-       if (fp == NULL) {
-               syslog(LOG_ERR, "cannot open %s: %s", ALIASES, strerror(errno));
-               return (2);
-       }
-       while (fgets(abuf, 256, fp) != NULL) {
-               strip_trailing_whitespace(abuf);
-               for (a = 0; a < strlen(abuf); ++a) {
-                       if (abuf[a] == ',') {
-                               abuf[a] = 0;
-                               if (!strcasecmp(name, abuf)) {
-                                       strcpy(name, &abuf[a + 1]);
-                               }
-                       }
-               }
-       }
-       fclose(fp);
-       return (0);
-}
 
 
-void deliver(char recp[], int is_test, int deliver_to_ignet)
-{
 
-       /* various ways we can deliver mail... */
-
-       if (deliver_to_ignet) {
-               syslog(LOG_NOTICE, "to Citadel network user %s", recp);
-               if (is_test == 0)
-                       do_citmail(recp, DELIVER_REMOTE);
-       } else if (!strcmp(recp, "uudecode")) {
-               syslog(LOG_NOTICE, "uudecoding to bit bucket directory");
-               if (is_test == 0)
-                       do_uudecode(config.c_bucket_dir);
-       } else if (!strcmp(recp, "cit86net")) {
-               syslog(LOG_NOTICE, "uudecoding to Cit86net spool");
-               if (is_test == 0) {
-                       do_uudecode(CIT86NET);
-                       system("exec ./BatchTranslate86");
-               }
-       } else if (!strcmp(recp, "null")) {
-               syslog(LOG_NOTICE, "zapping nulled message");
-       } else {
-               /* 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 recipient %s", recp);
-               if (is_test == 0)
-                       do_citmail(recp, DELIVER_LOCAL);
-       }
+void cleanup(int exitcode) {
+       char buf[1024];
 
+       serv_puts("QUIT");
+       serv_gets(buf);
+       fprintf(stderr, "%s\n", buf);
+       exit(exitcode);
 }
 
 
 
-int main(int argc, char **argv)
-{
-       int is_test = 0;
-       int deliver_to_ignet = 0;
-       static char recp[1024], buf[1024];
-       static char user[1024], node[1024], name[1024];
-       int a;
-
-       openlog("citmail", LOG_PID, LOG_USER);
-       get_config();
-       LoadInternetConfig();
-
-       if (!strcmp(argv[1], "-t")) {
-               is_test = 1;
-               syslog(LOG_NOTICE, "test mode - will not deliver");
-       }
-       if (is_test == 0) {
-               strcpy(recp, argv[1]);
-       } else {
-               strcpy(recp, argv[2]);
-       }
-
-/*** Non-SMTP delivery mode ***/
-       syslog(LOG_NOTICE, "recp: %s", recp);
-       for (a = 0; a < 2; ++a) {
-               alias(recp);
-       }
-
-       /* did we alias it back to a remote address? */
-       if ((haschar(recp, '%'))
-           || (haschar(recp, '@'))
-           || (haschar(recp, '!'))) {
-
-               process_rfc822_addr(recp, user, node, name);
-               host_alias(node);
-
-               /* If there are dots, it's an Internet host, so feed it
-                * back to an external mail transport agent such as sendmail.
-                */
-               if (haschar(node, '.')) {
-                       snprintf(buf, sizeof buf, SENDMAIL, recp);
-                       system(buf);
-                       exit(0);
-               }
-               /* Otherwise, we're dealing with Citadel mail. */
-               else {
-                       snprintf(recp, sizeof recp, "%s!%s", node, user);
-                       deliver_to_ignet = 1;
-               }
+int main(int argc, char **argv) {
+       char buf[1024];
+       char fromline[1024];
+       FILE *fp;
 
+       fp = tmpfile();
+       if (fp == NULL) return(errno);
+       sprintf(fromline, "From: someone@somewhere.org");
+       while (fgets(buf, 1024, stdin) != NULL) {
+               fprintf(fp, "%s", buf);
+               if (!strncasecmp(buf, "From:", 5)) strcpy(fromline, buf);
        }
-       deliver(recp, is_test, deliver_to_ignet);
-
-       if (RUN_NETPROC) {
-               syslog(LOG_NOTICE, "running netproc");
-               if (system("/bin/true") != 0) {
-                       syslog(LOG_ERR, "netproc failed: %s", strerror(errno));
-               }
-       } else {
-               syslog(LOG_NOTICE, "skipping netproc");
+       strip_trailing_nonprint(fromline);
+
+       sprintf(buf, "%d", SMTP_PORT);
+       serv_sock = connectsock("localhost", buf, "tcp");
+       serv_gets(buf);
+       fprintf(stderr, "%s\n", buf);
+       if (buf[0]!='2') cleanup(1);
+
+       serv_puts("HELO localhost");
+       serv_gets(buf);
+       fprintf(stderr, "%s\n", buf);
+       if (buf[0]!='2') cleanup(1);
+
+       sprintf(buf, "MAIL %s", fromline);
+       serv_puts(buf);
+       serv_gets(buf);
+       fprintf(stderr, "%s\n", buf);
+       if (buf[0]!='2') cleanup(1);
+
+       sprintf(buf, "RCPT To: %s", argv[1]);
+       serv_puts(buf);
+       serv_gets(buf);
+       fprintf(stderr, "%s\n", buf);
+       if (buf[0]!='2') cleanup(1);
+
+       serv_puts("DATA");
+       serv_gets(buf);
+       fprintf(stderr, "%s\n", buf);
+       if (buf[0]!='3') cleanup(1);
+
+       rewind(fp);
+       while (fgets(buf, sizeof buf, fp) != NULL) {
+               strip_trailing_nonprint(buf);
+               serv_puts(buf);
        }
-       exit(0);
+       serv_puts(".");
+       serv_gets(buf);
+       fprintf(stderr, "%s\n", buf);
+       if (buf[0]!='2') cleanup(1);
+       else cleanup(0);
+       return(0);
 }
index 837279aabea9187ebd2808836908a0f680a2c2b6..1eda2ae400d92fa8a0641474e4e95093bf366d1d 100644 (file)
@@ -348,14 +348,6 @@ int convert_field(struct CtdlMessage *msg, int beg, int end) {
                processed = 1;
        }
 
-       /* If a content type is specified, this becomes a MIME message.  The
-        * content-type header itself remains in the RFC822 headers, not in
-        * the Citadel headers, therefore we do not set 'processed' to 1.
-        */
-       else if (!strcasecmp(key, "Content-type")) {
-               msg->cm_format_type = 4;
-       }
-
        /* Clean up and move on. */
        phree(key);     /* Don't free 'value', it's actually the same buffer */
        return(processed);
@@ -379,7 +371,7 @@ struct CtdlMessage *convert_internet_message(char *rfc822) {
        memset(msg, 0, sizeof(struct CtdlMessage));
        msg->cm_magic = CTDLMESSAGE_MAGIC;      /* self check */
        msg->cm_anon_type = 0;                  /* never anonymous */
-       msg->cm_format_type = 1;                /* text unless specified */
+       msg->cm_format_type = FMT_RFC822;       /* internet message */
        msg->cm_fields['M'] = rfc822;
 
        lprintf(9, "Unconverted RFC822 message length = %d\n", strlen(rfc822));
@@ -409,10 +401,13 @@ struct CtdlMessage *convert_internet_message(char *rfc822) {
 
                /* At this point we have a field.  Are we interested in it? */
                converted = convert_field(msg, beg, end);
+
+               /******
                if (converted) {
                        strcpy(&rfc822[beg], &rfc822[pos]);
                        pos = beg;
                }
+               ********/
 
                /* If we've hit the end of the message, bail out */
                if (pos > strlen(rfc822)) done = 1;
index 96c4f0a3f71e9e9300f6a0981d1f065738ee31f5..091a92bb8a2205e69b29057620640dcb0bc69a57 100644 (file)
@@ -776,7 +776,7 @@ void output_message(char *msgid, int mode, int headers_only)
 
        /* Are we downloading a MIME component? */
        if (mode == MT_DOWNLOAD) {
-               if (TheMessage->cm_format_type != 4) {
+               if (TheMessage->cm_format_type != FMT_RFC822) {
                        cprintf("%d This is not a MIME message.\n",
                                ERROR);
                } else if (CC->download_fp != NULL) {
@@ -806,7 +806,7 @@ void output_message(char *msgid, int mode, int headers_only)
         * MIME message, *lie* about it and tell the user it's fixed-format.
         */
        if (mode == MT_CITADEL) {
-               if (TheMessage->cm_format_type == 4)
+               if (TheMessage->cm_format_type == FMT_RFC822)
                        cprintf("type=1\n");
                else
                        cprintf("type=%d\n", TheMessage->cm_format_type);
@@ -918,7 +918,7 @@ void output_message(char *msgid, int mode, int headers_only)
        mptr = TheMessage->cm_fields['M'];
 
        /* Tell the client about the MIME parts in this message */
-       if (TheMessage->cm_format_type == 4) {  /* legacy textual dump */
+       if (TheMessage->cm_format_type == FMT_RFC822) { /* legacy text dump */
                if (mode == MT_CITADEL) {
                        mime_parser(mptr, NULL, *list_this_part);
                }
@@ -939,14 +939,14 @@ void output_message(char *msgid, int mode, int headers_only)
        /* signify start of msg text */
        if (mode == MT_CITADEL)
                cprintf("text\n");
-       if ((mode == MT_RFC822) && (TheMessage->cm_format_type != 4))
+       if ((mode == MT_RFC822) && (TheMessage->cm_format_type != FMT_RFC822))
                cprintf("\n");
 
        /* If the format type on disk is 1 (fixed-format), then we want
         * everything to be output completely literally ... regardless of
         * what message transfer format is in use.
         */
-       if (TheMessage->cm_format_type == 1) {
+       if (TheMessage->cm_format_type == FMT_FIXED) {
                strcpy(buf, "");
                while (ch = *mptr++, ch > 0) {
                        if (ch == 13)
@@ -970,7 +970,7 @@ void output_message(char *msgid, int mode, int headers_only)
         * for new paragraphs is correct and the client will reformat the
         * message to the reader's screen width.
         */
-       if (TheMessage->cm_format_type == 0) {
+       if (TheMessage->cm_format_type == FMT_CITADEL) {
                memfmout(80, mptr, 0);
        }
 
@@ -979,7 +979,7 @@ void output_message(char *msgid, int mode, int headers_only)
         * this message is format 1 (fixed format), so the callback function
         * we use will display those parts as-is.
         */
-       if (TheMessage->cm_format_type == 4) {
+       if (TheMessage->cm_format_type == FMT_RFC822) {
                CtdlAllocUserData(SYM_MA_INFO, sizeof(struct ma_info));
                memset(ma, 0, sizeof(struct ma_info));
                mime_parser(mptr, NULL, *fixed_output);
@@ -1514,7 +1514,7 @@ void CtdlSaveMsg(struct CtdlMessage *msg, /* message to save */
        if (ReplicationChecks(msg) > 0) return;
 
        /* Network mail - send a copy to the network program. */
-       if ((strlen(recipient) > 0) && (mailtype != MES_LOCAL)) {
+       if ((strlen(recipient) > 0) && (mailtype == MES_BINARY)) {
                lprintf(9, "Sending network spool\n");
                sprintf(aaa, "./network/spoolin/netmail.%04lx.%04x.%04x",
                        (long) getpid(), CC->cs_pid, ++seqnum);
@@ -1557,6 +1557,13 @@ void CtdlSaveMsg(struct CtdlMessage *msg,        /* message to save */
                CtdlSaveMsgPointerInRoom(actual_rm, newmsgid, 0);
        }
 
+       /* For internet mail, drop a copy in the outbound queue room */
+       /* FIX  ...  nothing's going to get delivered until we add
+          some delivery instructions!!! */
+       if (mailtype == MES_INTERNET) {
+               CtdlSaveMsgPointerInRoom(SMTP_SPOOLOUT_ROOM, newmsgid, 0);
+       }
+
        /* Bump this user's messages posted counter. */
        lprintf(9, "Updating user\n");
        lgetuser(&CC->usersupp, CC->curr_user);
@@ -1615,14 +1622,24 @@ void quickie_message(char *from, char *to, char *room, char *text)
 /*
  * Back end function used by make_message() and similar functions
  */
-char *CtdlReadMessageBody(char *terminator, size_t maxlen) {
+char *CtdlReadMessageBody(char *terminator,    /* token signalling EOT */
+                       size_t maxlen,          /* maximum message length */
+                       char *exist             /* if non-null, append to it;
+                                                  exist is ALWAYS freed  */
+                       ) {
        char buf[256];
        size_t message_len = 0;
        size_t buffer_len = 0;
        char *ptr, *append;
        char *m;
 
-       m = mallok(4096);
+       if (exist == NULL) {
+               m = mallok(4096);
+       }
+       else {
+               m = reallok(exist, strlen(exist) + 4096);
+               if (m == NULL) phree(exist);
+       }
        if (m == NULL) {
                while ( (client_gets(buf)>0) && strcmp(buf, terminator) ) ;;
                return(NULL);
@@ -1741,7 +1758,8 @@ struct CtdlMessage *make_message(
                msg->cm_fields['D'] = strdoop(dest_node);
 
 
-       msg->cm_fields['M'] = CtdlReadMessageBody("000", config.c_maxmsglen);
+       msg->cm_fields['M'] = CtdlReadMessageBody("000",
+                                               config.c_maxmsglen, NULL);
 
 
        return(msg);
index 8193b90d5285832381bd3eda690fa0a2d2dd734b..9cae5ab297f84d11f62d31960367acecb2661af9 100644 (file)
@@ -70,4 +70,4 @@ void serialize_message(struct ser_ret *, struct CtdlMessage *);
 int is_valid_message(struct CtdlMessage *);
 int ReplicationChecks(struct CtdlMessage *);
 int CtdlSaveMsgPointerInRoom(char *roomname, long msgid, int flags);
-char *CtdlReadMessageBody(char *terminator, size_t maxlen);
+char *CtdlReadMessageBody(char *terminator, size_t maxlen, char *exist);
index f8dcb2fd2aeeb1f68d7fa25effd0cdb3f1e6de7f..dfd93087cf68d0d3d22c98487d89af7bb1585fae 100644 (file)
@@ -1,7 +1,5 @@
 /* $Id$ */
 
-#define POP3_PORT      1110
-
 #include "sysdep.h"
 #include <stdlib.h>
 #include <unistd.h>
index 5108ed2faded27bf609b9d40df59955e5522d07d..cc3ce8f4dd594c14f0dd849af947279872878038 100644 (file)
@@ -1,7 +1,5 @@
 /* $Id$ */
 
-#define SMTP_PORT      2525
-
 #include "sysdep.h"
 #include <stdlib.h>
 #include <unistd.h>
@@ -30,6 +28,7 @@
 #include "msgbase.h"
 #include "tools.h"
 #include "internet_addressing.h"
+#include "genstamp.h"
 
 
 struct citsmtp {               /* Information about the current session */
@@ -40,6 +39,7 @@ struct citsmtp {              /* Information about the current session */
        char from[256];
        char recipient[256];
        int number_of_recipients;
+       int delivery_mode;
 };
 
 enum {                         /* Command states for login authentication */
@@ -48,6 +48,11 @@ enum {                               /* Command states for login authentication */
        smtp_password
 };
 
+enum {                         /* Delivery modes */
+       smtp_deliver_local,
+       smtp_deliver_remote
+};
+
 #define SMTP ((struct citsmtp *)CtdlGetUserData(SYM_SMTP))
 
 long SYM_SMTP;
@@ -348,6 +353,7 @@ void smtp_rcpt(char *argbuf) {
 
        strcpy(SMTP->recipient, &argbuf[3]);
        striplt(SMTP->recipient);
+       alias(SMTP->recipient);
 
        cvt = convert_internet_address(user, node, SMTP->recipient);
        switch(cvt) {
@@ -428,6 +434,7 @@ void smtp_data(void) {
        char *body;
        struct CtdlMessage *msg;
        int retval;
+       char nowstamp[256];
 
        if (strlen(SMTP->from) == 0) {
                cprintf("503 Need MAIL command first.\n");
@@ -440,7 +447,18 @@ void smtp_data(void) {
        }
 
        cprintf("354 Transmit message now; terminate with '.' by itself\n");
-       body = CtdlReadMessageBody(".", config.c_maxmsglen);
+       
+       generate_rfc822_datestamp(nowstamp, time(NULL));
+       body = mallok(4096);
+       if (body != NULL) sprintf(body,
+               "Received: from %s\n"
+               "       by %s;\n"
+               "       %s\n",
+                       "FIX.FIX.com",
+                       config.c_fqdn,
+                       nowstamp);
+       
+       body = CtdlReadMessageBody(".", config.c_maxmsglen, body);
        if (body == NULL) {
                cprintf("550 Unable to save message text: internal error.\n");
                return;
@@ -556,12 +574,13 @@ void smtp_command_loop(void) {
 }
 
 
-
 char *Dynamic_Module_Init(void)
 {
        SYM_SMTP = CtdlGetDynamicSymbol();
        CtdlRegisterServiceHook(SMTP_PORT,
                                smtp_greeting,
                                smtp_command_loop);
+       create_room(SMTP_SPOOLOUT_ROOM, 3, "", 0);
        return "$Id$";
 }
+
index 0a7812c11829435df614289c6bf6c569c96dc870..0c2083e53780999c02787950acc3188104f3e408 100644 (file)
@@ -187,6 +187,13 @@ enum {
        MT_DOWNLOAD             /* Download a component */
 };
 
+/*
+ * Message format types in the database
+ */
+#define        FMT_CITADEL     0       /* Citadel vari-format (proprietary) */
+#define FMT_FIXED      1       /* Fixed format (proprietary)        */
+#define FMT_RFC822     4       /* Standard (headers are in M field) */
+
 
 /*
  * Citadel DataBases (define one for each cdb we need to open)
index a32afa728e648a34fddb88998ad96ed56ff05edf..f654a63fdef05a7eec33c3161a3a550d69b699f8 100644 (file)
 #define MAXFLOORS      16              /* Do not set higher than 127       */
 
 /*** END OF STRUCTURE SIZE VARIABLES ***/
+
+
+/* 
+ * These define what port to listen on for various services.
+ * FIX ... put this in a programmable config somewhere
+ */
+#define POP3_PORT              1110
+#define SMTP_PORT              2525
+#define SMTP_SPOOLOUT_ROOM     "__CitadelSMTPspoolout__"