From 2975015a8e6b00893a0ba003f3b086132fb858c8 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Wed, 31 Dec 2014 13:05:20 +0100 Subject: [PATCH] Digest delivery: - fix pick of wrong address list - implement that the digest is only sent once a day. --- citadel/include/citadel_dirs.h | 3 ++ citadel/modules/network/netspool.h | 1 + citadel/modules/network/serv_netmail.c | 8 ++-- citadel/modules/network/serv_netspool.c | 52 ++++++++++++++++++------- citadel/utillib/citadel_dirs.c | 34 ++++++++++++++++ 5 files changed, 79 insertions(+), 19 deletions(-) diff --git a/citadel/include/citadel_dirs.h b/citadel/include/citadel_dirs.h index 3a0b6d86e..407c1dee0 100644 --- a/citadel/include/citadel_dirs.h +++ b/citadel/include/citadel_dirs.h @@ -26,6 +26,7 @@ extern char ctdl_run_dir[PATH_MAX]; extern char ctdl_spool_dir[PATH_MAX]; extern char ctdl_netout_dir[PATH_MAX]; extern char ctdl_netin_dir[PATH_MAX]; +extern char ctdl_netdigest_dir[PATH_MAX]; extern char ctdl_nettmp_dir[PATH_MAX]; extern char ctdl_netcfg_dir[PATH_MAX]; extern char ctdl_bbsbase_dir[PATH_MAX]; @@ -68,4 +69,6 @@ extern size_t assoc_file_name(char *buf, struct ctdlroom *qrbuf, const char *prefix); +extern FILE *create_digest_file(struct ctdlroom *room); +extern void remove_digest_file(struct ctdlroom *room); #endif /* __CITADEL_DIRS_H */ diff --git a/citadel/modules/network/netspool.h b/citadel/modules/network/netspool.h index 8496c5c5a..55454a7fb 100644 --- a/citadel/modules/network/netspool.h +++ b/citadel/modules/network/netspool.h @@ -36,6 +36,7 @@ struct SpoolControl { StrBuf *RoomInfo; StrBuf *ListID; FILE *digestfp; + int newDigest; int num_msgs_spooled; long lastsent; diff --git a/citadel/modules/network/serv_netmail.c b/citadel/modules/network/serv_netmail.c index fd1de7abe..2782fbf8f 100644 --- a/citadel/modules/network/serv_netmail.c +++ b/citadel/modules/network/serv_netmail.c @@ -182,7 +182,7 @@ void network_deliver_digest(SpoolControl *sc) recptypes *valid; char bounce_to[256]; - if (sc->Users[listrecp] == NULL) + if (sc->Users[digestrecp] == NULL) return; if (sc->num_msgs_spooled < 1) { @@ -219,11 +219,9 @@ void network_deliver_digest(SpoolControl *sc) fread(pbuf, (size_t)msglen, 1, sc->digestfp); pbuf[msglen] = '\0'; CM_SetAsField(msg, eMesageText, &pbuf, msglen); - fclose(sc->digestfp); - sc->digestfp = NULL; /* Now generate the delivery instructions */ - if (sc->Users[listrecp] == NULL) + if (sc->Users[digestrecp] == NULL) return; /* Where do we want bounces and other noise to be heard? @@ -231,7 +229,7 @@ void network_deliver_digest(SpoolControl *sc) snprintf(bounce_to, sizeof bounce_to, "room_aide@%s", config.c_fqdn); /* Now submit the message */ - valid = validate_recipients(ChrPtr(sc->Users[listrecp]), NULL, 0); + valid = validate_recipients(ChrPtr(sc->Users[digestrecp]), NULL, 0); if (valid != NULL) { valid->bounce_to = strdup(bounce_to); valid->envelope_from = strdup(bounce_to); diff --git a/citadel/modules/network/serv_netspool.c b/citadel/modules/network/serv_netspool.c index 714bb0471..15f309972 100644 --- a/citadel/modules/network/serv_netspool.c +++ b/citadel/modules/network/serv_netspool.c @@ -332,6 +332,7 @@ void CalcListID(SpoolControl *sc) FreeStrBuf(&RoomName); } +static time_t last_digest_delivery = 0; /* * Batch up and send all outbound traffic from the current room @@ -354,8 +355,12 @@ void network_spoolout_room(SpoolControl *sc) /* If there are digest recipients, we have to build a digest */ if (sc->Users[digestrecp] != NULL) { - sc->digestfp = tmpfile(); - fprintf(sc->digestfp, "Content-type: text/plain\n\n"); + + sc->digestfp = create_digest_file(&sc->room); + sc->newDigest = ftell(sc->digestfp) > 0; + if (sc->newDigest) { + fprintf(sc->digestfp, "Content-type: text/plain\n\n"); + } } CalcListID(sc); @@ -363,11 +368,10 @@ void network_spoolout_room(SpoolControl *sc) /* remember where we started... */ lastsent = sc->lastsent; - /* Do something useful */ + /* Fetch the messages we ought to send & prepare them. */ CtdlForEachMessage(MSGS_GT, sc->lastsent, NULL, NULL, NULL, network_spool_msg, sc); - /* If we wrote a digest, deliver it and then close it */ if (StrLength(sc->Users[roommailalias]) > 0) { long len; @@ -387,17 +391,37 @@ void network_spoolout_room(SpoolControl *sc) buf[i] = tolower(buf[i]); if (isspace(buf[i])) buf[i] = '_'; } + + + /* If we wrote a digest, deliver it and then close it */ if (sc->digestfp != NULL) { - fprintf(sc->digestfp, - " -----------------------------------" - "------------------------------------" - "-------\n" - "You are subscribed to the '%s' " - "list.\n" - "To post to the list: %s\n", - CCC->room.QRname, buf - ); - network_deliver_digest(sc); /* deliver and close */ + time_t now = time(NULL); + time_t secs_today = now % (24 * 60 * 60); + long delta = 0; + + if (last_digest_delivery != 0) { + delta = now - last_digest_delivery; + delta = (24 * 60 * 60) - delta; + } + + if ((secs_today < 300) && + (delta < 300) ) + { + last_digest_delivery = now; + fprintf(sc->digestfp, + " -----------------------------------" + "------------------------------------" + "-------\n" + "You are subscribed to the '%s' " + "list.\n" + "To post to the list: %s\n", + CCC->room.QRname, buf + ); + network_deliver_digest(sc); /* deliver */ + } + fclose(sc->digestfp); + sc->digestfp = NULL; + remove_digest_file(&sc->room); } /* Now rewrite the config file */ diff --git a/citadel/utillib/citadel_dirs.c b/citadel/utillib/citadel_dirs.c index 17115df40..d9974c90d 100644 --- a/citadel/utillib/citadel_dirs.c +++ b/citadel/utillib/citadel_dirs.c @@ -44,6 +44,7 @@ char ctdl_run_dir[PATH_MAX]=""; char ctdl_spool_dir[PATH_MAX]="network"; char ctdl_netout_dir[PATH_MAX]="network/spoolout"; char ctdl_netin_dir[PATH_MAX]="network/spoolin"; +char ctdl_netdigest_dir[PATH_MAX]="network/digest"; char ctdl_nettmp_dir[PATH_MAX]="network/spooltmp"; char ctdl_netcfg_dir[PATH_MAX]="netconfigs"; char ctdl_utilbin_dir[PATH_MAX]=""; @@ -194,11 +195,13 @@ void calc_dirs_n_files(int relh, int home, const char *relhome, char *ctdldir, COMPUTE_DIRECTORY(ctdl_spool_dir); COMPUTE_DIRECTORY(ctdl_netout_dir); COMPUTE_DIRECTORY(ctdl_netin_dir); + COMPUTE_DIRECTORY(ctdl_netdigest_dir); COMPUTE_DIRECTORY(ctdl_nettmp_dir); StripSlashes(ctdl_spool_dir, 1); StripSlashes(ctdl_netout_dir, 1); StripSlashes(ctdl_netin_dir, 1); + StripSlashes(ctdl_netdigest_dir, 1); StripSlashes(ctdl_nettmp_dir, 1); /* ok, now we know the dirs, calc some commonly used files */ @@ -330,6 +333,7 @@ void calc_dirs_n_files(int relh, int home, const char *relhome, char *ctdldir, DBG_PRINT(ctdl_spool_dir); DBG_PRINT(ctdl_netout_dir); DBG_PRINT(ctdl_netin_dir); + DBG_PRINT(ctdl_netdigest_dir); DBG_PRINT(ctdl_nettmp_dir); DBG_PRINT(ctdl_netcfg_dir); DBG_PRINT(ctdl_bbsbase_dir); @@ -364,6 +368,36 @@ size_t assoc_file_name(char *buf, size_t n, return snprintf(buf, n, "%s%ld", prefix, qrbuf->QRnumber); } +void remove_digest_file(struct ctdlroom *room) +{ + char buf[PATH_MAX]; + + snprintf(buf, PATH_MAX, "%s/%ld.eml", + ctdl_netdigest_dir, + room->QRnumber); + StripSlashes(buf, 0); + fprintf(stderr, "----> %s \n", buf); + unlink(buf); +} + +FILE *create_digest_file(struct ctdlroom *room) +{ + char buf[PATH_MAX]; + FILE *fp; + + snprintf(buf, PATH_MAX, "%s/%ld.eml", + ctdl_netdigest_dir, + room->QRnumber); + StripSlashes(buf, 0); + fprintf(stderr, "----> %s \n", buf); + + fp = fopen(buf, "w+"); + if (fp == NULL) { + + } + return fp; +} + int create_dir(char *which, long ACCESS, long UID, long GID) { -- 2.30.2