* Coded up the "bounce" functions. Still a coupla bugs.
authorArt Cancro <ajc@citadel.org>
Fri, 18 Feb 2000 22:29:21 +0000 (22:29 +0000)
committerArt Cancro <ajc@citadel.org>
Fri, 18 Feb 2000 22:29:21 +0000 (22:29 +0000)
citadel/ChangeLog
citadel/msgbase.c
citadel/serv_smtp.c
citadel/sysconfig.h
citadel/techdoc/delivery-list.txt

index 388dac6b4a7b5509422bc21baa3a2a9f4f1953c4..d9be4ed01fad062d307ad4de338eded2ce342b03 100644 (file)
@@ -1,4 +1,7 @@
 $Log$
+Revision 1.464  2000/02/18 22:29:18  ajc
+* Coded up the "bounce" functions.  Still a coupla bugs.
+
 Revision 1.463  2000/02/18 05:10:50  ajc
 * Made the <.ASI> command a bit friendlier.
 * SMTP sender now pays attention to "smarthost" entries in the system's
@@ -1640,4 +1643,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 067d4e28c3209faf5fd43a86d9d997af86591e37..9dde1f53549da3d3844011ac017237296eec50a6 100644 (file)
@@ -674,10 +674,13 @@ void CtdlFreeMessage(struct CtdlMessage *msg)
        if (is_valid_message(msg) == 0) return;
 
        for (i = 0; i < 256; ++i)
-               if (msg->cm_fields[i] != NULL)
+               if (msg->cm_fields[i] != NULL) {
+                       lprintf(9, "phreeing %c\n", i);
                        phree(msg->cm_fields[i]);
+               }
 
        msg->cm_magic = 0;      /* just in case */
+       lprintf(9, "phreeing msg\n");
        phree(msg);
 }
 
@@ -1675,8 +1678,11 @@ long CtdlSaveMsg(struct CtdlMessage *msg,        /* message to save */
                instr = mallok(2048);
                sprintf(instr,
                        "Content-type: %s\n\nmsgid|%ld\nsubmitted|%ld\n"
+                       "bounceto|%s@%s\n"
                        "remote|%s|0||\n",
-                       SPOOLMIME, newmsgid, time(NULL), recipient );
+                       SPOOLMIME, newmsgid, time(NULL),
+                       msg->cm_fields['A'], msg->cm_fields['N'],
+                       recipient );
 
                imsg = mallok(sizeof(struct CtdlMessage));
                memset(imsg, 0, sizeof(struct CtdlMessage));
index 61a5e5ef3476d3423462e9e58813a4be23b9130c..f4b601491d4f96ec111886023971cd01fc23ea22 100644 (file)
@@ -459,8 +459,10 @@ int smtp_message_delivery(struct CtdlMessage *msg) {
        ++successful_saves;
 
        instr = mallok(1024);
-       sprintf(instr, "Content-type: %s\n\nmsgid|%ld\nsubmitted|%ld\n",
-               SPOOLMIME, msgid, time(NULL) );
+       sprintf(instr, "Content-type: %s\n\nmsgid|%ld\nsubmitted|%ld\n"
+                       "bounceto|%s\n",
+               SPOOLMIME, msgid, time(NULL),
+               SMTP->from );
 
        for (i=0; i<SMTP->number_of_recipients; ++i) {
                extract_token(buf, SMTP_RECP, i, '\n');
@@ -958,8 +960,112 @@ bail:     if (msg_fp != NULL) fclose(msg_fp);
 
 
 /*
- * smtp_purge_completed_deliveries() is caled by smtp_do_procmsg() to remove
- * all of the completed deliveries from a set of delivery instructions.
+ * smtp_do_bounce() is caled by smtp_do_procmsg() to scan a set of delivery
+ * instructions for "5" codes (permanent fatal errors) and produce/deliver
+ * a "bounce" message (delivery status notification).
+ */
+void smtp_do_bounce(char *instr) {
+       int i;
+       int lines;
+       int status;
+       char buf[1024];
+       char key[1024];
+       char addr[1024];
+       char dsn[1024];
+       char bounceto[1024];
+       int num_bounces = 0;
+       int bounce_this = 0;
+       long bounce_msgid = (-1);
+       struct CtdlMessage *bmsg = NULL;
+
+       lprintf(9, "smtp_do_bounce() called\n");
+       strcpy(bounceto, "");
+
+       bmsg = (struct CtdlMessage *) mallok(sizeof(struct CtdlMessage));
+       if (bmsg == NULL) return;
+       memset(bmsg, 0, sizeof(struct CtdlMessage));
+
+        bmsg->cm_magic = CTDLMESSAGE_MAGIC;
+        bmsg->cm_anon_type = MES_NORMAL;
+        bmsg->cm_format_type = 1;
+        bmsg->cm_fields['A'] = strdoop("Citadel");
+        bmsg->cm_fields['N'] = strdoop(config.c_nodename);
+        bmsg->cm_fields['M'] = strdoop(
+               "BOUNCE!  BOUNCE!!  BOUNCE!!!\n\n"
+               "FIX ... this message should be made to look nice and stuff.\n"
+               "In the meantime, you should be aware that the following\n"
+               "recipient addresses had permanent fatal errors:\n\n");
+
+       lines = num_tokens(instr, '\n');
+       for (i=0; i<lines; ++i) {
+               extract_token(buf, instr, i, '\n');
+               extract(key, buf, 0);
+               extract(addr, buf, 1);
+               status = extract_int(buf, 2);
+               extract(dsn, buf, 3);
+               bounce_this = 0;
+
+               lprintf(9, "key=<%s> addr=<%s> status=%d dsn=<%s>\n",
+                       key, addr, status, dsn);
+
+               if (!strcasecmp(key, "bounceto")) {
+                       strcpy(bounceto, addr);
+               }
+
+               if (
+                  (!strcasecmp(key, "local"))
+                  || (!strcasecmp(key, "remote"))
+                  || (!strcasecmp(key, "ignet"))
+                  || (!strcasecmp(key, "room"))
+               ) {
+                       if (status == 5) bounce_this = 1;
+               }
+
+               if (bounce_this) {
+                       ++num_bounces;
+
+                       /*  FIX put this back in!
+                       bmsg->cm_fields['M'] = reallok(bmsg->cm_fields['M'],
+                               strlen(bmsg->cm_fields['M'] + 1024) );
+                       strcat(bmsg->cm_fields['M'], addr);
+                       strcat(bmsg->cm_fields['M'], ": ");
+                       strcat(bmsg->cm_fields['M'], dsn);
+                       strcat(bmsg->cm_fields['M'], "\n");
+                       */
+
+                       remove_token(instr, i, '\n');
+                       --i;
+                       --lines;
+               }
+       }
+
+       /* Deliver the bounce if there's anything worth mentioning */
+       lprintf(9, "num_bounces = %d\n", num_bounces);
+       if (num_bounces > 0) {
+
+               /* First try the user who sent the message   FIX
+               lprintf(9, "bounce to user? <%s>\n", bounceto);
+               if (strlen(bounceto) == 0) bounce_msgid = (-1L);
+               else bounce_msgid = CtdlSaveMsg(bmsg,
+                       bounceto,
+                       "", MES_LOCAL, 1);
+               */
+
+               /* Otherwise, go to the Aide> room */
+               lprintf(9, "bounce to room?\n");
+               if (bounce_msgid < 0L) bounce_msgid = CtdlSaveMsg(bmsg,
+                       "", AIDEROOM,
+                       MES_LOCAL, 1);
+       }
+
+       CtdlFreeMessage(bmsg);
+       lprintf(9, "Done processing bounces\n");
+}
+
+
+/*
+ * smtp_purge_completed_deliveries() is caled by smtp_do_procmsg() to scan a
+ * set of delivery instructions for completed deliveries and remove them.
  *
  * It returns the number of incomplete deliveries remaining.
  */
@@ -1102,10 +1208,10 @@ void smtp_do_procmsg(long msgnum) {
        }
 
 
+       /* Generate 'bounce' messages */
+       smtp_do_bounce(instr);
 
-       /*
-        * Go through the delivery list, deleting completed deliveries
-        */
+       /* Go through the delivery list, deleting completed deliveries */
        incomplete_deliveries_remaining = 
                smtp_purge_completed_deliveries(instr);
 
@@ -1133,7 +1239,8 @@ void smtp_do_procmsg(long msgnum) {
                msg->cm_format_type = FMT_RFC822;
                msg->cm_fields['M'] = malloc(strlen(instr)+256);
                sprintf(msg->cm_fields['M'],
-                       "Content-type: %s\n\n%s\n", SPOOLMIME, instr);
+                       "Content-type: %s\n\n%s\nattempted|%ld\n",
+                       SPOOLMIME, instr, time(NULL) );
                phree(instr);
                CtdlSaveMsg(msg, "", SMTP_SPOOLOUT_ROOM, MES_LOCAL, 1);
                CtdlFreeMessage(msg);
index 198f7e557144b00ffd2536dd8a8d17742de1fcee..3ce4597f87e514ffb5fca948d6931d33a2f09ebd 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              110
-#define SMTP_PORT              25
+#define POP3_PORT              1110
+#define SMTP_PORT              2525
 
 
 /*
index 799c2155078ef0df57784db546b60377948ece51..b6c3880dd6fc503a69eab8acfedf087aed639f5a 100644 (file)
@@ -40,6 +40,22 @@ each line.
     the system.
  
  
+ INSTRUCTION:  attempted
+ SYNTAX:       attempted|999999999
+ DESCRIPTION:
+    Contains a timestamp designating the date/time of the last delivery
+    attempt.
+ INSTRUCTION:  bounceto
+ SYNTAX:       bounceto|Big Bad Sender[@host]
+ DESCRIPTION:
+    Where to send "bounce" messages (delivery status notifications).  The
+    contents of the second field are supplied as the "recipient" field to
+    CtdlSaveMsg(), and therefore may be a local username, a user on another
+    Citadel, or an Internet e-mail address.
  INSTRUCTION:  local
  SYNTAX:       local|Friko Mumjiboolean|0
  DESCRIPTION: