From a47ba867a090bf443d5a9752298d8f6cc39dfb38 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Fri, 18 Feb 2000 22:29:21 +0000 Subject: [PATCH] * Coded up the "bounce" functions. Still a coupla bugs. --- citadel/ChangeLog | 4 +- citadel/msgbase.c | 10 ++- citadel/serv_smtp.c | 123 ++++++++++++++++++++++++++++-- citadel/sysconfig.h | 4 +- citadel/techdoc/delivery-list.txt | 16 ++++ 5 files changed, 144 insertions(+), 13 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 388dac6b4..d9be4ed01 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -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 Fri Jul 10 1998 Art Cancro * Initial CVS import - diff --git a/citadel/msgbase.c b/citadel/msgbase.c index 067d4e28c..9dde1f535 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -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)); diff --git a/citadel/serv_smtp.c b/citadel/serv_smtp.c index 61a5e5ef3..f4b601491 100644 --- a/citadel/serv_smtp.c +++ b/citadel/serv_smtp.c @@ -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; inumber_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 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); diff --git a/citadel/sysconfig.h b/citadel/sysconfig.h index 198f7e557..3ce4597f8 100644 --- a/citadel/sysconfig.h +++ b/citadel/sysconfig.h @@ -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 /* diff --git a/citadel/techdoc/delivery-list.txt b/citadel/techdoc/delivery-list.txt index 799c21550..b6c3880dd 100644 --- a/citadel/techdoc/delivery-list.txt +++ b/citadel/techdoc/delivery-list.txt @@ -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: -- 2.30.2