/*
* Implements the message store.
*
- * Copyright (c) 1987-2020 by the citadel.org team
+ * Copyright (c) 1987-2021 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.
"rep2", // K -> eReplyTo
"list", // L -> eListID
"text", // M -> eMesageText
- NULL, // N (formerly used as eNodeName)
+ NULL, // N (formerly used as eNodename)
"room", // O -> eOriginalRoom
"path", // P -> eMessagePath
NULL, // Q
NULL // Z
};
+
HashList *msgKeyLookup = NULL;
int GetFieldFromMnemonic(eMsgField *f, const char* c)
}
}
+
eMsgField FieldOrder[] = {
/* Important fields */
emessageId ,
) {
CC->download_fp = tmpfile();
if (CC->download_fp == NULL) {
- syslog(LOG_EMERG, "msgbase: mime_download() couldn't write: %m");
+ syslog(LOG_ERR, "msgbase: mime_download() couldn't write: %m");
cprintf("%d cannot open temporary file: %s\n", ERROR + INTERNAL_ERROR, strerror(errno));
return;
}
rv = fwrite(content, length, 1, CC->download_fp);
if (rv <= 0) {
- syslog(LOG_EMERG, "msgbase: mime_download() Couldn't write: %m");
+ syslog(LOG_ERR, "msgbase: mime_download() Couldn't write: %m");
cprintf("%d unable to write tempfile.\n", ERROR + TOO_BIG);
fclose(CC->download_fp);
CC->download_fp = NULL;
}
-void OutputCtdlMsgHeaders(
- struct CtdlMessage *TheMessage,
- int do_proto) /* do Citadel protocol responses? */
-{
+void OutputCtdlMsgHeaders(struct CtdlMessage *TheMessage, int do_proto) {
int i;
char buf[SIZ];
char display_name[256];
eMsgField Field;
Field = FieldOrder[i];
if (Field != eMesageText) {
- if ( (!CM_IsEmpty(TheMessage, Field))
- && (msgkeys[Field] != NULL) ) {
- if ((Field == eenVelopeTo) ||
- (Field == eRecipient) ||
- (Field == eCarbonCopY)) {
+ if ( (!CM_IsEmpty(TheMessage, Field)) && (msgkeys[Field] != NULL) ) {
+ if ((Field == eenVelopeTo) || (Field == eRecipient) || (Field == eCarbonCopY)) {
sanitize_truncated_recipient(TheMessage->cm_fields[Field]);
}
if (Field == eAuthor) {
- if (do_proto) cprintf("%s=%s\n",
- msgkeys[Field],
- display_name);
+ if (do_proto) {
+ cprintf("%s=%s\n", msgkeys[Field], display_name);
+ }
}
/* Masquerade display name if needed */
else {
if (do_proto) {
cprintf("%s=%s\n", msgkeys[Field], TheMessage->cm_fields[Field]);
}
+ }
+ /* Give the client a hint about whether the message originated locally */
+ if (Field == erFc822Addr) {
+ if (IsDirectory(TheMessage->cm_fields[Field] ,0)) {
+ cprintf("locl=yes\n"); // message originated locally.
+ }
+
+
+
}
}
}
/* Tell the client which format type we're using. */
if ( (mode == MT_CITADEL) && (do_proto) ) {
- cprintf("type=%d\n", TheMessage->cm_format_type);
+ cprintf("type=%d\n", TheMessage->cm_format_type); // Tell the client which format type we're using.
}
/* nhdr=yes means that we're only displaying headers, no body */
cprintf("nhdr=yes\n");
}
- if ((mode == MT_CITADEL) || (mode == MT_MIME))
+ if ((mode == MT_CITADEL) || (mode == MT_MIME)) {
OutputCtdlMsgHeaders(TheMessage, do_proto);
-
+ }
/* begin header processing loop for RFC822 transfer format */
strcpy(suser, "");
}
-
-
/*
* Message base operation to save a new message to the message store
* (returns new message number)
* If the message is big, set its body aside for storage elsewhere
* and we hide the message body from the serializer
*/
- if (!CM_IsEmpty(msg, eMesageText) && msg->cm_lengths[eMesageText] > BIGMSG)
- {
+ if (!CM_IsEmpty(msg, eMesageText) && msg->cm_lengths[eMesageText] > BIGMSG) {
is_bigmsg = 1;
holdM = msg->cm_fields[eMesageText];
msg->cm_fields[eMesageText] = NULL;
}
/* Write our little bundle of joy into the message base */
- retval = cdb_store(CDB_MSGMAIN, &msgid, (int)sizeof(long),
- smr.ser, smr.len);
+ retval = cdb_store(CDB_MSGMAIN, &msgid, (int)sizeof(long), smr.ser, smr.len);
if (retval < 0) {
syslog(LOG_ERR, "msgbase: can't store message %ld: %ld", msgid, retval);
}
return(retval);
}
+
long send_message(struct CtdlMessage *msg) {
long newmsgid;
long retval;
}
-
/*
* Serialize a struct CtdlMessage into the format used on disk and network.
*
ret->ser[2] = msg->cm_format_type;
wlen = 3;
- for (i=0; i < NDiskFields; ++i)
- if (msg->cm_fields[FieldOrder[i]] != NULL)
- {
+ for (i=0; i < NDiskFields; ++i) {
+ if (msg->cm_fields[FieldOrder[i]] != NULL) {
ret->ser[wlen++] = (char)FieldOrder[i];
memcpy(&ret->ser[wlen],
wlen = wlen + msg->cm_lengths[FieldOrder[i]] + 1;
}
+ }
if (ret->len != wlen) {
syslog(LOG_ERR, "msgbase: ERROR; len=%ld wlen=%ld", (long)ret->len, (long)wlen);
}
-
/*
* Save a message to disk and submit it into the delivery system.
*/
long CtdlSubmitMsg(struct CtdlMessage *msg, /* message to save */
recptypes *recps, /* recipients (if mail) */
- const char *force, /* force a particular room? */
- int flags /* should the message be exported clean? */
- )
-{
+ const char *force /* force a particular room? */
+) {
char hold_rm[ROOMNAMELEN];
char actual_rm[ROOMNAMELEN];
char force_room[ROOMNAMELEN];
memset(&smi, 0, sizeof(struct MetaData));
smi.meta_msgnum = newmsgid;
smi.meta_refcount = 0;
- safestrncpy(smi.meta_content_type, content_type,
- sizeof smi.meta_content_type);
+ safestrncpy(smi.meta_content_type, content_type, sizeof smi.meta_content_type);
/*
* Measure how big this message will be when rendered as RFC822.
*/
if ((!CC->internal_pgm) || (recps == NULL)) {
if (CtdlSaveMsgPointerInRoom(actual_rm, newmsgid, 1, msg) != 0) {
- syslog(LOG_ERR, "msgbase: ERROR saving message pointer!");
+ syslog(LOG_ERR, "msgbase: ERROR saving message pointer %ld in %s", newmsgid, actual_rm);
CtdlSaveMsgPointerInRoom(CtdlGetConfigStr("c_aideroom"), newmsgid, 0, msg);
}
}
}
/* If other rooms are specified, drop them there too. */
- if ((recps != NULL) && (recps->num_room > 0))
+ if ((recps != NULL) && (recps->num_room > 0)) {
for (i=0; i<num_tokens(recps->recp_room, '|'); ++i) {
- extract_token(recipient, recps->recp_room, i,
- '|', sizeof recipient);
+ extract_token(recipient, recps->recp_room, i, '|', sizeof recipient);
syslog(LOG_DEBUG, "msgbase: delivering to room <%s>", recipient);
CtdlSaveMsgPointerInRoom(recipient, newmsgid, 0, msg);
}
+ }
/* Bump this user's messages posted counter. */
syslog(LOG_DEBUG, "msgbase: updating user");
CtdlPutCurrentUserLock();
/* Decide where bounces need to be delivered */
- if ((recps != NULL) && (recps->bounce_to == NULL))
- {
+ if ((recps != NULL) && (recps->bounce_to == NULL)) {
if (CC->logged_in) {
strcpy(bounce_to, CC->user.fullname);
}
/* Go back to the room we started from */
syslog(LOG_DEBUG, "msgbase: returning to original room %s", hold_rm);
- if (strcasecmp(hold_rm, CC->room.QRname))
+ if (strcasecmp(hold_rm, CC->room.QRname)) {
CtdlUserGoto(hold_rm, 0, 1, NULL, NULL, NULL, NULL);
+ }
/*
* Any addresses to harvest for someone's address book?
CM_SetField(msg, eMesageText, text, -1);
}
- long msgnum = CtdlSubmitMsg(msg, recp, room, 0);
+ long msgnum = CtdlSubmitMsg(msg, recp, room);
CM_Free(msg);
if (recp != NULL) free_recipients(recp);
return msgnum;
StrBuf *exist, /* if non-null, append to it;
exist is ALWAYS freed */
int crlf /* CRLF newlines instead of LF */
- )
-{
+) {
StrBuf *Message;
StrBuf *LineBuf;
int flushing = 0;
return SmashStrBuf(&Message);
}
+
struct CtdlMessage *CtdlMakeMessage(
struct ctdluser *author, /* author's user structure */
char *recipient, /* NULL if it's not mail */
char *supplied_euid, /* ...or NULL if this is irrelevant */
char *preformatted_text, /* ...or NULL to read text from client */
char *references /* Thread references */
-)
-{
+) {
return CtdlMakeMessageLen(
author, /* author's user structure */
recipient, /* NULL if it's not mail */
}
+
/*
* Build a binary message to be saved on disk.
* (NOTE: if you supply 'preformatted_text', the buffer you give it
* responsible for managing that memory -- it will be freed along with
* the rest of the fields when CM_Free() is called.)
*/
-
struct CtdlMessage *CtdlMakeMessageLen(
struct ctdluser *author, /* author's user structure */
char *recipient, /* NULL if it's not mail */
long textlen,
char *references, /* Thread references */
long reflen
- )
-{
- /* Don't confuse the poor folks if it's not routed mail. * /
- char dest_node[256] = "";*/
+) {
long blen;
char buf[1024];
struct CtdlMessage *msg;
}
-
-
/*
* API function to delete messages which match a set of criteria
* (returns the actual number of messages deleted)
*/
-int CtdlDeleteMessages(const char *room_name, /* which room */
- long *dmsgnums, /* array of msg numbers to be deleted */
- int num_dmsgnums, /* number of msgs to be deleted, or 0 for "any" */
- char *content_type /* or "" for any. regular expressions expected. */
- )
-{
+int CtdlDeleteMessages(const char *room_name, // which room
+ long *dmsgnums, // array of msg numbers to be deleted
+ int num_dmsgnums, // number of msgs to be deleted, or 0 for "any"
+ char *content_type // or "" for any. regular expressions expected.
+) {
struct ctdlroom qrbuf;
struct cdbdata *cdbfr;
long *msglist = NULL;
int is_binary, /* Is encoding necessary? */
int is_unique, /* Del others of this type? */
unsigned int flags /* Internal save flags */
- )
-{
+) {
struct ctdlroom qrbuf;
char roomname[ROOMNAMELEN];
struct CtdlMessage *msg;
);
}
/* Now write the data */
- CtdlSubmitMsg(msg, NULL, roomname, 0);
+ CtdlSubmitMsg(msg, NULL, roomname);
CM_Free(msg);
}