*
*/
-#ifdef DLL_EXPORT
-#define IN_LIBCIT
-#endif
-
#include "sysdep.h"
#include <stdlib.h>
#include <unistd.h>
#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",
FILE *fp;
fp = fopen(
-#ifndef HAVE_RUN_DIR
+#ifndef HAVE_DATA_DIR
"."
#else
- RUN_DIR
+ DATA_DIR
#endif
"/citadel.control", "r");
if (fp == NULL) {
struct CtdlMessage *msg;
msg = CtdlFetchMessage(msgnum, 0);
- if (msg < 0L) {
+ if (msg == NULL) {
cprintf("%ld|0|||||\n", msgnum);
return;
}
if (!strcasecmp(cbtype, "multipart/alternative")) {
++ma->is_ma;
ma->did_print = 0;
- return;
+ }
+ if (!strcasecmp(cbtype, "message/rfc822")) {
+ ++ma->freeze;
}
}
if (!strcasecmp(cbtype, "multipart/alternative")) {
--ma->is_ma;
ma->did_print = 0;
- return;
+ }
+ if (!strcasecmp(cbtype, "message/rfc822")) {
+ --ma->freeze;
}
}
* If we're in the middle of a multipart/alternative scope and
* we've already printed another section, skip this one.
*/
- if ( (ma->is_ma == 1) && (ma->did_print == 1) ) {
+ if ( (ma->is_ma) && (ma->did_print) ) {
lprintf(CTDL_DEBUG, "Skipping part %s (%s)\n",
partnum, cbtype);
return;
if (ma->is_ma > 0) {
for (i=0; i<num_tokens(CC->preferred_formats, '|'); ++i) {
extract_token(buf, CC->preferred_formats, i, '|', sizeof buf);
- if (!strcasecmp(buf, cbtype)) {
- if (num_tokens(partnum, '.') < 3) {
- safestrncpy(ma->chosen_part, partnum, sizeof ma->chosen_part);
- }
+ if ( (!strcasecmp(buf, cbtype)) && (!ma->freeze) ) {
+ safestrncpy(ma->chosen_part, partnum, sizeof ma->chosen_part);
}
}
}
/* Here is the weird form of this command, to process only an
* encapsulated message/rfc822 section.
*/
- if (section) {
+ if (section) if (strlen(section)>0) if (strcmp(section, "0")) {
memset(&encap, 0, sizeof encap);
safestrncpy(encap.desired_section, section, sizeof encap.desired_section);
mime_parser(TheMessage->cm_fields['M'],
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;
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 {
+ qualified_for_journaling = 1; /* FIXME */
+ }
+ /*
+ * 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);
+}
char this_recp[256];
char this_recp_cooked[256];
char append[SIZ];
- int num_recps;
+ int num_recps = 0;
int i, j;
int mailtype;
int invalid;
num = extract_long(args, 0);
extract_token(targ, args, 1, '|', sizeof targ);
+ convert_room_name_macros(targ, sizeof targ);
targ[ROOMNAMELEN - 1] = 0;
is_copy = extract_int(args, 2);
char *encoded_message = NULL;
off_t raw_length = 0;
- if (is_mailbox != NULL)
+ if (is_mailbox != NULL) {
MailboxName(roomname, sizeof roomname, is_mailbox, req_room);
- else
+ }
+ else {
safestrncpy(roomname, req_room, sizeof(roomname));
- lprintf(CTDL_DEBUG, "CtdlWriteObject() to <%s> (flags=%d)\n", roomname, flags);
-
+ }
fp = fopen(tempfilename, "rb");
if (fp == NULL) {
char temp[PATH_MAX];
FILE *fp;
- strcpy(temp, tmpnam(NULL));
+ CtdlMakeTempFileName(temp, sizeof temp);
fp = fopen(temp, "w");
if (fp == NULL) return;