NETWORKER: add from addresses and new way of setting list headers.
authorWilfried Goesgens <dothebart@citadel.org>
Sun, 17 Feb 2013 16:23:27 +0000 (17:23 +0100)
committerWilfried Goesgens <dothebart@citadel.org>
Sun, 17 Feb 2013 16:23:27 +0000 (17:23 +0100)
citadel/Makefile.in
citadel/debian/rules
citadel/modules/network/netspool.h
citadel/modules/network/serv_netmail.c
citadel/modules/network/serv_network.c
citadel/room_ops.c

index f4a23a539466e5fcb24e386511d193e55f698a8e..8a982d920490c3ae1e1acced8b525a137e2d986e 100644 (file)
@@ -81,7 +81,7 @@ SOURCES=utils/aidepost.c utils/citmail.c \
        locate_host.c auth.c msgbase.c parsedate.c \
        room_ops.c euidindex.c server_main.c ldap.c \
        support.c sysdep.c user_ops.c journaling.c threads.c \
-       context.c event_client.c netconfig.c nttlist.c
+       context.c event_client.c netconfig.c nttlist.c md5.c
 
 
 include Make_sources
@@ -136,7 +136,7 @@ SERV_OBJS = server_main.o utillib/citadel_dirs.o event_client.o \
        internet_addressing.o journaling.o \
        parsedate.o genstamp.o ecrash.o threads.o context.o \
        clientsocket.o modules_init.o modules_upgrade.o $(SERV_MODULES) \
-       svn_revision.o ldap.o netconfig.o nttlist.o
+       svn_revision.o ldap.o netconfig.o nttlist.o md5.o
 
 citserver$(EXEEXT): $(SERV_OBJS)
        $(CC) $(SERV_OBJS) $(LDFLAGS) $(SERVER_LDFLAGS) $(LIBS) $(SERVER_LIBS) $(RESOLV) -o citserver$(EXEEXT)
index ef15cba83710e5b7371bc7296b424cd34f96aed2..25eecb1e7144cbce05f921ab5a5de45b3d6fb71d 100755 (executable)
@@ -25,7 +25,7 @@ ifneq (,$(findstring profiling,$(DEB_BUILD_OPTIONS)))
 endif
 
 ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
-       CFLAGS += -O0 -ggdb -rdynamic -D_GNU_SOURCE -MD -MP -D TECH_PREVIEW
+       CFLAGS += -O0 -ggdb -rdynamic -D_GNU_SOURCE -MD -MP -D TECH_PREVIEW -Wcast-align
        LDFLAGS+=-Wl,--no-undefined -Wl,--as-needed
        EXTRA_ARGS = --with-backtrace
        ifneq (,$(findstring event,$(DEB_BUILD_OPTIONS)))
index a93db2c172f1e5ec8bf9c067f099703316fab02d..6284f0de58b3b4f6d6653743bc1a33d8d282090c 100644 (file)
@@ -33,6 +33,8 @@ struct SpoolControl {
        OneRoomNetCfg *RNCfg;
        struct ctdlroom room;
        StrBuf *Users[maxRoomNetCfg];
+       StrBuf *RoomInfo;
+       StrBuf *ListID;
        FILE *digestfp;
        int num_msgs_spooled;
        long lastsent;
index 18e7372c57b6a610abf9493f5f528cd748235859..dac000efc8527477b2cc6b0185f1ccd2c75f70b3 100644 (file)
@@ -120,13 +120,58 @@ void aggregate_recipients(StrBuf **recps, RoomNetCfg Which, OneRoomNetCfg *OneRN
        }
 }
 
+static void ListCalculateSubject(struct CtdlMessage *msg)
+{
+       struct CitContext *CCC = CC;
+       StrBuf *Subject, *FlatSubject;
+       int rlen;
+       char *pCh;
+
+       if (msg->cm_fields['U'] == NULL) {
+               Subject = NewStrBufPlain(HKEY("(no subject)"));
+       }
+       else {
+               Subject = NewStrBufPlain(
+                       msg->cm_fields['U'], -1);
+       }
+       FlatSubject = NewStrBufPlain(NULL, StrLength(Subject));
+       StrBuf_RFC822_to_Utf8(FlatSubject, Subject, NULL, NULL);
+
+       rlen = strlen(CCC->room.QRname);
+       pCh  = strstr(ChrPtr(FlatSubject), CCC->room.QRname);
+       if ((pCh == NULL) ||
+           (*(pCh + rlen) != ']') ||
+           (pCh == ChrPtr(FlatSubject)) ||
+           (*(pCh - 1) != '[')
+               )
+       {
+               StrBuf *tmp;
+               StrBufPlain(Subject, HKEY("["));
+               StrBufAppendBufPlain(Subject,
+                                    CCC->room.QRname,
+                                    rlen, 0);
+               StrBufAppendBufPlain(Subject, HKEY("] "), 0);
+               StrBufAppendBuf(Subject, FlatSubject, 0);
+               /* so we can free the right one swap them */
+               tmp = Subject;
+               Subject = FlatSubject;
+               FlatSubject = tmp;
+               StrBufRFC2047encode(&Subject, FlatSubject);
+       }
+
+       if (msg->cm_fields['U'] != NULL)
+               free (msg->cm_fields['U']);
+       msg->cm_fields['U'] = SmashStrBuf(&Subject);
+
+       FreeStrBuf(&FlatSubject);
+}
+
 /*
  * Deliver digest messages
  */
 void network_deliver_digest(SpoolControl *sc)
 {
        char buf[SIZ];
-       int i;
        struct CtdlMessage *msg = NULL;
        long msglen;
        struct recptypes *valid;
@@ -152,22 +197,12 @@ void network_deliver_digest(SpoolControl *sc)
        msg->cm_fields['A'] = strdup(CC->room.QRname);
        snprintf(buf, sizeof buf, "[%s]", CC->room.QRname);
        msg->cm_fields['U'] = strdup(buf);
-       sprintf(buf, "room_%s@%s", CC->room.QRname, config.c_fqdn);
-       for (i=0; buf[i]; ++i) {
-               if (isspace(buf[i])) buf[i]='_';
-               buf[i] = tolower(buf[i]);
-       }
-       msg->cm_fields['F'] = strdup(buf);
-       msg->cm_fields['R'] = strdup(buf);
+
+       CtdlMsgSetCM_Fields(msg, 'F', SKEY(sc->Users[roommailalias]));
+       CtdlMsgSetCM_Fields(msg, 'R', SKEY(sc->Users[roommailalias]));
 
        /* Set the 'List-ID' header */
-       msg->cm_fields['L'] = malloc(1024);
-       snprintf(msg->cm_fields['L'], 1024,
-                "%s <%ld.list-id.%s>",
-                CC->room.QRname,
-                CC->room.QRnumber,
-                config.c_fqdn
-               );
+       CtdlMsgSetCM_Fields(msg, 'L', SKEY(sc->ListID));
 
        /*
         * Go fetch the contents of the digest
@@ -270,12 +305,7 @@ void network_process_digest(SpoolControl *sc, struct CtdlMessage *omsg, long *de
 
 void network_process_list(SpoolControl *sc, struct CtdlMessage *omsg, long *delete_after_send)
 {
-       struct CitContext *CCC = CC;
-       int rlen;
-       char *pCh;
-       StrBuf *Subject, *FlatSubject;
        struct CtdlMessage *msg = NULL;
-       int i;
 
        /*
         * Process mailing list recipients
@@ -308,60 +338,8 @@ void network_process_list(SpoolControl *sc, struct CtdlMessage *omsg, long *dele
                msg->cm_fields['K'] =
                        strdup (msg->cm_fields['V']);
        }
-       /* Set the 'List-ID' header */
-       if (msg->cm_fields['L'] != NULL) {
-               free(msg->cm_fields['L']);
-       }
-       msg->cm_fields['L'] = malloc(1024);
-       snprintf(msg->cm_fields['L'], 1024,
-                "%s <%ld.list-id.%s>",
-                CCC->room.QRname,
-                CCC->room.QRnumber,
-                config.c_fqdn
-               );
-
-       /* Prepend "[List name]" to the subject */
-       if (msg->cm_fields['U'] == NULL) {
-               Subject = NewStrBufPlain(HKEY("(no subject)"));
-       }
-       else {
-               Subject = NewStrBufPlain(
-                       msg->cm_fields['U'], -1);
-       }
-       FlatSubject = NewStrBufPlain(NULL, StrLength(Subject));
-       StrBuf_RFC822_to_Utf8(FlatSubject, Subject, NULL, NULL);
-
-       rlen = strlen(CCC->room.QRname);
-       pCh  = strstr(ChrPtr(FlatSubject), CCC->room.QRname);
-       if ((pCh == NULL) ||
-           (*(pCh + rlen) != ']') ||
-           (pCh == ChrPtr(FlatSubject)) ||
-           (*(pCh - 1) != '[')
-               )
-       {
-               StrBuf *tmp;
-               StrBufPlain(Subject, HKEY("["));
-               StrBufAppendBufPlain(Subject,
-                                    CCC->room.QRname,
-                                    rlen, 0);
-               StrBufAppendBufPlain(Subject, HKEY("] "), 0);
-               StrBufAppendBuf(Subject, FlatSubject, 0);
-               /* so we can free the right one swap them */
-               tmp = Subject;
-               Subject = FlatSubject;
-               FlatSubject = tmp;
-               StrBufRFC2047encode(&Subject, FlatSubject);
-       }
 
-       if (msg->cm_fields['U'] != NULL)
-               free (msg->cm_fields['U']);
-       msg->cm_fields['U'] = SmashStrBuf(&Subject);
-
-       FreeStrBuf(&FlatSubject);
-
-       /* else we won't modify the buffer, since the
-        * roomname is already here.
-        */
+       CtdlMsgSetCM_Fields(msg, 'F', SKEY(sc->Users[roommailalias]));
 
        /* if there is no other recipient, Set the recipient
         * of the list message to the email address of the
@@ -370,22 +348,18 @@ void network_process_list(SpoolControl *sc, struct CtdlMessage *omsg, long *dele
        if ((msg->cm_fields['R'] == NULL) ||
            IsEmptyStr(msg->cm_fields['R']))
        {
-               if (msg->cm_fields['R'] != NULL)
-                       free(msg->cm_fields['R']);
-
-               msg->cm_fields['R'] = malloc(256);
-               snprintf(msg->cm_fields['R'], 256,
-                        "room_%s@%s", CCC->room.QRname,
-                        config.c_fqdn);
-               for (i=0; msg->cm_fields['R'][i]; ++i) {
-                       if (isspace(msg->cm_fields['R'][i])) {
-                               msg->cm_fields['R'][i] = '_';
-                       }
-               }
+               CtdlMsgSetCM_Fields(msg, 'R', SKEY(sc->Users[roommailalias]));
        }
 
+       /* Set the 'List-ID' header */
+       CtdlMsgSetCM_Fields(msg, 'L', SKEY(sc->ListID));
+
+
+       /* Prepend "[List name]" to the subject */
+       ListCalculateSubject(msg);
+
        /* Handle delivery */
-       network_deliver_list(msg, sc, CCC->room.QRname);
+       network_deliver_list(msg, sc, CC->room.QRname);
        CtdlFreeMessage(msg);
 }
 
@@ -423,7 +397,6 @@ void network_deliver_list(struct CtdlMessage *msg, SpoolControl *sc, const char
 void network_process_participate(SpoolControl *sc, struct CtdlMessage *omsg, long *delete_after_send)
 {
        struct CtdlMessage *msg = NULL;
-       int i;
        int ok_to_participate = 0;
        StrBuf *Buf = NULL;
        struct recptypes *valid;
@@ -460,35 +433,16 @@ void network_process_participate(SpoolControl *sc, struct CtdlMessage *omsg, lon
        }
        if (ok_to_participate)
        {
-               if (msg->cm_fields['F'] != NULL) {
-                       free(msg->cm_fields['F']);
-               }
-               msg->cm_fields['F'] = malloc(SIZ);
                /* Replace the Internet email address of the
                 * actual author with the email address of the
                 * room itself, so the remote listserv doesn't
                 * reject us.
                 */
-               if (sc->Users[roommailalias] != NULL)
-                       snprintf(msg->cm_fields['F'], SIZ,
-                                "%s", ChrPtr(sc->Users[roommailalias]));
-               else
-                       snprintf(msg->cm_fields['F'], SIZ,
-                                "room_%s@%s", CC->room.QRname,
-                                config.c_fqdn);
-
-               for (i=0; msg->cm_fields['F'][i]; ++i) {
-                       if (isspace(msg->cm_fields['F'][i])) {
-                               msg->cm_fields['F'][i] = '_';
-                       }
-               }
+               CtdlMsgSetCM_Fields(msg, 'F', SKEY(sc->Users[roommailalias]));
 
                valid = validate_recipients(ChrPtr(sc->Users[participate]) , NULL, 0);
 
-               if (msg->cm_fields['R'] != NULL) {
-                       free(msg->cm_fields['R']);
-               }/* TODO: check whether 'R' is set appropriate later. */
-
+               CtdlMsgSetCM_Fields(msg, 'R', SKEY(sc->Users[roommailalias]));
                CtdlSubmitMsg(msg, valid, "", 0);
                free_recipients(valid);
        }
index 5dedf0c536ec52754710e18c0078b74182fd8f20..00719bfea96eddb6d0ee94cd96ee78578efc96a3 100644 (file)
@@ -149,6 +149,93 @@ int network_usetable(struct CtdlMessage *msg)
 }
 
 
+void CalcListID(SpoolControl *sc)
+{
+       const char *err;
+       int fd;
+       struct CitContext *CCC = CC;
+       char filename[PATH_MAX];
+#define MAX_LISTIDLENGTH 150
+
+       assoc_file_name(filename, sizeof filename, &sc->room, ctdl_info_dir);
+       fd = open(filename, 0);
+
+       if (fd != 0) {
+               struct stat stbuf;
+
+               fstat(fd, &stbuf);
+               if (stbuf.st_size > 0)
+               {
+                       sc->RoomInfo = NewStrBufPlain(NULL, stbuf.st_size + 1);
+                       StrBufReadBLOB(sc->RoomInfo, &fd, 0, stbuf.st_size, &err);
+               }
+               close(fd);
+       }
+
+       sc->ListID = NewStrBufPlain(NULL, 1024);
+       if (StrLength(sc->RoomInfo) > 0)
+       {
+               const char *Pos = NULL;
+               StrBufSipLine(sc->ListID, sc->RoomInfo, &Pos);
+
+               if (StrLength(sc->ListID) > MAX_LISTIDLENGTH)
+               {
+                       StrBufCutAt(sc->ListID, MAX_LISTIDLENGTH, NULL);
+                       StrBufAppendBufPlain(sc->ListID, HKEY("..."), 0);
+               }
+               StrBufAsciify(sc->ListID, ' ');
+       }
+       else
+       {
+               StrBufAppendBufPlain(sc->ListID, CCC->room.QRname, -1, 0);
+       }
+
+       StrBufAppendBufPlain(sc->ListID, HKEY("<"), 0);
+
+       if (StrLength(sc->Users[roommailalias]) > 0)
+       {
+               long Pos;
+               const char *AtPos;
+
+               Pos = StrLength(sc->ListID);
+               StrBufAppendBuf(sc->ListID, sc->Users[roommailalias], 0);
+               AtPos = strchr(ChrPtr(sc->ListID) + Pos, '@');
+
+               if (AtPos != NULL)
+               {
+                       StrBufPeek(sc->ListID, AtPos, 0, '.');
+               }
+       }
+       else
+       {
+               StrBufAppendBufPlain(sc->ListID, HKEY("room_"), 0);
+               StrBufAppendBufPlain(sc->ListID, sc->room.QRname, -1, 0);
+               StrBufAppendBufPlain(sc->ListID, HKEY("."), 0);
+               StrBufAppendBufPlain(sc->ListID, config.c_fqdn, -1, 0);
+               /*
+                * this used to be:
+                * roomname <Room-Number.list-id.fqdn>
+                * according to rfc2919.txt it only has to be a uniq identifier
+                * under the domain of the system; 
+                * in general MUAs use it to calculate the reply address nowadays.
+                */
+       }
+       StrBufAppendBufPlain(sc->ListID, HKEY(">"), 0);
+
+       if (StrLength(sc->Users[roommailalias]) == 0)
+       {
+               sc->Users[roommailalias] = NewStrBuf();
+               
+               StrBufPrintf(sc->Users[roommailalias],
+                            "room_%s@%s",
+                            CCC->room.QRname,
+                            config.c_fqdn);
+
+               StrBufAsciify(sc->Users[roommailalias], '_');
+               StrBufLowerCase(sc->Users[roommailalias]);
+       }
+
+}
 
 /*
  * Send the *entire* contents of the current room to one specific network node,
@@ -194,6 +281,7 @@ int network_sync_to(char *target_node, long len)
        sc.working_ignetcfg = CtdlLoadIgNetCfg();
        sc.the_netmap = CtdlReadNetworkMap();
 
+       CalcListID(&sc);
        /* Send ALL messages */
        num_spooled = CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL, NULL,
                network_spool_msg, &sc);
index 998cf8f1cdf232d6cfe5801edaa07a603b2e3278..c657378f89af5885ca82fcf0d9dc3d68125569af 100644 (file)
@@ -1704,7 +1704,7 @@ void cmd_seta(char *new_ra)
  */
 void cmd_rinf(char *gargs)
 {
-       char filename[128];
+       char filename[PATH_MAX];
        char buf[SIZ];
        FILE *info_fp;