Digest delivery:
authorWilfried Goesgens <dothebart@citadel.org>
Wed, 31 Dec 2014 12:05:20 +0000 (13:05 +0100)
committerWilfried Goesgens <dothebart@citadel.org>
Wed, 31 Dec 2014 12:05:20 +0000 (13:05 +0100)
  - fix pick of wrong address list
  - implement that the digest is only sent once a day.

citadel/include/citadel_dirs.h
citadel/modules/network/netspool.h
citadel/modules/network/serv_netmail.c
citadel/modules/network/serv_netspool.c
citadel/utillib/citadel_dirs.c

index 3a0b6d86e38573f630970387cd37c7c2d6417281..407c1dee0145ef54ef22c549ef52b9a610b1fce5 100644 (file)
@@ -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 */
index 8496c5c5acaafb0ba0563432aa71dcb0d28e2808..55454a7fb581206cd7d5b9073ee48b8688c6173e 100644 (file)
@@ -36,6 +36,7 @@ struct SpoolControl {
        StrBuf *RoomInfo;
        StrBuf *ListID;
        FILE *digestfp;
+       int newDigest;
        int num_msgs_spooled;
        long lastsent;
 
index fd1de7abe71aac452a024a0fa21567395c38be56..2782fbf8f23bf60a4b8a08fe98534b5fe362cac7 100644 (file)
@@ -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);
index 714bb0471918db577cc597c25e9b5d7e05313f45..15f309972537b2592baac01fdfb072bd4d1a5ea0 100644 (file)
@@ -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 */
index 17115df40075354d2f0490b314b5d05c78256247..d9974c90db90f78021133ed964355951ce6eedd4 100644 (file)
@@ -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)
 {