]> code.citadel.org Git - citadel.git/blobdiff - citadel/serv_smtp.c
* Finished the inbound side of gateway domain service
[citadel.git] / citadel / serv_smtp.c
index 8dd3b6554ed52ff263d4466fbfb336f350a501e2..8a7a3147c54749255e969ca12875d64f43321fc0 100644 (file)
@@ -30,7 +30,6 @@
 #include "msgbase.h"
 #include "tools.h"
 #include "internet_addressing.h"
-#include "ignet.h"
 #include "genstamp.h"
 #include "domain.h"
 #include "clientsocket.h"
@@ -373,6 +372,7 @@ void smtp_rcpt(char *argbuf) {
 
        cvt = convert_internet_address(user, node, recp);
        sprintf(recp, "%s@%s", user, node);
+       lprintf(9, "cvt=%d, citaddr=<%s@%s>\n", cvt, user, node);
 
        switch(cvt) {
                case rfc822_address_locally_validated:
@@ -399,7 +399,19 @@ void smtp_rcpt(char *argbuf) {
                        cprintf("550 %s: no such user\r\n", recp);
                        return;
 
-               case rfc822_address_invalid:
+               case rfc822_address_on_citadel_network:
+                       cprintf("250 %s is on the local network\r\n", recp);
+                       ++SMTP->number_of_recipients;
+                       CtdlReallocUserData(SYM_SMTP_RECP,
+                               strlen(SMTP_RECP) + 1024 );
+                       strcat(SMTP_RECP, "ignet|");
+                       strcat(SMTP_RECP, user);
+                       strcat(SMTP_RECP, "|");
+                       strcat(SMTP_RECP, node);
+                       strcat(SMTP_RECP, "|0|\n");
+                       return;
+
+               case rfc822_address_nonlocal:
                        if (is_spam) {
                                cprintf("551 Away with thee, spammer!\r\n");
                        }
@@ -421,6 +433,44 @@ void smtp_rcpt(char *argbuf) {
 
 
 
+/*
+ * Send a message out through the local network
+ * (This is kind of ugly.  IGnet should be done using clean server-to-server
+ * code instead of the old style spool.)
+ */
+void smtp_deliver_ignet(struct CtdlMessage *msg, char *user, char *dest) {
+       struct ser_ret smr;
+       char *hold_R, *hold_D;
+       FILE *fp;
+       char filename[256];
+       static int seq = 0;
+
+       lprintf(9, "smtp_deliver_ignet(msg, %s, %s)\n", user, dest);
+
+       hold_R = msg->cm_fields['R'];
+       hold_D = msg->cm_fields['D'];
+       msg->cm_fields['R'] = user;
+       msg->cm_fields['D'] = dest;
+
+       serialize_message(&smr, msg);
+
+       msg->cm_fields['R'] = hold_R;
+       msg->cm_fields['D'] = hold_D;
+
+       if (smr.len != 0) {
+               sprintf(filename, "./network/spoolin/%s.%04x.%04x",
+                       dest, getpid(), ++seq);
+               lprintf(9, "spool file name is <%s>\n", filename);
+               fp = fopen(filename, "wb");
+               if (fp != NULL) {
+                       fwrite(smr.ser, smr.len, 1, fp);
+                       fclose(fp);
+               }
+               phree(smr.ser);
+       }
+
+}
+
 
 
 /*
@@ -489,6 +539,13 @@ int smtp_message_delivery(struct CtdlMessage *msg) {
                        ++successful_saves;
                }
 
+               /* Delivery over the local Citadel network (IGnet) */
+               if (!strcasecmp(dtype, "ignet")) {
+                       extract(user, buf, 1);
+                       extract(node, buf, 2);
+                       smtp_deliver_ignet(msg, user, node);
+               }
+
                /* Remote delivery */
                if (!strcasecmp(dtype, "remote")) {
                        extract(user, buf, 1);
@@ -706,18 +763,6 @@ void smtp_try(char *key, char *addr, int *status, char *dsn, long msgnum)
        /* Parse out the host portion of the recipient address */
        process_rfc822_addr(addr, user, node, name);
 
-       if (is_ignet(node)) {
-               if (ignet_spool_to(node, msgnum) == 0) {
-                       strcpy(dsn, "Delivery via Citadel network successful");
-                       *status = 2;
-               }
-               else {
-                       strcpy(dsn, "Delivery via Citadel network failed");
-                       *status = 5;
-               }
-               return;
-       }
-
        lprintf(9, "Attempting SMTP delivery to <%s> @ <%s> (%s)\n",
                user, node, name);
 
@@ -816,12 +861,12 @@ void smtp_try(char *key, char *addr, int *status, char *dsn, long msgnum)
        if (buf[0] != '2') {
                if (buf[0] == '4') {
                        *status = 4;
-                       strcpy(dsn, &buf[4]);
+                       safestrncpy(dsn, &buf[4], 1023);
                        goto bail;
                }
                else {
                        *status = 5;
-                       strcpy(dsn, &buf[4]);
+                       safestrncpy(dsn, &buf[4], 1023);
                        goto bail;
                }
        }
@@ -841,12 +886,12 @@ void smtp_try(char *key, char *addr, int *status, char *dsn, long msgnum)
        if (buf[0] != '2') {
                if (buf[0] == '4') {
                        *status = 4;
-                       strcpy(dsn, &buf[4]);
+                       safestrncpy(dsn, &buf[4], 1023);
                        goto bail;
                }
                else {
                        *status = 5;
-                       strcpy(dsn, &buf[4]);
+                       safestrncpy(dsn, &buf[4], 1023);
                        goto bail;
                }
        }
@@ -865,12 +910,12 @@ void smtp_try(char *key, char *addr, int *status, char *dsn, long msgnum)
        if (buf[0] != '2') {
                if (buf[0] == '4') {
                        *status = 4;
-                       strcpy(dsn, &buf[4]);
+                       safestrncpy(dsn, &buf[4], 1023);
                        goto bail;
                }
                else {
                        *status = 5;
-                       strcpy(dsn, &buf[4]);
+                       safestrncpy(dsn, &buf[4], 1023);
                        goto bail;
                }
        }
@@ -889,12 +934,12 @@ void smtp_try(char *key, char *addr, int *status, char *dsn, long msgnum)
        if (buf[0] != '2') {
                if (buf[0] == '4') {
                        *status = 4;
-                       strcpy(dsn, &buf[4]);
+                       safestrncpy(dsn, &buf[4], 1023);
                        goto bail;
                }
                else {
                        *status = 5;
-                       strcpy(dsn, &buf[4]);
+                       safestrncpy(dsn, &buf[4], 1023);
                        goto bail;
                }
        }
@@ -912,12 +957,12 @@ void smtp_try(char *key, char *addr, int *status, char *dsn, long msgnum)
        if (buf[0] != '3') {
                if (buf[0] == '4') {
                        *status = 3;
-                       strcpy(dsn, &buf[4]);
+                       safestrncpy(dsn, &buf[4], 1023);
                        goto bail;
                }
                else {
                        *status = 5;
-                       strcpy(dsn, &buf[4]);
+                       safestrncpy(dsn, &buf[4], 1023);
                        goto bail;
                }
        }
@@ -947,18 +992,18 @@ void smtp_try(char *key, char *addr, int *status, char *dsn, long msgnum)
        if (buf[0] != '2') {
                if (buf[0] == '4') {
                        *status = 4;
-                       strcpy(dsn, &buf[4]);
+                       safestrncpy(dsn, &buf[4], 1023);
                        goto bail;
                }
                else {
                        *status = 5;
-                       strcpy(dsn, &buf[4]);
+                       safestrncpy(dsn, &buf[4], 1023);
                        goto bail;
                }
        }
 
        /* We did it! */
-       strcpy(dsn, &buf[4]);
+       safestrncpy(dsn, &buf[4], 1023);
        *status = 2;
 
        lprintf(9, ">QUIT\n");