+ CM_SetField(journal_msg, eJournal, HKEY("is journal"));
+
+ 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);
+
+ 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.
+ * 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.
+ */
+ StrBufAppendBufPlain(
+ message_text,
+ HKEY("Content-type: multipart/mixed; boundary=\""), 0);
+
+ StrBufAppendBufPlain(message_text, mime_boundary, mblen, 0);
+
+ StrBufAppendBufPlain(
+ message_text,
+ HKEY("\"\r\n"
+ "Content-Identifer: ExJournalReport\r\n"
+ "MIME-Version: 1.0\r\n"
+ "\n"
+ "--"), 0);
+
+ StrBufAppendBufPlain(message_text, mime_boundary, mblen, 0);
+
+ StrBufAppendBufPlain(
+ message_text,
+ HKEY("\r\n"
+ "Content-type: text/plain\r\n"
+ "\r\n"
+ "Sender: "), 0);
+
+ if (CM_IsEmpty(journal_msg, eAuthor))
+ StrBufAppendBufPlain(
+ message_text,
+ journal_msg->cm_fields[eAuthor], -1, 0);
+ else
+ StrBufAppendBufPlain(
+ message_text,
+ HKEY("(null)"), 0);
+
+ if (!CM_IsEmpty(journal_msg, erFc822Addr)) {
+ StrBufAppendPrintf(message_text, " <%s>",
+ journal_msg->cm_fields[erFc822Addr]);
+ }
+ else if (!CM_IsEmpty(journal_msg, eNodeName)) {
+ StrBufAppendPrintf(message_text, " @ %s",
+ journal_msg->cm_fields[eNodeName]);
+ }
+ else
+ StrBufAppendBufPlain(
+ message_text,
+ HKEY(" "), 0);
+
+ StrBufAppendBufPlain(
+ message_text,
+ HKEY("\r\n"
+ "Message-ID: <"), 0);
+
+ StrBufAppendBufPlain(message_text, jmsg->msgn, -1, 0);
+ StrBufAppendBufPlain(
+ message_text,
+ HKEY(">\r\n"
+ "Recipients:\r\n"), 0);
+
+ if (jmsg->recps.num_local > 0) {
+ 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);
+ StrBufAppendPrintf(message_text,
+ " %s <%s>\r\n", recipient, inetemail);
+ }
+ }
+
+ if (jmsg->recps.num_ignet > 0) {
+ for (i=0; i<jmsg->recps.num_ignet; ++i) {
+ extract_token(recipient, jmsg->recps.recp_ignet,
+ i, '|', sizeof recipient);
+ StrBufAppendPrintf(message_text,
+ " %s\r\n", recipient);
+ }
+ }
+
+ if (jmsg->recps.num_internet > 0) {
+ for (i=0; i<jmsg->recps.num_internet; ++i) {
+ extract_token(recipient, jmsg->recps.recp_internet,
+ i, '|', sizeof recipient);
+ StrBufAppendPrintf(message_text,
+ " %s\r\n", recipient);
+ }
+ }
+
+ StrBufAppendBufPlain(
+ message_text,
+ HKEY("\r\n"
+ "--"), 0);
+
+ StrBufAppendBufPlain(message_text, mime_boundary, mblen, 0);
+
+ StrBufAppendBufPlain(
+ message_text,
+ HKEY("\r\n"
+ "Content-type: message/rfc822\r\n"
+ "\r\n"), 0);
+
+ StrBufAppendBufPlain(message_text, jmsg->rfc822, rfc822len, 0);
+
+ StrBufAppendBufPlain(
+ message_text,
+ HKEY("--"), 0);
+
+ StrBufAppendBufPlain(message_text, mime_boundary, mblen, 0);
+
+ StrBufAppendBufPlain(
+ message_text,
+ HKEY("--\r\n"), 0);
+
+ CM_SetAsFieldSB(journal_msg, eMesageText, &message_text);