X-Git-Url: https://code.citadel.org/?p=citadel.git;a=blobdiff_plain;f=citadel%2Fmsgbase.c;h=081be8980a2aba77e5dd44121e083e57f8e4027e;hp=870a83a0347dcd0e318e28330a130bb92b562e38;hb=79d6eafd2a8bb379b3e13ff071a000d9bf36771b;hpb=436e37f800487ea58343ba015299869d216269d2 diff --git a/citadel/msgbase.c b/citadel/msgbase.c index 870a83a03..081be8980 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -1,7 +1,7 @@ /* * 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. @@ -61,7 +61,7 @@ char *msgkeys[] = { "rep2", // K -> eReplyTo "list", // L -> eListID "text", // M -> eMesageText - "locl", // N -> eOrigLocal + NULL, // N (formerly used as eNodename) "room", // O -> eOriginalRoom "path", // P -> eMessagePath NULL, // Q @@ -113,7 +113,6 @@ eMsgField FieldOrder[] = { eOriginalRoom, eRecipient , /* Semi-important fields */ - eOrigLocal , eBig_message , eExclusiveID , eWeferences , @@ -141,14 +140,12 @@ eMsgField FieldOrder[] = { static const long NDiskFields = sizeof(FieldOrder) / sizeof(eMsgField); -int CM_IsEmpty(struct CtdlMessage *Msg, eMsgField which) -{ +int CM_IsEmpty(struct CtdlMessage *Msg, eMsgField which) { return !((Msg->cm_fields[which] != NULL) && (Msg->cm_fields[which][0] != '\0')); } -void CM_SetField(struct CtdlMessage *Msg, eMsgField which, const char *buf, long length) -{ +void CM_SetField(struct CtdlMessage *Msg, eMsgField which, const char *buf, long length) { if (Msg->cm_fields[which] != NULL) { free (Msg->cm_fields[which]); } @@ -162,8 +159,7 @@ void CM_SetField(struct CtdlMessage *Msg, eMsgField which, const char *buf, long } -void CM_SetFieldLONG(struct CtdlMessage *Msg, eMsgField which, long lvalue) -{ +void CM_SetFieldLONG(struct CtdlMessage *Msg, eMsgField which, long lvalue) { char buf[128]; long len; len = snprintf(buf, sizeof(buf), "%ld", lvalue); @@ -171,8 +167,7 @@ void CM_SetFieldLONG(struct CtdlMessage *Msg, eMsgField which, long lvalue) } -void CM_CutFieldAt(struct CtdlMessage *Msg, eMsgField WhichToCut, long maxlen) -{ +void CM_CutFieldAt(struct CtdlMessage *Msg, eMsgField WhichToCut, long maxlen) { if (Msg->cm_fields[WhichToCut] == NULL) return; @@ -184,8 +179,7 @@ void CM_CutFieldAt(struct CtdlMessage *Msg, eMsgField WhichToCut, long maxlen) } -void CM_FlushField(struct CtdlMessage *Msg, eMsgField which) -{ +void CM_FlushField(struct CtdlMessage *Msg, eMsgField which) { if (Msg->cm_fields[which] != NULL) free (Msg->cm_fields[which]); Msg->cm_fields[which] = NULL; @@ -193,8 +187,7 @@ void CM_FlushField(struct CtdlMessage *Msg, eMsgField which) } -void CM_Flush(struct CtdlMessage *Msg) -{ +void CM_Flush(struct CtdlMessage *Msg) { int i; if (CM_IsValidMsg(Msg) == 0) { @@ -207,8 +200,7 @@ void CM_Flush(struct CtdlMessage *Msg) } -void CM_CopyField(struct CtdlMessage *Msg, eMsgField WhichToPutTo, eMsgField WhichtToCopy) -{ +void CM_CopyField(struct CtdlMessage *Msg, eMsgField WhichToPutTo, eMsgField WhichtToCopy) { long len; if (Msg->cm_fields[WhichToPutTo] != NULL) { free (Msg->cm_fields[WhichToPutTo]); @@ -228,8 +220,7 @@ void CM_CopyField(struct CtdlMessage *Msg, eMsgField WhichToPutTo, eMsgField Whi } -void CM_PrependToField(struct CtdlMessage *Msg, eMsgField which, const char *buf, long length) -{ +void CM_PrependToField(struct CtdlMessage *Msg, eMsgField which, const char *buf, long length) { if (Msg->cm_fields[which] != NULL) { long oldmsgsize; long newmsgsize; @@ -254,8 +245,7 @@ void CM_PrependToField(struct CtdlMessage *Msg, eMsgField which, const char *buf } -void CM_SetAsField(struct CtdlMessage *Msg, eMsgField which, char **buf, long length) -{ +void CM_SetAsField(struct CtdlMessage *Msg, eMsgField which, char **buf, long length) { if (Msg->cm_fields[which] != NULL) { free (Msg->cm_fields[which]); } @@ -271,8 +261,7 @@ void CM_SetAsField(struct CtdlMessage *Msg, eMsgField which, char **buf, long le } -void CM_SetAsFieldSB(struct CtdlMessage *Msg, eMsgField which, StrBuf **buf) -{ +void CM_SetAsFieldSB(struct CtdlMessage *Msg, eMsgField which, StrBuf **buf) { if (Msg->cm_fields[which] != NULL) { free (Msg->cm_fields[which]); } @@ -282,8 +271,7 @@ void CM_SetAsFieldSB(struct CtdlMessage *Msg, eMsgField which, StrBuf **buf) } -void CM_GetAsField(struct CtdlMessage *Msg, eMsgField which, char **ret, long *retlen) -{ +void CM_GetAsField(struct CtdlMessage *Msg, eMsgField which, char **ret, long *retlen) { if (Msg->cm_fields[which] != NULL) { *retlen = Msg->cm_lengths[which]; *ret = Msg->cm_fields[which]; @@ -313,8 +301,7 @@ int CM_IsValidMsg(struct CtdlMessage *msg) { } -void CM_FreeContents(struct CtdlMessage *msg) -{ +void CM_FreeContents(struct CtdlMessage *msg) { int i; for (i = 0; i < 256; ++i) @@ -330,8 +317,7 @@ void CM_FreeContents(struct CtdlMessage *msg) /* * 'Destructor' for struct CtdlMessage */ -void CM_Free(struct CtdlMessage *msg) -{ +void CM_Free(struct CtdlMessage *msg) { if (CM_IsValidMsg(msg) == 0) { if (msg != NULL) free (msg); return; @@ -341,8 +327,7 @@ void CM_Free(struct CtdlMessage *msg) } -int CM_DupField(eMsgField i, struct CtdlMessage *OrgMsg, struct CtdlMessage *NewMsg) -{ +int CM_DupField(eMsgField i, struct CtdlMessage *OrgMsg, struct CtdlMessage *NewMsg) { long len; len = OrgMsg->cm_lengths[i]; NewMsg->cm_fields[i] = malloc(len + 1); @@ -356,8 +341,7 @@ int CM_DupField(eMsgField i, struct CtdlMessage *OrgMsg, struct CtdlMessage *New } -struct CtdlMessage * CM_Duplicate(struct CtdlMessage *OrgMsg) -{ +struct CtdlMessage *CM_Duplicate(struct CtdlMessage *OrgMsg) { int i; struct CtdlMessage *NewMsg; @@ -489,7 +473,8 @@ void CtdlSetSeen(long *target_msgnums, int num_target_msgnums, cdbfr->ptr = NULL; /* CtdlSetSeen() now owns this memory */ num_msgs = cdbfr->len / sizeof(long); cdb_free(cdbfr); - } else { + } + else { return; /* No messages at all? No further action. */ } @@ -1055,14 +1040,14 @@ void mime_download(char *name, char *filename, char *partnum, char *disp, ) { 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; @@ -1690,10 +1675,7 @@ int CtdlOutputMsg(long msg_num, /* message number (local) to fetch */ } -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]; @@ -1726,23 +1708,29 @@ void OutputCtdlMsgHeaders( 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. + } + + + } } } @@ -1807,6 +1795,7 @@ void OutputRFC822MsgHeaders( break; case erFc822Addr: safestrncpy(fuser, mptr, sizeof_fuser); + break; case eRecipient: if (haschar(mptr, '@') == 0) { sanitize_truncated_recipient(mptr); @@ -1857,7 +1846,6 @@ void OutputRFC822MsgHeaders( case eSuppressIdx: case eExtnotify: case eVltMsgNum: - case eOrigLocal: /* these don't map to mime message headers. */ break; } @@ -2128,7 +2116,7 @@ int CtdlOutputPreLoadedMsg( /* 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 */ @@ -2139,9 +2127,9 @@ int CtdlOutputPreLoadedMsg( 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, ""); @@ -2568,7 +2556,7 @@ long send_message(struct CtdlMessage *msg) { /* - * Serialize a struct CtdlMessage into the format used on disk and network. + * Serialize a struct CtdlMessage into the format used on disk. * * This function loads up a "struct ser_ret" (defined in server.h) which * contains the length of the serialized message and a pointer to the @@ -2658,9 +2646,8 @@ void ReplicationChecks(struct CtdlMessage *msg) { * 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? */ + struct recptypes *recps, /* recipients (if mail) */ + const char *force /* force a particular room? */ ) { char hold_rm[ROOMNAMELEN]; char actual_rm[ROOMNAMELEN]; @@ -2839,7 +2826,7 @@ long CtdlSubmitMsg(struct CtdlMessage *msg, /* message to save */ */ 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); } } @@ -2986,7 +2973,7 @@ long quickie_message(const char *from, const char *subject) { struct CtdlMessage *msg; - recptypes *recp = NULL; + struct recptypes *recp = NULL; msg = malloc(sizeof(struct CtdlMessage)); memset(msg, 0, sizeof(struct CtdlMessage)); @@ -3022,7 +3009,7 @@ long quickie_message(const char *from, 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; @@ -3612,7 +3599,7 @@ void CtdlWriteObject(char *req_room, /* Room to stuff it in */ ); } /* Now write the data */ - CtdlSubmitMsg(msg, NULL, roomname, 0); + CtdlSubmitMsg(msg, NULL, roomname); CM_Free(msg); }