Moved all threading code into threads.c
[citadel.git] / citadel / journaling.c
index 26af56e11c6eee8df327221c381b925f8987344f..b3c79e0abf6b4288550a15d3cd79d94ac203c826 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id:  $
+ * $Id$
  *
  * Message journaling functions.
  *
@@ -29,9 +29,9 @@
 #include <errno.h>
 #include <stdarg.h>
 #include <sys/stat.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
-#include "serv_extensions.h"
 #include "database.h"
 #include "msgbase.h"
 #include "support.h"
 #include "file_ops.h"
 #include "config.h"
 #include "control.h"
-#include "tools.h"
-#include "mime_parser.h"
 #include "html.h"
 #include "genstamp.h"
 #include "internet_addressing.h"
+#include "serv_vcard.h"                        /* Needed for vcard_getuser and extract_inet_email_addrs */
 #include "journaling.h"
 
+#include "ctdl_module.h"
+#include "threads.h"
+
 struct jnlq *jnlq = NULL;      /* journal queue */
 
 /*
@@ -88,6 +90,36 @@ void JournalBackgroundSubmit(struct CtdlMessage *msg,
 }
 
 
+/*
+ * Convert a local user name to an internet email address for the journal
+ */
+/*
+ * TODODRW: change this into a CtdlModuleDo type function that returns alternative address info
+ * for this local user. Something like CtdlModuleGoGetAddr(char *localuser, int type, char *alt_addr, size_t alt_addr_len)
+ * where type can be ADDR_EMAIL, ADDR_FIDO, ADDR_UUCP, ADDR_WEB, ADDR_POSTAL etc etc.
+ * This then begs the question of what should be returned. Is it wise to return a single char* using a comma as a
+ * delimiter? Or would it be better to return a linked list of some kind?
+ */
+void local_to_inetemail(char *inetemail, char *localuser, size_t inetemail_len) {
+       struct ctdluser us;
+       struct vCard *v;
+
+       strcpy(inetemail, "");
+       if (getuser(&us, localuser) != 0) {
+               return;
+       }
+
+       v = vcard_get_user(&us);
+       if (v == NULL) {
+               return;
+       }
+
+       extract_inet_email_addrs(inetemail, inetemail_len, NULL, 0, v, 1);
+       vcard_free(v);
+}
+
+
 /*
  * Called by JournalRunQueue() to send an individual message.
  */
@@ -98,10 +130,11 @@ void JournalRunQueueMsg(struct jnlq *jmsg) {
        char *message_text = NULL;
        char mime_boundary[256];
        char recipient[256];
+       char inetemail[256];
        static int seq = 0;
        int i;
 
-       journal_recps = validate_recipients(config.c_journal_dest);
+       journal_recps = validate_recipients(config.c_journal_dest, NULL, 0);
        if (journal_recps != NULL) {
 
                if (  (journal_recps->num_local > 0)
@@ -128,8 +161,15 @@ void JournalRunQueueMsg(struct jnlq *jmsg) {
                        sprintf(mime_boundary, "--Citadel-Journal-%08lx-%04x--", time(NULL), ++seq);
                        message_text = malloc(strlen(jmsg->rfc822) + sizeof(struct recptypes) + 1024);
 
+                       /*
+                        * Here is where we begin to compose the journalized message.
+                        * NOTE: the superfluous "Content-Identifer: ExJournalReport" header was
+                        *       requested by a paying customer, and yes, it is intentionally
+                        *       spelled wrong.  Do NOT remove or change it.
+                        */
                        sprintf(message_text,
                                "Content-type: multipart/mixed; boundary=\"%s\"\r\n"
+                               "Content-Identifer: ExJournalReport\r\n"
                                "MIME-Version: 1.0\r\n"
                                "\n"
                                "--%s\r\n"
@@ -163,8 +203,9 @@ void JournalRunQueueMsg(struct jnlq *jmsg) {
                                for (i=0; i<jmsg->recps.num_local; ++i) {
                                        extract_token(recipient, jmsg->recps.recp_local,
                                                        i, '|', sizeof recipient);
+                                       local_to_inetemail(inetemail, recipient, sizeof inetemail);
                                        sprintf(&message_text[strlen(message_text)],
-                                               "       %s\r\n", recipient);
+                                               "       %s <%s>\r\n", recipient, inetemail);
                                }
                        }
 
@@ -208,7 +249,7 @@ void JournalRunQueueMsg(struct jnlq *jmsg) {
                        CtdlFreeMessage(journal_msg);
                }
 
-               free(journal_recps);
+               free_recipients(journal_recps);
        }
 
        /* We are responsible for freeing this memory. */
@@ -220,7 +261,7 @@ void JournalRunQueueMsg(struct jnlq *jmsg) {
  * Run the queue.
  */
 void JournalRunQueue(void) {
-       struct jnlq *jptr;
+       struct jnlq *jptr = NULL;
 
        while (jnlq != NULL) {
                begin_critical_section(S_JOURNAL_QUEUE);