X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fjournaling.c;h=0d2e74f4182d2218a042b7a9ea9167de77abbf06;hb=c4609169aa7baf208848e72c16d33a3f892353b8;hp=d1daf5a7acd7ca3628f23c18638ec4f33e12e8ab;hpb=848934c1722edc208c4df49c571586b72c3fc486;p=citadel.git diff --git a/citadel/journaling.c b/citadel/journaling.c index d1daf5a7a..0d2e74f41 100644 --- a/citadel/journaling.c +++ b/citadel/journaling.c @@ -1,52 +1,29 @@ /* * Message journaling functions. + * + * Copyright (c) 1987-2015 by the citadel.org team + * + * This program is open source software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. */ -#include "sysdep.h" -#include -#include #include -#include - -#if TIME_WITH_SYS_TIME -# include -# include -#else -# if HAVE_SYS_TIME_H -# include -# else -# include -# endif -#endif - - -#include -#include -#include -#include -#include -#include #include -#include "citadel.h" -#include "server.h" -#include "database.h" -#include "msgbase.h" -#include "support.h" -#include "sysdep_decls.h" + +#include "ctdl_module.h" + #include "citserver.h" -#include "room_ops.h" -#include "user_ops.h" -#include "file_ops.h" #include "config.h" -#include "control.h" -#include "genstamp.h" -#include "internet_addressing.h" +#include "user_ops.h" #include "serv_vcard.h" /* Needed for vcard_getuser and extract_inet_email_addrs */ +#include "internet_addressing.h" #include "journaling.h" -#include "ctdl_module.h" -#include "threads.h" - struct jnlq *jnlq = NULL; /* journal queue */ /* @@ -54,12 +31,12 @@ struct jnlq *jnlq = NULL; /* journal queue */ */ void JournalBackgroundSubmit(struct CtdlMessage *msg, StrBuf *saved_rfc822_version, - struct recptypes *recps) { + recptypes *recps) { struct jnlq *jptr = NULL; /* Avoid double journaling! */ - if (msg->cm_fields[eJournal] != NULL) { + if (!CM_IsEmpty(msg, eJournal)) { FreeStrBuf(&saved_rfc822_version); return; } @@ -70,12 +47,12 @@ void JournalBackgroundSubmit(struct CtdlMessage *msg, return; } memset(jptr, 0, sizeof(struct jnlq)); - if (recps != NULL) memcpy(&jptr->recps, recps, sizeof(struct recptypes)); - if (msg->cm_fields[eAuthor] != NULL) jptr->from = strdup(msg->cm_fields[eAuthor]); - if (msg->cm_fields[eNodeName] != NULL) jptr->node = strdup(msg->cm_fields[eNodeName]); - if (msg->cm_fields[erFc822Addr] != NULL) jptr->rfca = strdup(msg->cm_fields[erFc822Addr]); - if (msg->cm_fields[eMsgSubject] != NULL) jptr->subj = strdup(msg->cm_fields[eMsgSubject]); - if (msg->cm_fields[emessageId] != NULL) jptr->msgn = strdup(msg->cm_fields[emessageId]); + if (recps != NULL) memcpy(&jptr->recps, recps, sizeof(recptypes)); + if (!CM_IsEmpty(msg, eAuthor)) jptr->from = strdup(msg->cm_fields[eAuthor]); + if (!CM_IsEmpty(msg, eNodeName)) jptr->node = strdup(msg->cm_fields[eNodeName]); + if (!CM_IsEmpty(msg, erFc822Addr)) jptr->rfca = strdup(msg->cm_fields[erFc822Addr]); + if (!CM_IsEmpty(msg, eMsgSubject)) jptr->subj = strdup(msg->cm_fields[eMsgSubject]); + if (!CM_IsEmpty(msg, emessageId)) jptr->msgn = strdup(msg->cm_fields[emessageId]); jptr->rfc822 = SmashStrBuf(&saved_rfc822_version); /* Add to the queue */ @@ -122,7 +99,7 @@ void local_to_inetemail(char *inetemail, char *localuser, size_t inetemail_len) void JournalRunQueueMsg(struct jnlq *jmsg) { struct CtdlMessage *journal_msg = NULL; - struct recptypes *journal_recps = NULL; + recptypes *journal_recps = NULL; StrBuf *message_text = NULL; char mime_boundary[256]; long mblen; @@ -134,7 +111,7 @@ void JournalRunQueueMsg(struct jnlq *jmsg) { if (jmsg == NULL) return; - journal_recps = validate_recipients(config.c_journal_dest, NULL, 0); + journal_recps = validate_recipients(CtdlGetConfigStr("c_journal_dest"), NULL, 0); if (journal_recps != NULL) { if ( (journal_recps->num_local > 0) @@ -153,16 +130,34 @@ void JournalRunQueueMsg(struct jnlq *jmsg) { journal_msg->cm_anon_type = MES_NORMAL; journal_msg->cm_format_type = FMT_RFC822; CM_SetField(journal_msg, eJournal, HKEY("is journal")); - CM_SetField(journal_msg, eAuthor, jmsg->from, strlen(jmsg->from)); - CM_SetField(journal_msg, eNodeName, jmsg->node, strlen(jmsg->node)); - CM_SetField(journal_msg, erFc822Addr, jmsg->rfca, strlen(jmsg->rfca)); - CM_SetField(journal_msg, eMsgSubject, jmsg->subj, strlen(jmsg->subj)); + + if (!IsEmptyStr(jmsg->from)) { + CM_SetField(journal_msg, eAuthor, jmsg->from, strlen(jmsg->from)); + } + + if (!IsEmptyStr(jmsg->node)) { + CM_SetField(journal_msg, eNodeName, jmsg->node, strlen(jmsg->node)); + } + + if (!IsEmptyStr(jmsg->rfca)) { + CM_SetField(journal_msg, erFc822Addr, jmsg->rfca, strlen(jmsg->rfca)); + } + + if (!IsEmptyStr(jmsg->subj)) { + CM_SetField(journal_msg, eMsgSubject, jmsg->subj, strlen(jmsg->subj)); + } mblen = snprintf(mime_boundary, sizeof(mime_boundary), "--Citadel-Journal-%08lx-%04x--", time(NULL), ++seq); - rfc822len = strlen(jmsg->rfc822); - - message_text = NewStrBufPlain(NULL, rfc822len + sizeof(struct recptypes) + 1024); + + if (!IsEmptyStr(jmsg->rfc822)) { + rfc822len = strlen(jmsg->rfc822); + } + else { + rfc822len = 0; + } + + message_text = NewStrBufPlain(NULL, rfc822len + sizeof(recptypes) + 1024); /* * Here is where we begin to compose the journalized message. @@ -193,7 +188,7 @@ void JournalRunQueueMsg(struct jnlq *jmsg) { "\r\n" "Sender: "), 0); - if (journal_msg->cm_fields[eAuthor]) + if (CM_IsEmpty(journal_msg, eAuthor)) StrBufAppendBufPlain( message_text, journal_msg->cm_fields[eAuthor], -1, 0); @@ -202,11 +197,11 @@ void JournalRunQueueMsg(struct jnlq *jmsg) { message_text, HKEY("(null)"), 0); - if (journal_msg->cm_fields[erFc822Addr]) { + if (!CM_IsEmpty(journal_msg, erFc822Addr)) { StrBufAppendPrintf(message_text, " <%s>", journal_msg->cm_fields[erFc822Addr]); } - else if (journal_msg->cm_fields[eNodeName]) { + else if (!CM_IsEmpty(journal_msg, eNodeName)) { StrBufAppendPrintf(message_text, " @ %s", journal_msg->cm_fields[eNodeName]); } @@ -287,7 +282,7 @@ void JournalRunQueueMsg(struct jnlq *jmsg) { /* Submit journal message */ CtdlSubmitMsg(journal_msg, journal_recps, "", 0); - CtdlFreeMessage(journal_msg); + CM_Free(journal_msg); } free_recipients(journal_recps);