]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/network/serv_network.c
* add reply-to: header to mails sent to room list recipients
[citadel.git] / citadel / modules / network / serv_network.c
index c8269f05a00128ef900e24e787079947f0251264..e89f26eec7b78c03e21d0efe98a82a877a0fffd1 100644 (file)
@@ -647,7 +647,19 @@ void network_spool_msg(long msgnum, void *userdata) {
                 */
                msg = CtdlFetchMessage(msgnum, 1);
                if (msg != NULL) {
-
+                       if (msg->cm_fields['V'] == NULL){
+                               /* local message, no enVelope */
+                               StrBuf *Buf;
+                               Buf = NewStrBuf();
+                               StrBufAppendBufPlain(Buf, msg->cm_fields['O'], -1, 0);
+                               StrBufAppendBufPlain(Buf, HKEY("@"), 0);
+                               StrBufAppendBufPlain(Buf, config.c_fqdn, -1, 0);
+                               
+                               msg->cm_fields['K'] = SmashStrBuf(&Buf);
+                       }
+                       else {
+                               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']);
@@ -1843,17 +1855,28 @@ void receive_spool(int *sock, char *remote_nodename) {
        char buf[SIZ];
        static char pbuf[IGNET_PACKET_SIZE];
        char tempfilename[PATH_MAX];
-       char filename[PATH_MAX];
+       char permfilename[PATH_MAX];
        long plen;
        FILE *fp;
 
        snprintf(tempfilename, 
-                sizeof tempfilename, 
-                "%s/%s.%ld",
-                ctdl_nettmp_dir,
-                remote_nodename, 
-                (long) getpid()
+               sizeof tempfilename, 
+               "%s/%s.%lx%x",
+               ctdl_nettmp_dir,
+               remote_nodename, 
+               time(NULL),
+               rand()
+       );
+
+       snprintf(permfilename, 
+               sizeof permfilename, 
+               "%s/%s.%lx%x",
+               ctdl_netin_dir,
+               remote_nodename, 
+               time(NULL),
+               rand()
        );
+
        if (sock_puts(sock, "NDOP") < 0) return;
        if (sock_getln(sock, buf, sizeof buf) < 0) return;
        CtdlLogPrintf(CTDL_DEBUG, "<%s\n", buf);
@@ -1862,53 +1885,57 @@ void receive_spool(int *sock, char *remote_nodename) {
        }
        download_len = extract_long(&buf[4], 0);
 
-       bytes_received = 0L;
-       fp = fopen(tempfilename, "w");
-       if (fp == NULL) {
-               CtdlLogPrintf(CTDL_CRIT, "cannot open download file locally: %s\n",
-                       strerror(errno));
-               return;
-       }
-
-       while (bytes_received < download_len) {
-               /*
-                * If shutting down we can exit here and unlink the temp file.
-                * this shouldn't loose us any messages.
-                */
-               if (CtdlThreadCheckStop())
-               {
-                       fclose(fp);
-                       unlink(tempfilename);
-                       return;
-               }
-               snprintf(buf, sizeof buf, "READ %ld|%ld",
-                       bytes_received,
-                    ((download_len - bytes_received > IGNET_PACKET_SIZE)
-                ? IGNET_PACKET_SIZE : (download_len - bytes_received)));
-               if (sock_puts(sock, buf) < 0) {
-                       fclose(fp);
-                       unlink(tempfilename);
+       if (download_len>0) {
+               bytes_received = 0L;
+               fp = fopen(tempfilename, "w");
+               if (fp == NULL) {
+                       CtdlLogPrintf(CTDL_CRIT, "cannot open download file locally: %s\n",
+                                     strerror(errno));
                        return;
                }
-               if (sock_getln(sock, buf, sizeof buf) < 0) {
-                       fclose(fp);
-                       unlink(tempfilename);
-                       return;
-               }
-               if (buf[0] == '6') {
-                       plen = extract_long(&buf[4], 0);
-                       if (sock_read(sock, pbuf, plen, 1) < 0) {
+
+               CtdlLogPrintf(CTDL_DEBUG, "For this download we are expecting %d bytes\n", download_len);
+               while (bytes_received < download_len) {
+                       /*
+                        * If shutting down we can exit here and unlink the temp file.
+                        * this shouldn't loose us any messages.
+                        */
+                       if (CtdlThreadCheckStop())
+                       {
                                fclose(fp);
                                unlink(tempfilename);
                                return;
                        }
-                       fwrite((char *) pbuf, plen, 1, fp);
-                       bytes_received = bytes_received + plen;
+                       snprintf(buf, sizeof buf, "READ %ld|%ld",
+                                bytes_received,
+                                ((download_len - bytes_received > IGNET_PACKET_SIZE)
+                                 ? IGNET_PACKET_SIZE : (download_len - bytes_received)));
+                       
+                       if (sock_puts(sock, buf) < 0) {
+                               fclose(fp);
+                               unlink(tempfilename);
+                               return;
+                       }
+                       if (sock_getln(sock, buf, sizeof buf) < 0) {
+                               fclose(fp);
+                               unlink(tempfilename);
+                               return;
+                       }
+                       
+                       if (buf[0] == '6') {
+                               plen = extract_long(&buf[4], 0);
+                               if (sock_read(sock, pbuf, plen, 1) < 0) {
+                                       fclose(fp);
+                                       unlink(tempfilename);
+                                       return;
+                               }
+                               fwrite((char *) pbuf, plen, 1, fp);
+                               bytes_received = bytes_received + plen;
+                       }
                }
-       }
-
-       fclose(fp);
 
+               fclose(fp);
+       }
        /* Last chance for shutdown exit */
        if (CtdlThreadCheckStop())
        {
@@ -1935,17 +1962,9 @@ void receive_spool(int *sock, char *remote_nodename) {
        
        /* Now move the temp file to its permanent location.
         */
-       snprintf(filename, 
-                sizeof filename, 
-                "%s/%s.%ld",
-                ctdl_netin_dir,
-                remote_nodename, 
-                (long) getpid()
-       );
-
-       if (link(tempfilename, filename) != 0) {
+       if (link(tempfilename, permfilename) != 0) {
                CtdlLogPrintf(CTDL_ALERT, "Could not link %s to %s: %s\n",
-                       tempfilename, filename, strerror(errno)
+                       tempfilename, permfilename, strerror(errno)
                );
        }
        unlink(tempfilename);
@@ -2225,6 +2244,7 @@ void *network_do_queue(void *args) {
         * with a static variable instead.
         */
        if (doing_queue) {
+               CtdlClearSystemContext();
                return NULL;
        }
        doing_queue = 1;
@@ -2312,6 +2332,7 @@ void *network_do_queue(void *args) {
        else {
                CtdlLogPrintf(CTDL_DEBUG, "network: Task STOPPED.\n");
        }
+       CtdlClearSystemContext();
        return NULL;
 }