]> code.citadel.org Git - citadel.git/blobdiff - citadel/msgbase.c
calculate the directories in a central manner.
[citadel.git] / citadel / msgbase.c
index c0e5eaa2ce1d110d48b89d15322bfd9d053a545a..2af13d95e80c9e99e73b53d6937ca3942a64e01d 100644 (file)
@@ -50,6 +50,7 @@
 #include "serv_fulltext.h"
 #include "vcard.h"
 #include "euidindex.h"
+#include "journaling.h"
 
 long config_msgnum;
 struct addresses_to_be_filed *atbf = NULL;
@@ -82,7 +83,8 @@ char *msgkeys[] = {
        NULL, 
        "hnod",
        "msgn",
-       NULL, NULL, NULL,
+       "jrnl",
+       NULL, NULL,
        "text",
        "node",
        "room",
@@ -136,18 +138,26 @@ int alias(char *name)
        char node[64];
        char testnode[64];
        char buf[SIZ];
+       char filename[256];
 
        striplt(name);
        remove_any_whitespace_to_the_left_or_right_of_at_symbol(name);
        stripallbut(name, '<', '>');
 
-       fp = fopen(
+       /* 
+        * DIRTY HACK FOLLOWS! due to configs in the network dir in the 
+        * legacy installations, we need to calculate ifdeffed here.
+        */
+               snprintf(filename, 
+                                sizeof filename,
+                                "%s/mail.aliases",
 #ifndef HAVE_ETG_DIR
-                          "network/"
+                                ctdl_spool_dir
 #else
-                          ETC_DIR
+                                ctdl_etc_dir
 #endif
-                          "mail.aliases", "r");
+                                );
+       fp = fopen(filename, "r");
        if (fp == NULL) {
                fp = fopen("/dev/null", "r");
        }
@@ -241,14 +251,15 @@ int alias(char *name)
 void get_mm(void)
 {
        FILE *fp;
+       char filename[256];
 
-       fp = fopen(
-#ifndef HAVE_DATA_DIR
-                          "."
-#else
-                          DATA_DIR
-#endif
-                          "/citadel.control", "r");
+       snprintf(filename, 
+                        sizeof filename,
+                        "%s/citadel.control",
+                        ctdl_etc_dir
+                        );
+
+       fp = fopen(filename, "r");
        if (fp == NULL) {
                lprintf(CTDL_CRIT, "Cannot open citadel.control: %s\n",
                        strerror(errno));
@@ -2137,6 +2148,8 @@ long CtdlSubmitMsg(struct CtdlMessage *msg,       /* message to save */
        char *hold_R, *hold_D;
        char *collected_addresses = NULL;
        struct addresses_to_be_filed *aptr = NULL;
+       char *saved_rfc822_version = NULL;
+       int qualified_for_journaling = 0;
 
        lprintf(CTDL_DEBUG, "CtdlSubmitMsg() called\n");
        if (is_valid_message(msg) == 0) return(-1);     /* self check */
@@ -2265,13 +2278,16 @@ long CtdlSubmitMsg(struct CtdlMessage *msg,     /* message to save */
        safestrncpy(smi.meta_content_type, content_type,
                        sizeof smi.meta_content_type);
 
-       /* As part of the new metadata record, measure how
-        * big this message will be when displayed as RFC822.
-        * Both POP and IMAP use this, and it's best to just take the hit now
-        * instead of having to potentially measure thousands of messages when
-        * a mailbox is opened later.
+       /*
+        * Measure how big this message will be when rendered as RFC822.
+        * We do this for two reasons:
+        * 1. We need the RFC822 length for the new metadata record, so the
+        *    POP and IMAP services don't have to calculate message lengths
+        *    while the user is waiting (multiplied by potentially hundreds
+        *    or thousands of messages).
+        * 2. If journaling is enabled, we will need an RFC822 version of the
+        *    message to attach to the journalized copy.
         */
-
        if (CC->redirect_buffer != NULL) {
                lprintf(CTDL_ALERT, "CC->redirect_buffer is not NULL during message submission!\n");
                abort();
@@ -2281,7 +2297,7 @@ long CtdlSubmitMsg(struct CtdlMessage *msg,       /* message to save */
        CC->redirect_alloc = SIZ;
        CtdlOutputPreLoadedMsg(msg, MT_RFC822, HEADERS_ALL, 0, 1);
        smi.meta_rfc822_length = CC->redirect_len;
-       free(CC->redirect_buffer);
+       saved_rfc822_version = CC->redirect_buffer;
        CC->redirect_buffer = NULL;
        CC->redirect_len = 0;
        CC->redirect_alloc = 0;
@@ -2375,12 +2391,8 @@ long CtdlSubmitMsg(struct CtdlMessage *msg,      /* message to save */
                serialize_message(&smr, msg);
                if (smr.len > 0) {
                        snprintf(submit_filename, sizeof submit_filename,
-#ifndef HAVE_SPOOL_DIR
-                                        "."
-#else
-                                        SPOOL_DIR
-#endif
-                                        "/network/spoolin/netmail.%04lx.%04x.%04x",
+                                        "%s/netmail.%04lx.%04x.%04x",
+                                        ctdl_netin_dir,
                                         (long) getpid(), CC->cs_pid, ++seqnum);
                        network_fp = fopen(submit_filename, "wb+");
                        if (network_fp != NULL) {
@@ -2432,6 +2444,7 @@ long CtdlSubmitMsg(struct CtdlMessage *msg,       /* message to save */
                imsg->cm_anon_type = MES_NORMAL;
                imsg->cm_format_type = FMT_RFC822;
                imsg->cm_fields['A'] = strdup("Citadel");
+               imsg->cm_fields['J'] = strdup("do not journal");
                imsg->cm_fields['M'] = instr;
                CtdlSubmitMsg(imsg, NULL, SMTP_SPOOLOUT_ROOM);
                CtdlFreeMessage(imsg);
@@ -2456,11 +2469,42 @@ long CtdlSubmitMsg(struct CtdlMessage *msg,     /* message to save */
                atbf = aptr;
                end_critical_section(S_ATBF);
        }
-       return(newmsgid);
-}
 
+       /*
+        * Determine whether this message qualifies for journaling.
+        */
+       if (msg->cm_fields['J'] != NULL) {
+               qualified_for_journaling = 0;
+       }
+       else {
+               if (recps == NULL) {
+                       qualified_for_journaling = config.c_journal_pubmsgs;
+               }
+               else if (recps->num_local + recps->num_ignet + recps->num_internet > 0) {
+                       qualified_for_journaling = config.c_journal_email;
+               }
+               else {
+                       qualified_for_journaling = config.c_journal_pubmsgs;
+               }
+       }
 
+       /*
+        * Do we have to perform journaling?  If so, hand off the saved
+        * RFC822 version will be handed off to the journaler for background
+        * submit.  Otherwise, we have to free the memory ourselves.
+        */
+       if (saved_rfc822_version != NULL) {
+               if (qualified_for_journaling) {
+                       JournalBackgroundSubmit(msg, saved_rfc822_version, recps);
+               }
+               else {
+                       free(saved_rfc822_version);
+               }
+       }
 
+       /* Done. */
+       return(newmsgid);
+}