For messages delivered to a mailing list, add the room name to the subject line,...
authorArt Cancro <ajc@citadel.org>
Sun, 14 Feb 2021 19:19:47 +0000 (14:19 -0500)
committerArt Cancro <ajc@citadel.org>
Sun, 14 Feb 2021 19:19:47 +0000 (14:19 -0500)
citadel/internet_addressing.c
citadel/modules/listdeliver/serv_listdeliver.c
citadel/modules/smtp/serv_smtpclient.c
citadel/msgbase.c

index afa637a..95350af 100644 (file)
@@ -570,8 +570,7 @@ struct recptypes *validate_recipients(const char *supplied_recipients, const cha
                                }
                                strcat(ret->recp_room, this_recp);
                        }
-                       else if ( (!strncasecmp(this_recp, "room_", 5))
-                                 && (!CtdlGetRoom(&tempQR, &this_recp_cooked[5])) ) {
+                       else if ( (!strncasecmp(this_recp, "room_", 5)) && (!CtdlGetRoom(&tempQR, &this_recp_cooked[5])) ) {
 
                                /* Save room so we can restore it later */
                                tempQR2 = CCC->room;
index 039937e..f82a807 100644 (file)
@@ -55,6 +55,7 @@ void listdeliver_do_msg(long msgnum, void *userdata) {
        struct lddata *ld = (struct lddata *) userdata;
        if (!ld) return;
        char buf[SIZ];
+       char *ch;
 
        ld->msgnum = msgnum;
        if (msgnum <= 0) return;
@@ -62,12 +63,27 @@ void listdeliver_do_msg(long msgnum, void *userdata) {
        struct CtdlMessage *TheMessage = CtdlFetchMessage(msgnum, 1);
        if (!TheMessage) return;
 
+       // If the subject line does not contain the name of the room, add it now.
+       if (!bmstrcasestr(TheMessage->cm_fields[eMsgSubject], CC->room.QRname)) {
+               snprintf(buf, sizeof buf, "[%s] %s", CC->room.QRname, TheMessage->cm_fields[eMsgSubject]);
+               CM_SetField(TheMessage, eMsgSubject, buf, strlen(buf));
+       }
+
+       // Reply-to: should be set so that replies come to the list.
+       snprintf(buf, sizeof buf, "room_%s@%s", CC->room.QRname, CtdlGetConfigStr("c_fqdn"));
+       for (ch=buf; *ch; ++ch) {
+               if (isspace(*ch)) *ch = '_';
+       }
+       CM_SetField(TheMessage, eReplyTo, buf, strlen(buf));
+
+       // Errors-to: should be set to our Aide room so we see the notifications.
 
 
-       // FIXME munge the headers so it looks like it came from a mailing list
 
 
 
+
+       // With that out of the way, let's figure out who this message needs to be sent to.
        char *recipients = malloc(strlen(ld->netconf));
        if (recipients) {
                recipients[0] = 0;
@@ -88,10 +104,10 @@ void listdeliver_do_msg(long msgnum, void *userdata) {
                                strcat(recipients, &buf[11]);
                        }
                }
-               syslog(LOG_DEBUG, "\033[33m%s\033[0m", recipients);
                struct recptypes *valid = validate_recipients(recipients, NULL, 0);
                if (valid) {
                        long new_msgnum = CtdlSubmitMsg(TheMessage, valid, "");
+                       syslog(LOG_DEBUG, "listdeliver: original message <%ld> is now <%ld> outgoing to the list", msgnum, new_msgnum);
                        free_recipients(valid);
                }
        }
@@ -123,8 +139,6 @@ void listdeliver_sweep_room(char *roomname) {
                return;                         // no netconfig, no processing, no problem
        }
 
-       syslog(LOG_DEBUG, "listdeliver: sweeping %s", roomname);
-
        config_lines = num_tokens(netconfig, '\n');
        for (i=0; i<config_lines; ++i) {
                extract_token(buf, netconfig, i, '\n', sizeof buf);
@@ -141,7 +155,7 @@ void listdeliver_sweep_room(char *roomname) {
                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);
+               syslog(LOG_INFO, "listdeliver: processed <%d> messages in <%s> for <%d> recipients", number_of_messages_processed, CC->room.QRname, number_of_recipients);
        
                if (number_of_messages_processed > 0) {
                        syslog(LOG_DEBUG, "listdeliver: new lastsent is %ld", ld.msgnum);
@@ -167,10 +181,10 @@ void listdeliver_sweep_room(char *roomname) {
 
                        // Write the new netconfig back to disk
                        SaveRoomNetConfigFile(CC->room.QRnumber, newnetconfig);
-                       free(newnetconfig);
+                       free(newnetconfig);     // this was the new netconfig, free it because we're done with it
                }
        }
-       free(netconfig);
+       free(netconfig);                        // this was the old netconfig, free it even if we didn't do anything
 }
 
 
@@ -223,19 +237,15 @@ void listdeliver_sweep(void) {
        syslog(LOG_DEBUG, "listdeliver: ended");
        last_run = time(NULL);
        doing_listdeliver = 0;
-
-       //exit(0);
 }
 
 
-
 /*
  * Module entry point
  */
 CTDL_MODULE_INIT(listdeliver)
 {
-       if (!threading)
-       {
+       if (!threading) {
                CtdlRegisterSessionHook(listdeliver_sweep, EVT_TIMER, PRIO_AGGR + 50);
        }
        
index e18fe56..ad57314 100644 (file)
@@ -561,7 +561,7 @@ CTDL_MODULE_INIT(smtpclient)
 {
        if (!threading) {
                CtdlRegisterMessageHook(smtp_aftersave, EVT_AFTERSAVE);
-               CtdlRegisterSessionHook(smtp_do_queue, EVT_TIMER, PRIO_AGGR + 50);
+               CtdlRegisterSessionHook(smtp_do_queue, EVT_TIMER, PRIO_AGGR + 51);
                smtp_init_spoolout();
        }
 
index cd15f7c..38b598b 100644 (file)
@@ -140,14 +140,12 @@ eMsgField FieldOrder[]  = {
 static const long NDiskFields = sizeof(FieldOrder) / sizeof(eMsgField);
 
 
-int CM_IsEmpty(struct CtdlMessage *Msg, eMsgField which)
-{
+int CM_IsEmpty(struct CtdlMessage *Msg, eMsgField which) {
        return !((Msg->cm_fields[which] != NULL) && (Msg->cm_fields[which][0] != '\0'));
 }
 
 
-void CM_SetField(struct CtdlMessage *Msg, eMsgField which, const char *buf, long length)
-{
+void CM_SetField(struct CtdlMessage *Msg, eMsgField which, const char *buf, long length) {
        if (Msg->cm_fields[which] != NULL) {
                free (Msg->cm_fields[which]);
        }
@@ -161,8 +159,7 @@ void CM_SetField(struct CtdlMessage *Msg, eMsgField which, const char *buf, long
 }
 
 
-void CM_SetFieldLONG(struct CtdlMessage *Msg, eMsgField which, long lvalue)
-{
+void CM_SetFieldLONG(struct CtdlMessage *Msg, eMsgField which, long lvalue) {
        char buf[128];
        long len;
        len = snprintf(buf, sizeof(buf), "%ld", lvalue);
@@ -170,8 +167,7 @@ void CM_SetFieldLONG(struct CtdlMessage *Msg, eMsgField which, long lvalue)
 }
 
 
-void CM_CutFieldAt(struct CtdlMessage *Msg, eMsgField WhichToCut, long maxlen)
-{
+void CM_CutFieldAt(struct CtdlMessage *Msg, eMsgField WhichToCut, long maxlen) {
        if (Msg->cm_fields[WhichToCut] == NULL)
                return;
 
@@ -183,8 +179,7 @@ void CM_CutFieldAt(struct CtdlMessage *Msg, eMsgField WhichToCut, long maxlen)
 }
 
 
-void CM_FlushField(struct CtdlMessage *Msg, eMsgField which)
-{
+void CM_FlushField(struct CtdlMessage *Msg, eMsgField which) {
        if (Msg->cm_fields[which] != NULL)
                free (Msg->cm_fields[which]);
        Msg->cm_fields[which] = NULL;
@@ -192,8 +187,7 @@ void CM_FlushField(struct CtdlMessage *Msg, eMsgField which)
 }
 
 
-void CM_Flush(struct CtdlMessage *Msg)
-{
+void CM_Flush(struct CtdlMessage *Msg) {
        int i;
 
        if (CM_IsValidMsg(Msg) == 0) {
@@ -206,8 +200,7 @@ void CM_Flush(struct CtdlMessage *Msg)
 }
 
 
-void CM_CopyField(struct CtdlMessage *Msg, eMsgField WhichToPutTo, eMsgField WhichtToCopy)
-{
+void CM_CopyField(struct CtdlMessage *Msg, eMsgField WhichToPutTo, eMsgField WhichtToCopy) {
        long len;
        if (Msg->cm_fields[WhichToPutTo] != NULL) {
                free (Msg->cm_fields[WhichToPutTo]);
@@ -227,8 +220,7 @@ void CM_CopyField(struct CtdlMessage *Msg, eMsgField WhichToPutTo, eMsgField Whi
 }
 
 
-void CM_PrependToField(struct CtdlMessage *Msg, eMsgField which, const char *buf, long length)
-{
+void CM_PrependToField(struct CtdlMessage *Msg, eMsgField which, const char *buf, long length) {
        if (Msg->cm_fields[which] != NULL) {
                long oldmsgsize;
                long newmsgsize;
@@ -253,8 +245,7 @@ void CM_PrependToField(struct CtdlMessage *Msg, eMsgField which, const char *buf
 }
 
 
-void CM_SetAsField(struct CtdlMessage *Msg, eMsgField which, char **buf, long length)
-{
+void CM_SetAsField(struct CtdlMessage *Msg, eMsgField which, char **buf, long length) {
        if (Msg->cm_fields[which] != NULL) {
                free (Msg->cm_fields[which]);
        }
@@ -270,8 +261,7 @@ void CM_SetAsField(struct CtdlMessage *Msg, eMsgField which, char **buf, long le
 }
 
 
-void CM_SetAsFieldSB(struct CtdlMessage *Msg, eMsgField which, StrBuf **buf)
-{
+void CM_SetAsFieldSB(struct CtdlMessage *Msg, eMsgField which, StrBuf **buf) {
        if (Msg->cm_fields[which] != NULL) {
                free (Msg->cm_fields[which]);
        }
@@ -281,8 +271,7 @@ void CM_SetAsFieldSB(struct CtdlMessage *Msg, eMsgField which, StrBuf **buf)
 }
 
 
-void CM_GetAsField(struct CtdlMessage *Msg, eMsgField which, char **ret, long *retlen)
-{
+void CM_GetAsField(struct CtdlMessage *Msg, eMsgField which, char **ret, long *retlen) {
        if (Msg->cm_fields[which] != NULL) {
                *retlen = Msg->cm_lengths[which];
                *ret = Msg->cm_fields[which];
@@ -312,8 +301,7 @@ int CM_IsValidMsg(struct CtdlMessage *msg) {
 }
 
 
-void CM_FreeContents(struct CtdlMessage *msg)
-{
+void CM_FreeContents(struct CtdlMessage *msg) {
        int i;
 
        for (i = 0; i < 256; ++i)
@@ -329,8 +317,7 @@ void CM_FreeContents(struct CtdlMessage *msg)
 /*
  * 'Destructor' for struct CtdlMessage
  */
-void CM_Free(struct CtdlMessage *msg)
-{
+void CM_Free(struct CtdlMessage *msg) {
        if (CM_IsValidMsg(msg) == 0) {
                if (msg != NULL) free (msg);
                return;
@@ -340,8 +327,7 @@ void CM_Free(struct CtdlMessage *msg)
 }
 
 
-int CM_DupField(eMsgField i, struct CtdlMessage *OrgMsg, struct CtdlMessage *NewMsg)
-{
+int CM_DupField(eMsgField i, struct CtdlMessage *OrgMsg, struct CtdlMessage *NewMsg) {
        long len;
        len = OrgMsg->cm_lengths[i];
        NewMsg->cm_fields[i] = malloc(len + 1);
@@ -355,8 +341,7 @@ int CM_DupField(eMsgField i, struct CtdlMessage *OrgMsg, struct CtdlMessage *New
 }
 
 
-struct CtdlMessage * CM_Duplicate(struct CtdlMessage *OrgMsg)
-{
+struct CtdlMessage *CM_Duplicate(struct CtdlMessage *OrgMsg) {
        int i;
        struct CtdlMessage *NewMsg;
 
@@ -488,7 +473,8 @@ void CtdlSetSeen(long *target_msgnums, int num_target_msgnums,
                cdbfr->ptr = NULL;      /* CtdlSetSeen() now owns this memory */
                num_msgs = cdbfr->len / sizeof(long);
                cdb_free(cdbfr);
-       } else {
+       }
+       else {
                return; /* No messages at all?  No further action. */
        }