* Wrote enough of the SMTP sender to get Patriot drooling over it, but not
authorArt Cancro <ajc@citadel.org>
Tue, 25 Jan 2000 04:45:50 +0000 (04:45 +0000)
committerArt Cancro <ajc@citadel.org>
Tue, 25 Jan 2000 04:45:50 +0000 (04:45 +0000)
  enough to complete the transmission of mail.

citadel/ChangeLog
citadel/clientsocket.c
citadel/clientsocket.h
citadel/msgbase.c
citadel/serv_smtp.c
citadel/sysconfig.h

index 8260a195f140a8cedd3c83bb3a251d4dc5f75e67..05689b35974bef8bddc3b4b6cfbf1057c6a508db 100644 (file)
@@ -1,4 +1,8 @@
 $Log$
+Revision 1.452  2000/01/25 04:45:50  ajc
+* Wrote enough of the SMTP sender to get Patriot drooling over it, but not
+  enough to complete the transmission of mail.
+
 Revision 1.451  2000/01/23 21:25:45  ajc
 * Temporary hack to ig_tcp_server() to listen on an arbitrary port if the
   one specified is not bindable (for development only)
@@ -1586,4 +1590,3 @@ 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 710df1a3fcde4f057e607b291618380dc33fdd63..3c5e94caf928db5dd84bb3ce5bbc7a604784f722 100644 (file)
@@ -159,6 +159,7 @@ int sock_gets(int sock, char *buf)
 
        /* Strip any trailing CR and LF characters.
         */
+       buf[i] = 0;
        while ( (strlen(buf)>0)
              && ((buf[strlen(buf)-1]==13)
              || (buf[strlen(buf)-1]==10)) ) {
index 0185fdf249331c061610dfdbb949468e46450700..9ff18c8902223b2f8a29fd532f25f1361d54609f 100644 (file)
@@ -6,9 +6,9 @@
 
 int sock_connect(char *host, char *service, char *protocol);
 int sock_read(int sock, char *buf, int bytes);
-int sock_write(int sock, *buf, int nbytes);
-int *sock_gets(int sock, *buf);
-int sock_puts(int sock, *buf);
+int sock_write(int sock, char *buf, int nbytes);
+int sock_gets(int sock, char *buf);
+int sock_puts(int sock, char *buf);
 
 /* 
  * This looks dumb, but it's being done for future portability
index dca9cbb0cd10282829d7322112a218c7bb70641f..867ff964a8b57089e965ffb2a66b42aca2b054f3 100644 (file)
@@ -289,9 +289,7 @@ void CtdlForEachMessage(int mode, long ref,
                if (content_type != NULL)
                        if (strlen(content_type) > 0)
                                for (a = 0; a < num_msgs; ++a) {
-                                       lprintf(9, "Trying %ld\n", msglist[a]);
                                        GetSuppMsgInfo(&smi, msglist[a]);
-                                       lprintf(9, "ct is %s\n", smi.smi_content_type);
                                        if (strcasecmp(smi.smi_content_type, content_type)) {
                                                msglist[a] = 0L;
                                        }
@@ -1628,8 +1626,16 @@ long CtdlSaveMsg(struct CtdlMessage *msg,        /* message to save */
        }
 
        lprintf(9, "Possibly relocating\n");
-       if (strcasecmp(actual_rm, CC->quickroom.QRname))
+       if (strcasecmp(actual_rm, CC->quickroom.QRname)) {
                getroom(&CC->quickroom, actual_rm);
+       }
+
+       /*
+        * If this message has no O (room) field, generate one.
+        */
+       if (msg->cm_fields['O'] == NULL) {
+               msg->cm_fields['O'] = strdoop(CC->quickroom.QRname);
+       }
 
        /* Perform "before save" hooks (aborting if any return nonzero) */
        lprintf(9, "Performing before-save hooks\n");
index cffda13022c518dba91f1c04a0374ee94105509d..fb01d6329c5994ed929bf0125de068091ef14f6c 100644 (file)
@@ -29,6 +29,8 @@
 #include "tools.h"
 #include "internet_addressing.h"
 #include "genstamp.h"
+#include "domain.h"
+#include "clientsocket.h"
 
 
 struct citsmtp {               /* Information about the current session */
@@ -676,13 +678,105 @@ void smtp_command_loop(void) {
  *
  */
 void smtp_try(char *key, char *addr, int *status, char *dsn) {
+       char buf[256];
+       int sock = (-1);
+       char mxhosts[1024];
+       int num_mxhosts;
+       int mx;
+       char user[256], node[256], name[256];
+
+       /* Parse out the host portion of the recipient address */
+       process_rfc822_addr(addr, user, node, name);
+       lprintf(9, "Attempting SMTP delivery to <%s> @ <%s> (%s)\n",
+               user, node, name);
+
+       num_mxhosts = getmx(mxhosts, node);
+       lprintf(9, "Number of MX hosts for <%s> is %d\n", node, num_mxhosts);
+       if (num_mxhosts < 1) {
+               *status = 5;
+               sprintf(dsn, "No MX hosts found for <%s>", node);
+               return;
+       }
+
+       for (mx=0; mx<num_mxhosts; ++mx) {
+               extract(buf, mxhosts, mx);
+               lprintf(9, "Trying <%s>\n", buf);
+               sock = sock_connect(buf, "25", "tcp");
+               sprintf(dsn, "Could not connect: %s", strerror(errno));
+               if (sock >= 0) lprintf(9, "Connected!\n");
+               if (sock < 0) sprintf(dsn, "%s", strerror(errno));
+               if (sock >= 0) break;
+       }
+
+       if (sock < 0) {
+               *status = 3;    /* dsn is already filled in */
+               return;
+       }
+
+       /* Process the SMTP greeting from the server */
+       if (sock_gets(sock, buf) < 0) {
+               *status = 3;
+               strcpy(dsn, "Connection broken during SMTP conversation");
+               sock_close(sock);
+               return;
+       }
+       lprintf(9, "%s\n", buf);
+       if (buf[0] != '2') {
+               if (buf[0] == '3') {
+                       *status = 3;
+                       strcpy(dsn, &buf[4]);
+                       sock_close(sock);
+                       return;
+               }
+               else {
+                       *status = 5;
+                       strcpy(dsn, &buf[4]);
+                       sock_close(sock);
+                       return;
+               }
+       }
+
+       /* At this point we know we are talking to a real SMTP server */
+
+       /* Do a HELO command */
+       sprintf(buf, "HELO %s", config.c_fqdn);
+       sock_puts(sock, buf);
+       if (sock_gets(sock, buf) < 0) {
+               *status = 3;
+               strcpy(dsn, "Connection broken during SMTP conversation");
+               sock_close(sock);
+               return;
+       }
+       lprintf(9, "%s\n", buf);
+       if (buf[0] != '2') {
+               if (buf[0] == '3') {
+                       *status = 3;
+                       strcpy(dsn, &buf[4]);
+                       sock_close(sock);
+                       return;
+               }
+               else {
+                       *status = 5;
+                       strcpy(dsn, &buf[4]);
+                       sock_close(sock);
+                       return;
+               }
+       }
 
+       sock_puts(sock, "QUIT");
+       sock_gets(sock, buf);
+       lprintf(9, "%s\n", buf);
+       sock_close(sock);
+
+       /* temporary hook to make things not go kerblooie */
        *status = 3;
        strcpy(dsn, "smtp_try() is not finished yet");
+       /*                                                */
 }
 
 
 
+
 /*
  * smtp_do_procmsg()
  *
@@ -716,7 +810,7 @@ void smtp_do_procmsg(long msgnum) {
                extract_token(buf, instr, i, '\n');
                if (num_tokens(buf, '|') < 2) {
                        lprintf(9, "removing <%s>\n", buf);
-                       remove_token(instr, i, '|');
+                       remove_token(instr, i, '\n');
                        --lines;
                        --i;
                }
@@ -785,7 +879,10 @@ void smtp_do_procmsg(long msgnum) {
        msg->cm_magic = CTDLMESSAGE_MAGIC;
        msg->cm_anon_type = MES_NORMAL;
        msg->cm_format_type = FMT_RFC822;
-       msg->cm_fields['M'] = instr;
+       msg->cm_fields['M'] = malloc(strlen(instr)+256);
+       sprintf(msg->cm_fields['M'],
+               "Content-type: %s\n\n%s\n", SPOOLMIME, instr);
+       phree(instr);
        CtdlSaveMsg(msg, "", SMTP_SPOOLOUT_ROOM, MES_LOCAL, 1);
        CtdlFreeMessage(msg);
 }
index 3ce4597f87e514ffb5fca948d6931d33a2f09ebd..198f7e557144b00ffd2536dd8a8d17742de1fcee 100644 (file)
@@ -83,8 +83,8 @@
  * 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 POP3_PORT              110
+#define SMTP_PORT              25
 
 
 /*