#include "serv_fulltext.h"
#include "vcard.h"
#include "euidindex.h"
+#include "journaling.h"
long config_msgnum;
struct addresses_to_be_filed *atbf = NULL;
NULL,
"hnod",
"msgn",
- NULL, NULL, NULL,
+ "jrnl",
+ NULL, NULL,
"text",
"node",
"room",
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");
}
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));
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 */
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();
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;
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) {
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);
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);
+}