X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fmodules%2Flistdeliver%2Fserv_listdeliver.c;h=039937e678cda81c0f176b587c14b73b6b4c2495;hb=53d8e6f8d1f18b0085dcfd46d1fc8640381513bc;hp=39006a0b70f235a0af6ea1fae5c99db7ab6e1e09;hpb=cb3eac8fb6440223370d3608c445438000d2b908;p=citadel.git diff --git a/citadel/modules/listdeliver/serv_listdeliver.c b/citadel/modules/listdeliver/serv_listdeliver.c index 39006a0b7..039937e67 100644 --- a/citadel/modules/listdeliver/serv_listdeliver.c +++ b/citadel/modules/listdeliver/serv_listdeliver.c @@ -62,6 +62,12 @@ void listdeliver_do_msg(long msgnum, void *userdata) { struct CtdlMessage *TheMessage = CtdlFetchMessage(msgnum, 1); if (!TheMessage) return; + + + // FIXME munge the headers so it looks like it came from a mailing list + + + char *recipients = malloc(strlen(ld->netconf)); if (recipients) { recipients[0] = 0; @@ -83,14 +89,22 @@ void listdeliver_do_msg(long msgnum, void *userdata) { } } syslog(LOG_DEBUG, "\033[33m%s\033[0m", recipients); - free(recipients); + struct recptypes *valid = validate_recipients(recipients, NULL, 0); + if (valid) { + long new_msgnum = CtdlSubmitMsg(TheMessage, valid, ""); + free_recipients(valid); + } } CM_Free(TheMessage); } -void listdeliver_sweep_room(struct ctdlroom *qrbuf, void *data) { +/* + * Sweep through one room looking for mailing list deliveries to do + */ +void listdeliver_sweep_room(char *roomname) { char *netconfig = NULL; + char *newnetconfig = NULL; long lastsent = 0; char buf[SIZ]; int config_lines; @@ -99,16 +113,18 @@ void listdeliver_sweep_room(struct ctdlroom *qrbuf, void *data) { int number_of_recipients = 0; struct lddata ld; - if (CtdlGetRoom(&CC->room, qrbuf->QRname)) { - syslog(LOG_DEBUG, "listdeliver: no room <%s>", qrbuf->QRname); + if (CtdlGetRoom(&CC->room, roomname)) { + syslog(LOG_DEBUG, "listdeliver: no room <%s>", roomname); return; } - netconfig = LoadRoomNetConfigFile(qrbuf->QRnumber); + netconfig = LoadRoomNetConfigFile(CC->room.QRnumber); if (!netconfig) { return; // no netconfig, no processing, no problem } + syslog(LOG_DEBUG, "listdeliver: sweeping %s", roomname); + config_lines = num_tokens(netconfig, '\n'); for (i=0; i 0) { - syslog(LOG_DEBUG, "listdeliver: processing new messages in <%s> for <%d> recipients", qrbuf->QRname, number_of_recipients); + syslog(LOG_DEBUG, "listdeliver: processing new messages in <%s> for <%d> recipients", CC->room.QRname, number_of_recipients); ld.netconf = netconfig; number_of_messages_processed = CtdlForEachMessage(MSGS_GT, lastsent, NULL, NULL, NULL, listdeliver_do_msg, &ld); syslog(LOG_DEBUG, "listdeliver: processed %d messages", number_of_messages_processed); @@ -130,24 +146,50 @@ void listdeliver_sweep_room(struct ctdlroom *qrbuf, void *data) { if (number_of_messages_processed > 0) { syslog(LOG_DEBUG, "listdeliver: new lastsent is %ld", ld.msgnum); - // FIXME write lastsent back to netconfig - syslog(LOG_DEBUG, "\033[31mBEFORE:<%s>\033[0m", netconfig); - syslog(LOG_DEBUG, "\033[32mAFTER:<%s>\033[0m", netconfig); - - + // Update this room's netconfig with the updated lastsent + netconfig = LoadRoomNetConfigFile(CC->room.QRnumber); + if (!netconfig) { + netconfig = strdup(""); + } + // The new netconfig begins with the new lastsent directive + newnetconfig = malloc(strlen(netconfig) + 1024); + sprintf(newnetconfig, "lastsent|%ld\n", ld.msgnum); + // And then we append all of the old netconfig, minus the old lastsent. Also omit blank lines. + config_lines = num_tokens(netconfig, '\n'); + for (i=0; iroom.QRnumber, newnetconfig); + free(newnetconfig); } } - free(netconfig); } +/* + * Callback for listdeliver_sweep() + * Adds one room to the queue + */ +void listdeliver_queue_room(struct ctdlroom *qrbuf, void *data) { + Array *roomlistarr = (Array *)data; + array_append(roomlistarr, qrbuf->QRname); +} + +/* + * Queue up the list of rooms so we can sweep them for mailing list delivery instructions + */ void listdeliver_sweep(void) { static time_t last_run = 0L; + int i = 0; /* * Run mailing list delivery no more frequently than once every 15 minutes (we should make this configurable) @@ -169,7 +211,15 @@ void listdeliver_sweep(void) { * Go through each room looking for mailing lists to process */ syslog(LOG_DEBUG, "listdeliver: sweep started"); - CtdlForEachRoom(listdeliver_sweep_room, NULL); + + Array *roomlistarr = array_new(ROOMNAMELEN); // we have to queue them + CtdlForEachRoom(listdeliver_queue_room, roomlistarr); // otherwise we get multiple cursors in progress + + for (i=0; i