X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fmodules%2Fctdlproto%2Fserv_messages.c;h=480f849952f377411f56e72002d4e16ad0363bc6;hb=2e4e67a1f7f65568abace99d13a71024ad06ebde;hp=96e49b6534cf7e21636ac4cc52db8d4cef31fec2;hpb=2cd0bde63d12852bfe34c36e2582aeb63d228edb;p=citadel.git diff --git a/citadel/modules/ctdlproto/serv_messages.c b/citadel/modules/ctdlproto/serv_messages.c index 96e49b653..480f84995 100644 --- a/citadel/modules/ctdlproto/serv_messages.c +++ b/citadel/modules/ctdlproto/serv_messages.c @@ -1,20 +1,17 @@ -/* - * represent messages to the citadel clients - * - * Copyright (c) 1987-2017 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. - */ +// Message-related protocol commands for Citadel clients +// +// Copyright (c) 1987-2022 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 #include - #include "citserver.h" #include "ctdl_module.h" #include "internet_addressing.h" @@ -25,24 +22,18 @@ extern char *msgkeys[]; -/* - * Back end for the MSGS command: output message number only. - */ -void simple_listing(long msgnum, void *userdata) -{ +// Back end for the MSGS command: output message number only. +void simple_listing(long msgnum, void *userdata) { cprintf("%ld\n", msgnum); } -/* - * Back end for the MSGS command: output header summary. - */ -void headers_listing(long msgnum, void *userdata) -{ +// Back end for the MSGS command: output header summary. +void headers_listing(long msgnum, void *userdata) { struct CtdlMessage *msg; int output_mode = *(int *)userdata; - msg = CtdlFetchMessage(msgnum, 0, 1); + msg = CtdlFetchMessage(msgnum, 0); if (msg == NULL) { cprintf("%ld|0|||||||\n", msgnum); return; @@ -52,7 +43,6 @@ void headers_listing(long msgnum, void *userdata) if (!CM_IsEmpty(msg, eMsgSubject)) { char *p; for (p=msg->cm_fields[eMsgSubject]; *p; p++) { - printf("%c\n", *p); if (*p == '|') { *p = '-'; } @@ -64,7 +54,7 @@ void headers_listing(long msgnum, void *userdata) msgnum, (!CM_IsEmpty(msg, eTimestamp) ? msg->cm_fields[eTimestamp] : "0"), (!CM_IsEmpty(msg, eAuthor) ? msg->cm_fields[eAuthor] : ""), - (!CM_IsEmpty(msg, eNodeName) ? msg->cm_fields[eNodeName] : ""), + CtdlGetConfigStr("c_nodename"), // no more nodenames anymore (!CM_IsEmpty(msg, erFc822Addr) ? msg->cm_fields[erFc822Addr] : ""), (!CM_IsEmpty(msg, eMsgSubject) ? msg->cm_fields[eMsgSubject] : "") ); @@ -97,20 +87,20 @@ void headers_listing(long msgnum, void *userdata) CM_Free(msg); } -typedef struct _msg_filter{ +typedef struct _msg_filter { HashList *Filter; HashPos *p; StrBuf *buffer; -}msg_filter; +} msg_filter; -void headers_brief_filter(long msgnum, void *userdata) -{ + +void headers_brief_filter(long msgnum, void *userdata) { long i, l; struct CtdlMessage *msg; msg_filter *flt = (msg_filter*) userdata; l = GetCount(flt->Filter); - msg = CtdlFetchMessage(msgnum, 0, 1); + msg = CtdlFetchMessage(msgnum, 0); StrBufPrintf(flt->buffer, "%ld", msgnum); if (msg == NULL) { for (i = 0; i < l; i++) { @@ -135,14 +125,11 @@ void headers_brief_filter(long msgnum, void *userdata) cputbuf(flt->buffer); } -/* - * Back end for the MSGS command: output EUID header. - */ -void headers_euid(long msgnum, void *userdata) -{ +// Back end for the MSGS command: output EUID header. +void headers_euid(long msgnum, void *userdata) { struct CtdlMessage *msg; - msg = CtdlFetchMessage(msgnum, 0, 1); + msg = CtdlFetchMessage(msgnum, 0); if (msg == NULL) { cprintf("%ld||\n", msgnum); return; @@ -156,13 +143,9 @@ void headers_euid(long msgnum, void *userdata) } - -/* - * cmd_msgs() - get list of message #'s in this room - * implements the MSGS server command using CtdlForEachMessage() - */ -void cmd_msgs(char *cmdbuf) -{ +// cmd_msgs() - get list of message #'s in this room +// implements the MSGS server command using CtdlForEachMessage() +void cmd_msgs(char *cmdbuf) { int mode = 0; char which[16]; char buf[256]; @@ -299,6 +282,7 @@ void cmd_msgs(char *cmdbuf) cprintf("000\n"); } + /* * display a message (mode 0 - Citadel proprietary) */ @@ -315,11 +299,8 @@ void cmd_msg0(char *cmdbuf) } -/* - * display a message (mode 2 - RFC822) - */ -void cmd_msg2(char *cmdbuf) -{ +// display a message (mode 2 - RFC822) +void cmd_msg2(char *cmdbuf) { long msgid; int headers_only = HEADERS_ALL; @@ -330,51 +311,8 @@ void cmd_msg2(char *cmdbuf) } - -/* - * display a message (mode 3 - IGnet raw format - internal programs only) - */ -void cmd_msg3(char *cmdbuf) -{ - long msgnum; - struct CtdlMessage *msg = NULL; - struct ser_ret smr; - - if (CC->internal_pgm == 0) { - cprintf("%d This command is for internal programs only.\n", - ERROR + HIGHER_ACCESS_REQUIRED); - return; - } - - msgnum = extract_long(cmdbuf, 0); - msg = CtdlFetchMessage(msgnum, 1, 1); - if (msg == NULL) { - cprintf("%d Message %ld not found.\n", - ERROR + MESSAGE_NOT_FOUND, msgnum); - return; - } - - CtdlSerializeMessage(&smr, msg); - CM_Free(msg); - - if (smr.len == 0) { - cprintf("%d Unable to serialize message\n", - ERROR + INTERNAL_ERROR); - return; - } - - cprintf("%d %ld\n", BINARY_FOLLOWS, (long)smr.len); - client_write((char *)smr.ser, (int)smr.len); - free(smr.ser); -} - - - -/* - * Display a message using MIME content types - */ -void cmd_msg4(char *cmdbuf) -{ +// Display a message using MIME content types +void cmd_msg4(char *cmdbuf) { long msgid; char section[64]; @@ -384,12 +322,8 @@ void cmd_msg4(char *cmdbuf) } - -/* - * Client tells us its preferred message format(s) - */ -void cmd_msgp(char *cmdbuf) -{ +// Client tells us its preferred message format(s) +void cmd_msgp(char *cmdbuf) { if (!strcasecmp(cmdbuf, "dont_decode")) { CC->msg4_dont_decode = 1; cprintf("%d MSG4 will not pre-decode messages.\n", CIT_OK); @@ -401,11 +335,8 @@ void cmd_msgp(char *cmdbuf) } -/* - * Open a component of a MIME message as a download file - */ -void cmd_opna(char *cmdbuf) -{ +// Open a component of a MIME message as a download file +void cmd_opna(char *cmdbuf) { long msgid; char desired_section[128]; @@ -417,27 +348,20 @@ void cmd_opna(char *cmdbuf) } -/* - * Open a component of a MIME message and transmit it all at once - */ -void cmd_dlat(char *cmdbuf) -{ +// Open a component of a MIME message and transmit it all at once +void cmd_dlat(char *cmdbuf) { long msgid; char desired_section[128]; msgid = extract_long(cmdbuf, 0); extract_token(desired_section, cmdbuf, 1, '|', sizeof desired_section); - safestrncpy(CC->download_desired_section, desired_section, - sizeof CC->download_desired_section); + safestrncpy(CC->download_desired_section, desired_section, sizeof CC->download_desired_section); CtdlOutputMsg(msgid, MT_SPEW_SECTION, 0, 1, 1, NULL, 0, NULL, NULL, NULL); } -/* - * message entry - mode 0 (normal) - */ -void cmd_ent0(char *entargs) -{ - struct CitContext *CCC = CC; + +// message entry - mode 0 (normal) +void cmd_ent0(char *entargs) { int post = 0; char recp[SIZ]; char cc[SIZ]; @@ -451,10 +375,10 @@ void cmd_ent0(char *entargs) int anonymous = 0; char errmsg[SIZ]; int err = 0; - recptypes *valid = NULL; - recptypes *valid_to = NULL; - recptypes *valid_cc = NULL; - recptypes *valid_bcc = NULL; + struct recptypes *valid = NULL; + struct recptypes *valid_to = NULL; + struct recptypes *valid_cc = NULL; + struct recptypes *valid_bcc = NULL; char subject[SIZ]; int subject_required = 0; int do_confirm = 0; @@ -479,7 +403,6 @@ void cmd_ent0(char *entargs) switch(CC->room.QRdefaultview) { case VIEW_NOTES: case VIEW_WIKI: - case VIEW_WIKIMD: extract_token(supplied_euid, entargs, 9, '|', sizeof supplied_euid); break; default: @@ -499,10 +422,9 @@ void cmd_ent0(char *entargs) sizeof errmsg, NULL, POST_LOGGED_IN, - (!IsEmptyStr(references)) /* is this a reply? or a top-level post? */ - ); - if (err) - { + (!IsEmptyStr(references)) // is this a reply? or a top-level post? + ); + if (err) { cprintf("%d %s\n", err, errmsg); return; } @@ -510,32 +432,31 @@ void cmd_ent0(char *entargs) /* Check some other permission type things. */ if (IsEmptyStr(newusername)) { - strcpy(newusername, CCC->user.fullname); + strcpy(newusername, CC->user.fullname); } - if ( (CCC->user.axlevel < AxAideU) - && (strcasecmp(newusername, CCC->user.fullname)) - && (strcasecmp(newusername, CCC->cs_inet_fn)) - ) { + if ( (CC->user.axlevel < AxAideU) + && (strcasecmp(newusername, CC->user.fullname)) + && (strcasecmp(newusername, CC->cs_inet_fn)) + ) { cprintf("%d You don't have permission to author messages as '%s'.\n", ERROR + HIGHER_ACCESS_REQUIRED, newusername - ); + ); return; } - if (IsEmptyStr(newuseremail)) { newuseremail_ok = 1; } if (!IsEmptyStr(newuseremail)) { - if (!strcasecmp(newuseremail, CCC->cs_inet_email)) { + if (!strcasecmp(newuseremail, CC->cs_inet_email)) { newuseremail_ok = 1; } - else if (!IsEmptyStr(CCC->cs_inet_other_emails)) { - j = num_tokens(CCC->cs_inet_other_emails, '|'); + else if (!IsEmptyStr(CC->cs_inet_other_emails)) { + j = num_tokens(CC->cs_inet_other_emails, '|'); for (i=0; ics_inet_other_emails, i, '|', sizeof buf); + extract_token(buf, CC->cs_inet_other_emails, i, '|', sizeof buf); if (!strcasecmp(newuseremail, buf)) { newuseremail_ok = 1; } @@ -551,19 +472,18 @@ void cmd_ent0(char *entargs) return; } - CCC->cs_flags |= CS_POSTING; + CC->cs_flags |= CS_POSTING; - /* In mailbox rooms we have to behave a little differently -- - * make sure the user has specified at least one recipient. Then - * validate the recipient(s). We do this for the Mail> room, as - * well as any room which has the "Mailbox" view set - unless it - * is the DRAFTS room which does not require recipients - */ + // In mailbox rooms we have to behave a little differently -- + // make sure the user has specified at least one recipient. Then + // validate the recipient(s). We do this for the Mail> room, as + // well as any room which has the "Mailbox" view set - unless it + // is the DRAFTS room which does not require recipients. - if ( ( ( (CCC->room.QRflags & QR_MAILBOX) && (!strcasecmp(&CCC->room.QRname[11], MAILROOM)) ) - || ( (CCC->room.QRflags & QR_MAILBOX) && (CCC->curr_view == VIEW_MAILBOX) ) - ) && (strcasecmp(&CCC->room.QRname[11], USERDRAFTROOM)) !=0 ) { - if (CCC->user.axlevel < AxProbU) { + if ( ( ( (CC->room.QRflags & QR_MAILBOX) && (!strcasecmp(&CC->room.QRname[11], MAILROOM)) ) + || ( (CC->room.QRflags & QR_MAILBOX) && (CC->curr_view == VIEW_MAILBOX) ) + ) && (strcasecmp(&CC->room.QRname[11], USERDRAFTROOM)) !=0 ) { + if (CC->user.axlevel < AxProbU) { strcpy(recp, "sysop"); strcpy(cc, ""); strcpy(bcc, ""); @@ -593,7 +513,7 @@ void cmd_ent0(char *entargs) return; } - /* Recipient required, but none were specified */ + // Recipient required, but none were specified if ( (valid_to->num_error < 0) && (valid_cc->num_error < 0) && (valid_bcc->num_error < 0) ) { free_recipients(valid_to); free_recipients(valid_cc); @@ -603,7 +523,7 @@ void cmd_ent0(char *entargs) } if (valid_to->num_internet + valid_cc->num_internet + valid_bcc->num_internet > 0) { - if (CtdlCheckInternetMailPermission(&CCC->user)==0) { + if (CtdlCheckInternetMailPermission(&CC->user)==0) { cprintf("%d You do not have permission " "to send Internet mail.\n", ERROR + HIGHER_ACCESS_REQUIRED); @@ -614,10 +534,8 @@ void cmd_ent0(char *entargs) } } - if ( ( (valid_to->num_internet + valid_to->num_ignet + valid_cc->num_internet + valid_cc->num_ignet + valid_bcc->num_internet + valid_bcc->num_ignet) > 0) - && (CCC->user.axlevel < AxNetU) ) { - cprintf("%d Higher access required for network mail.\n", - ERROR + HIGHER_ACCESS_REQUIRED); + if ( ( (valid_to->num_internet + valid_cc->num_internet + valid_bcc->num_internet) > 0) && (CC->user.axlevel < AxNetU) ) { + cprintf("%d Higher access required for network mail.\n", ERROR + HIGHER_ACCESS_REQUIRED); free_recipients(valid_to); free_recipients(valid_cc); free_recipients(valid_bcc); @@ -626,8 +544,8 @@ void cmd_ent0(char *entargs) if ((RESTRICT_INTERNET == 1) && (valid_to->num_internet + valid_cc->num_internet + valid_bcc->num_internet > 0) - && ((CCC->user.flags & US_INTERNET) == 0) - && (!CCC->internal_pgm)) { + && ((CC->user.flags & US_INTERNET) == 0) + && (!CC->internal_pgm)) { cprintf("%d You don't have access to Internet mail.\n", ERROR + HIGHER_ACCESS_REQUIRED); free_recipients(valid_to); @@ -638,33 +556,31 @@ void cmd_ent0(char *entargs) } - /* Is this a room which has anonymous-only or anonymous-option? */ + // Is this a room which has anonymous-only or anonymous-option? anonymous = MES_NORMAL; - if (CCC->room.QRflags & QR_ANONONLY) { + if (CC->room.QRflags & QR_ANONONLY) { anonymous = MES_ANONONLY; } - if (CCC->room.QRflags & QR_ANONOPT) { - if (anon_flag == 1) { /* only if the user requested it */ + if (CC->room.QRflags & QR_ANONOPT) { + if (anon_flag == 1) { // only if the user requested it anonymous = MES_ANONOPT; } } - if ((CCC->room.QRflags & QR_MAILBOX) == 0) { + if ((CC->room.QRflags & QR_MAILBOX) == 0) { recp[0] = 0; } - /* Recommend to the client that the use of a message subject is - * strongly recommended in this room, if either the SUBJECTREQ flag - * is set, or if there is one or more Internet email recipients. - */ - if (CCC->room.QRflags2 & QR2_SUBJECTREQ) subject_required = 1; + // Recommend to the client that the use of a message subject is + // strongly recommended in this room, if either the SUBJECTREQ flag + // is set, or if there is one or more Internet email recipients. + + if (CC->room.QRflags2 & QR2_SUBJECTREQ) subject_required = 1; if ((valid_to) && (valid_to->num_internet > 0)) subject_required = 1; if ((valid_cc) && (valid_cc->num_internet > 0)) subject_required = 1; if ((valid_bcc) && (valid_bcc->num_internet > 0)) subject_required = 1; - /* If we're only checking the validity of the request, return - * success without creating the message. - */ + // If we're only checking the validity of the request, return success without creating the message. if (post == 0) { cprintf("%d %s|%d\n", CIT_OK, ((valid_to != NULL) ? valid_to->display_recp : ""), @@ -675,27 +591,26 @@ void cmd_ent0(char *entargs) return; } - /* We don't need these anymore because we'll do it differently below */ + // We don't need these anymore because we'll do it differently below free_recipients(valid_to); free_recipients(valid_cc); free_recipients(valid_bcc); - /* Read in the message from the client. */ + // Read in the message from the client. if (do_confirm) { cprintf("%d send message\n", START_CHAT_MODE); - } else { + } + else { cprintf("%d send message\n", SEND_LISTING); } - msg = CtdlMakeMessage(&CCC->user, recp, cc, - CCC->room.QRname, anonymous, format_type, + msg = CtdlMakeMessage(&CC->user, recp, cc, + CC->room.QRname, anonymous, format_type, newusername, newuseremail, subject, ((!IsEmptyStr(supplied_euid)) ? supplied_euid : NULL), NULL, references); - /* Put together one big recipients struct containing to/cc/bcc all in - * one. This is for the envelope. - */ + // Put together one big recipients struct containing to/cc/bcc all in one. This is for the envelope. char *all_recps = malloc(SIZ * 3); strcpy(all_recps, recp); if (!IsEmptyStr(cc)) { @@ -718,22 +633,19 @@ void cmd_ent0(char *entargs) } free(all_recps); - if ((valid != NULL) && (valid->num_room == 1) && !IsEmptyStr(valid->recp_orgroom)) - { - /* posting into an ML room? set the envelope from - * to the actual mail address so others get a valid - * reply-to-header. - */ + // posting into a mailing list room? set the envelope from + // to the actual mail address so others get a valid reply-to-header. + if ((valid != NULL) && (valid->num_room == 1) && !IsEmptyStr(valid->recp_orgroom)) { CM_SetField(msg, eenVelopeTo, valid->recp_orgroom, strlen(valid->recp_orgroom)); } if (msg != NULL) { - msgnum = CtdlSubmitMsg(msg, valid, "", QP_EADDR); + msgnum = CtdlSubmitMsg(msg, valid, ""); if (do_confirm) { cprintf("%ld\n", msgnum); - if (StrLength(CCC->StatusMessage) > 0) { - cprintf("%s\n", ChrPtr(CCC->StatusMessage)); + if (StrLength(CC->StatusMessage) > 0) { + cprintf("%s\n", ChrPtr(CC->StatusMessage)); } else if (msgnum >= 0L) { client_write(HKEY("Message accepted.\n")); @@ -758,11 +670,9 @@ void cmd_ent0(char *entargs) return; } -/* - * Delete message from current room - */ -void cmd_dele(char *args) -{ + +// Delete message from current room +void cmd_dele(char *args) { int num_deleted; int i; char msgset[SIZ]; @@ -783,9 +693,7 @@ void cmd_dele(char *args) return; } - /* - * Build our message set to be moved/copied - */ + // Build our message set to be moved/copied msgs = malloc(num_msgs * sizeof(long)); for (i=0; iuser, CC->curr_user); CtdlRoomAccess(&qtemp, &CC->user, &ra, NULL); - /* Check for permission to perform this operation. - * Remember: "CC->room" is source, "qtemp" is target. - */ + // Check for permission to perform this operation. + // Remember: "CC->room" is source, "qtemp" is target. permit = 0; - /* Admins can move/copy */ + // Admins can move/copy if (CC->user.axlevel >= AxAideU) permit = 1; - /* Room aides can move/copy */ + // Room aides can move/copy if (CC->user.usernum == CC->room.QRroomaide) permit = 1; - /* Permit move/copy from personal rooms */ + // Permit move/copy from personal rooms if ((CC->room.QRflags & QR_MAILBOX) && (qtemp.QRflags & QR_MAILBOX)) permit = 1; - /* Permit only copy from public to personal room */ - if ( (is_copy) - && (!(CC->room.QRflags & QR_MAILBOX)) - && (qtemp.QRflags & QR_MAILBOX)) permit = 1; + // Permit only copy from public to personal room + if ( (is_copy) + && (!(CC->room.QRflags & QR_MAILBOX)) + && (qtemp.QRflags & QR_MAILBOX) + ) { + permit = 1; + } - /* Permit message removal from collaborative delete rooms */ + // Permit message removal from collaborative delete rooms if (CC->room.QRflags2 & QR2_COLLABDEL) permit = 1; - /* Users allowed to post into the target room may move into it too. */ + // Users allowed to post into the target room may move into it too. if ((CC->room.QRflags & QR_MAILBOX) && (qtemp.QRflags & UA_POSTALLOWED)) permit = 1; - /* User must have access to target room */ + // User must have access to target room if (!(ra & UA_KNOWN)) permit = 0; if (!permit) { @@ -884,18 +790,14 @@ void cmd_move(char *args) return; } - /* - * Build our message set to be moved/copied - */ + // Build our message set to be moved/copied msgs = malloc(num_msgs * sizeof(long)); for (i=0; iroom.QRname, msgs, num_msgs, ""); } @@ -926,7 +826,6 @@ CTDL_MODULE_INIT(ctdl_message) CtdlRegisterProtoHook(cmd_msgs, "MSGS", "Output a list of messages in the current room"); CtdlRegisterProtoHook(cmd_msg0, "MSG0", "Output a message in plain text format"); CtdlRegisterProtoHook(cmd_msg2, "MSG2", "Output a message in RFC822 format"); - CtdlRegisterProtoHook(cmd_msg3, "MSG3", "Output a message in raw format (deprecated)"); CtdlRegisterProtoHook(cmd_msg4, "MSG4", "Output a message in the client's preferred format"); CtdlRegisterProtoHook(cmd_msgp, "MSGP", "Select preferred format for MSG4 output"); CtdlRegisterProtoHook(cmd_opna, "OPNA", "Open an attachment for download");