From 47d28f12a14a82a725d0989021febf806b358af5 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Thu, 1 Aug 2002 05:41:53 +0000 Subject: [PATCH] * Completion of (most of) digest mode. Still needs some polish. --- citadel/ChangeLog | 4 +- citadel/serv_network.c | 118 ++++++++++++++++++++++++++++++++++++++--- citadel/serv_network.h | 1 + 3 files changed, 115 insertions(+), 8 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 6b2f269f0..8441fd437 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,4 +1,7 @@ $Log$ + Revision 591.76 2002/08/01 05:41:53 ajc + * Completion of (most of) digest mode. Still needs some polish. + Revision 591.75 2002/07/31 04:01:57 ajc * Began implementing "digest mode" for listserving. (Not complete) @@ -3845,4 +3848,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant Fri Jul 10 1998 Art Cancro * Initial CVS import - diff --git a/citadel/serv_network.c b/citadel/serv_network.c index 47b957f4f..00b044d09 100644 --- a/citadel/serv_network.c +++ b/citadel/serv_network.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -375,20 +376,19 @@ void cmd_snet(char *argbuf) { } - /* * Spools out one message from the list. */ void network_spool_msg(long msgnum, void *userdata) { struct SpoolControl *sc; - struct namelist *nptr; int err; int i; - char *instr = NULL; char *newpath = NULL; + char *instr = NULL; size_t instr_len = SIZ; struct CtdlMessage *msg = NULL; struct CtdlMessage *imsg; + struct namelist *nptr; struct ser_ret sermsg; FILE *fp; char filename[SIZ]; @@ -463,6 +463,7 @@ void network_spool_msg(long msgnum, void *userdata) { CtdlRedirectOutput(sc->digestfp, -1); CtdlOutputMsg(msgnum, MT_RFC822, HEADERS_ALL, 0, 1); CtdlRedirectOutput(NULL, -1); + sc->num_msgs_spooled += 1; } /* @@ -566,6 +567,104 @@ void network_spool_msg(long msgnum, void *userdata) { } +/* + * Deliver digest messages + */ +void network_deliver_digest(struct SpoolControl *sc) { + char buf[SIZ]; + int i; + struct CtdlMessage *msg; + long msglen; + long msgnum; + char *instr = NULL; + size_t instr_len = SIZ; + struct CtdlMessage *imsg; + struct namelist *nptr; + + if (sc->num_msgs_spooled < 1) { + fclose(sc->digestfp); + sc->digestfp = NULL; + return; + } + + msg = mallok(sizeof(struct CtdlMessage)); + memset(msg, 0, sizeof(struct CtdlMessage)); + msg->cm_magic = CTDLMESSAGE_MAGIC; + msg->cm_format_type = FMT_RFC822; + msg->cm_anon_type = MES_NORMAL; + + sprintf(buf, "%ld", time(NULL)); + msg->cm_fields['T'] = strdoop(buf); + + sprintf(buf, "room_%s@%s", CC->quickroom.QRname, config.c_fqdn); + for (i=0; icm_fields['F'] = strdoop(buf); + + msg->cm_fields['A'] = strdoop(CC->quickroom.QRname); + + fseek(sc->digestfp, 0L, SEEK_END); + msglen = ftell(sc->digestfp); + + msg->cm_fields['M'] = mallok(msglen + 1); + fseek(sc->digestfp, 0L, SEEK_SET); + fread(msg->cm_fields['M'], (size_t)msglen, 1, sc->digestfp); + msg->cm_fields['M'][msglen] = 0; + + fclose(sc->digestfp); + sc->digestfp = NULL; + + msgnum = CtdlSubmitMsg(msg, NULL, SMTP_SPOOLOUT_ROOM); + CtdlFreeMessage(msg); + + /* Now generate the delivery instructions */ + + /* + * Figure out how big a buffer we need to allocate + */ + for (nptr = sc->digestrecps; nptr != NULL; nptr = nptr->next) { + instr_len = instr_len + strlen(nptr->name); + } + + /* + * allocate... + */ + lprintf(9, "Generating delivery instructions\n"); + instr = mallok(instr_len); + if (instr == NULL) { + lprintf(1, "Cannot allocate %ld bytes for instr...\n", + (long)instr_len); + abort(); + } + snprintf(instr, instr_len, + "Content-type: %s\n\nmsgid|%ld\nsubmitted|%ld\n" + "bounceto|postmaster@%s\n" , + SPOOLMIME, msgnum, (long)time(NULL), config.c_fqdn ); + + /* Generate delivery instructions for each recipient */ + for (nptr = sc->digestrecps; nptr != NULL; nptr = nptr->next) { + size_t tmp = strlen(instr); + snprintf(&instr[tmp], instr_len - tmp, + "remote|%s|0||\n", nptr->name); + } + + /* + * Generate a message from the instructions + */ + imsg = mallok(sizeof(struct CtdlMessage)); + memset(imsg, 0, sizeof(struct CtdlMessage)); + imsg->cm_magic = CTDLMESSAGE_MAGIC; + imsg->cm_anon_type = MES_NORMAL; + imsg->cm_format_type = FMT_RFC822; + imsg->cm_fields['A'] = strdoop("Citadel"); + imsg->cm_fields['M'] = instr; + + /* Save delivery instructions in spoolout room */ + CtdlSubmitMsg(imsg, NULL, SMTP_SPOOLOUT_ROOM); + CtdlFreeMessage(imsg); +} /* @@ -634,6 +733,7 @@ void network_spoolout_room(char *room_to_spool) { /* If there are digest recipients, we have to build a digest */ if (sc.digestrecps != NULL) { sc.digestfp = tmpfile(); + fprintf(sc.digestfp, "Content-type: text/plain\r\n\r\n"); } /* Do something useful */ @@ -642,11 +742,15 @@ void network_spoolout_room(char *room_to_spool) { /* If we wrote a digest, deliver it and then close it */ if (sc.digestfp != NULL) { - fprintf(sc->digestfp, " -----------------------------------" + fprintf(sc.digestfp, " -----------------------------------" "------------------------------------" - "-------\r\n"); - /* FIXME deliver it! */ - fclose(sc.digestfp); + "-------\r\n" + "You are subscribed to the '%s' " + "list.\r\nTo unsubscribe, blah blah " + "blah FIXME.\r\n", + CC->quickroom.QRname + ); + network_deliver_digest(&sc); /* deliver and close */ } /* Now rewrite the config file */ diff --git a/citadel/serv_network.h b/citadel/serv_network.h index d9e56a0da..1e8c6ef6b 100644 --- a/citadel/serv_network.h +++ b/citadel/serv_network.h @@ -9,6 +9,7 @@ struct SpoolControl { struct namelist *digestrecps; struct namelist *ignet_push_shares; FILE *digestfp; + int num_msgs_spooled; }; struct NetMap { -- 2.39.2