From f3191f2926a4f724d890d2a3c28f198adb4cd03d Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Wed, 3 Oct 2001 03:15:16 +0000 Subject: [PATCH] * Implemented BOUNCE BOUNCE BOUNCE --- citadel/ChangeLog | 4 +- citadel/msgbase.c | 2 +- citadel/serv_network.c | 122 ++++++++++++++++++++++++++++++++++++++++- citadel/sysconfig.h | 5 ++ 4 files changed, 128 insertions(+), 5 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 11f906286..cb110d212 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -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 Fri Jul 10 1998 Art Cancro * Initial CVS import - diff --git a/citadel/msgbase.c b/citadel/msgbase.c index df567a289..8c3e06e80 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -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; diff --git a/citadel/serv_network.c b/citadel/serv_network.c index d28b717e4..b18738f7f 100644 --- a/citadel/serv_network.c +++ b/citadel/serv_network.c @@ -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); diff --git a/citadel/sysconfig.h b/citadel/sysconfig.h index 611877f1f..8e17038b0 100644 --- a/citadel/sysconfig.h +++ b/citadel/sysconfig.h @@ -96,6 +96,11 @@ */ #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 -- 2.30.2