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];
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 */
StrBuf *RoomInfo;
StrBuf *ListID;
FILE *digestfp;
+ int newDigest;
int num_msgs_spooled;
long lastsent;
recptypes *valid;
char bounce_to[256];
- if (sc->Users[listrecp] == NULL)
+ if (sc->Users[digestrecp] == NULL)
return;
if (sc->num_msgs_spooled < 1) {
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?
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);
FreeStrBuf(&RoomName);
}
+static time_t last_digest_delivery = 0;
/*
* Batch up and send all outbound traffic from the current room
/* 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);
/* 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;
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 */
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]="";
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 */
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);
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)
{