* Implemented BOUNCE BOUNCE BOUNCE
authorArt Cancro <ajc@citadel.org>
Wed, 3 Oct 2001 03:15:16 +0000 (03:15 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 3 Oct 2001 03:15:16 +0000 (03:15 +0000)
citadel/ChangeLog
citadel/msgbase.c
citadel/serv_network.c
citadel/sysconfig.h

index 11f9062863cd601291e008324fc94f3463e49ead..cb110d2123938e0d75ed952a72a0de881414da69 100644 (file)
@@ -1,4 +1,7 @@
  $Log$
+ Revision 580.49  2001/10/03 03:15:16  ajc
+ * Implemented BOUNCE BOUNCE BOUNCE
+
  Revision 580.48  2001/10/02 03:04:30  ajc
  * Allow non-Aides to terminate sessions belonging to them
 
@@ -2765,4 +2768,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import 
-
index df567a28928fab473ecfe10cae5941813b090e3b..8c3e06e8011786c4657b524d79aec441fff89a46 100644 (file)
@@ -1547,7 +1547,7 @@ void serialize_message(struct ser_ret *ret,               /* return values */
                ret->len = ret->len +
                        strlen(msg->cm_fields[(int)forder[i]]) + 2;
 
-       lprintf(9, "calling malloc(%d)\n", ret->len);
+       lprintf(9, "serialize_message() calling malloc(%d)\n", ret->len);
        ret->ser = mallok(ret->len);
        if (ret->ser == NULL) {
                ret->len = 0;
index d28b717e4999ea4bd35cfb4d5bbd1910202d5a10..b18738f7f2dd50b0f2005b7a576706aa220189d5 100644 (file)
@@ -605,6 +605,108 @@ void network_learn_topology(char *node, char *path) {
 
 
 
+
+/*
+ * Bounce a message back to the sender
+ */
+void network_bounce(struct CtdlMessage *msg, char *reason) {
+       static int serialnum = 0;
+       FILE *fp;
+       char filename[SIZ];
+       struct ser_ret sermsg;
+       char *oldpath = NULL;
+       char buf[SIZ];
+
+       lprintf(9, "entering network_bounce()\n");
+
+       if (msg == NULL) return;
+
+       /* 
+        * Give it a fresh message ID
+        */
+       if (msg->cm_fields['I'] != NULL) {
+               phree(msg->cm_fields['I']);
+       }
+       sprintf(buf, "%ld.%04x.%04x@%s",
+               time(NULL), getpid(), ++serialnum, config.c_fqdn);
+       msg->cm_fields['I'] = strdoop(buf);
+
+       /*
+        * FIXME ... right now we're just sending a bounce; we really want to
+        * include the text of the bounced message.
+        */
+       if (msg->cm_fields['M'] != NULL) {
+               phree(msg->cm_fields['M']);
+       }
+       msg->cm_fields['M'] = strdoop(reason);
+       msg->cm_format_type = 0;
+
+       /*
+        * Turn the message around
+        */
+       if (msg->cm_fields['R'] == NULL) {
+               phree(msg->cm_fields['R']);
+       }
+
+       if (msg->cm_fields['D'] == NULL) {
+               phree(msg->cm_fields['D']);
+       }
+
+       msg->cm_fields['R'] = msg->cm_fields['A'];
+       msg->cm_fields['D'] = msg->cm_fields['N'];
+       msg->cm_fields['A'] = strdoop(BOUNCESOURCE);
+       msg->cm_fields['N'] = strdoop(config.c_nodename);
+       
+       if (!strcasecmp(msg->cm_fields['D'], config.c_nodename)) {
+               phree(msg->cm_fields['D']);
+       }
+
+       /*
+        * If this is a bounce of a bounce, send it to the Aide> room
+        * instead of looping around forever
+        */
+       if (msg->cm_fields['D'] == NULL) if (msg->cm_fields['R'] != NULL)
+          if (!strcasecmp(msg->cm_fields['R'], BOUNCESOURCE)) {
+               phree(msg->cm_fields['R']);
+               if (msg->cm_fields['C'] != NULL) {
+                       phree(msg->cm_fields['C']);
+               }
+               msg->cm_fields['C'] = strdoop(AIDEROOM);
+       }
+
+       /* prepend our node to the path */
+       if (msg->cm_fields['P'] != NULL) {
+               oldpath = msg->cm_fields['P'];
+               msg->cm_fields['P'] = NULL;
+       }
+       else {
+               oldpath = strdoop("unknown_user");
+       }
+       msg->cm_fields['P'] = mallok(strlen(oldpath) + SIZ);
+       sprintf(msg->cm_fields['P'], "%s!%s", config.c_nodename, oldpath);
+       phree(oldpath);
+
+       /* serialize the message */
+       serialize_message(&sermsg, msg);
+
+       /* now send it */
+       sprintf(filename, "./network/spoolin/bounce.%04x.%04x",
+               getpid(), serialnum);
+
+       fp = fopen(filename, "ab");
+       if (fp != NULL) {
+               fwrite(sermsg.ser,
+                       sermsg.len, 1, fp);
+               fclose(fp);
+       }
+       phree(sermsg.ser);
+       CtdlFreeMessage(msg);
+       lprintf(9, "leaving network_bounce()\n");
+}
+
+
+
+
 /*
  * Process a buffer containing a single message from a single file
  * from the inbound queue 
@@ -681,7 +783,11 @@ void network_process_buffer(char *buffer, long size) {
                        
                        else {  /* invalid destination node name */
 
-                               /* FIXME bounce the msg */
+                               network_bounce(msg,
+"A message you sent could not be delivered due to an invalid destination node"
+" name.  Please check the address and try sending the message again.\n");
+                               msg = NULL;
+                               return;
 
                        }
                }
@@ -703,13 +809,23 @@ void network_process_buffer(char *buffer, long size) {
                 e = alias(recp);        /* alias and mail type */
                 if ((recp[0] == 0) || (e == MES_ERROR)) {
 
-                       /* FIXME bounce the msg */
+                       network_bounce(msg,
+"A message you sent could not be delivered due to an invalid address.\n"
+"Please check the address and try sending the message again.\n");
+                       msg = NULL;
+                       return;
 
                 }
                 else if (e == MES_LOCAL) {
                         a = getuser(&tempUS, recp);
                         if (a != 0) {
-                               /* FIXME bounce the msg */
+
+                               network_bounce(msg,
+"A message you sent could not be delivered because the user does not exist\n"
+"on this system.  Please check the address and try again.\n");
+                               msg = NULL;
+                               return;
+
                         }
                        else {
                                MailboxName(target_room, &tempUS, MAILROOM);
index 611877f1f1bf815baea16f4946a2abddeeee8ac9..8e17038b0731088ffe524f187ab49a3de22d4bd7 100644 (file)
  */
 #define NETWORK_QUEUE_FREQUENCY 3600   /* Once per hour */
 
+/*
+ * Who bounced messages appear to be from
+ */
+#define BOUNCESOURCE           "Citadel Mail Delivery Subsystem"
+
 /*
  * This variable defines the amount of network spool data that may be carried
  * in one server transfer command.  For some reason, some networks get hung