From 314acc50c58e49fb9a5df9d7f0c24b2535ba0757 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Sun, 1 Sep 2013 22:09:55 +0200 Subject: [PATCH] split citadel protocol related functions from msgbase.c into ctdl_message.c; fix missing header forward declarations. --- citadel/Makefile.in | 4 +- citadel/ctdl_message.c | 865 ++++++++++++++++++++ citadel/housekeeping.c | 1 + citadel/internet_addressing.h | 28 + citadel/modules/migrate/serv_migrate.c | 2 +- citadel/modules/network/serv_netmail.c | 2 +- citadel/modules/network/serv_netspool.c | 2 +- citadel/modules/rssclient/rss_atom_parser.h | 1 + citadel/msgbase.c | 796 +----------------- citadel/msgbase.h | 40 +- citadel/netconfig.c | 1 + citadel/scripts/mk_module_init.sh | 2 +- citadel/user_ops.c | 1 + 13 files changed, 909 insertions(+), 836 deletions(-) create mode 100644 citadel/ctdl_message.c diff --git a/citadel/Makefile.in b/citadel/Makefile.in index 8a982d920..8f8e4724a 100644 --- a/citadel/Makefile.in +++ b/citadel/Makefile.in @@ -78,7 +78,7 @@ SOURCES=utils/aidepost.c utils/citmail.c \ citserver.c clientsocket.c config.c control.c $(DATABASE) \ domain.c serv_extensions.c file_ops.c genstamp.c \ housekeeping.c ical_dezonify.c internet_addressing.c ecrash.c \ - locate_host.c auth.c msgbase.c parsedate.c \ + locate_host.c auth.c msgbase.c ctdl_message.c parsedate.c \ room_ops.c euidindex.c server_main.c ldap.c \ support.c sysdep.c user_ops.c journaling.c threads.c \ context.c event_client.c netconfig.c nttlist.c md5.c @@ -131,7 +131,7 @@ SERV_OBJS = server_main.o utillib/citadel_dirs.o event_client.o \ user_ops.o citserver.o sysdep.o serv_extensions.o \ $(DATABASE:.c=.o) domain.o \ control.o config.o support.o room_ops.o \ - file_ops.o msgbase.o euidindex.o \ + file_ops.o msgbase.o ctdl_message.o euidindex.o \ locate_host.o housekeeping.o ical_dezonify.o \ internet_addressing.o journaling.o \ parsedate.o genstamp.o ecrash.o threads.o context.o \ diff --git a/citadel/ctdl_message.c b/citadel/ctdl_message.c new file mode 100644 index 000000000..4d9230bdd --- /dev/null +++ b/citadel/ctdl_message.c @@ -0,0 +1,865 @@ +/* + * represent messages to the citadel clients + * + * Copyright (c) 1987-2012 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 + +#include "md5.h" + +#include +#include "citadel.h" +#include "server.h" +#include "serv_extensions.h" +#include "database.h" +///#include "msgbase.h" +#include "support.h" +#include "sysdep_decls.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 "euidindex.h" +#include "journaling.h" +#include "citadel_dirs.h" +#include "clientsocket.h" +#include "threads.h" + +#include "ctdl_module.h" + +extern char *msgkeys[]; + + + +/* + * 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) +{ + struct CtdlMessage *msg; + + msg = CtdlFetchMessage(msgnum, 0); + if (msg == NULL) { + cprintf("%ld|0|||||\n", msgnum); + return; + } + + cprintf("%ld|%s|%s|%s|%s|%s|\n", + 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] : ""), + (!CM_IsEmpty(msg, erFc822Addr) ? msg->cm_fields[erFc822Addr] : ""), + (!CM_IsEmpty(msg, eMsgSubject) ? msg->cm_fields[eMsgSubject] : "") + ); + CM_Free(msg); +} + +/* + * Back end for the MSGS command: output EUID header. + */ +void headers_euid(long msgnum, void *userdata) +{ + struct CtdlMessage *msg; + + msg = CtdlFetchMessage(msgnum, 0); + if (msg == NULL) { + cprintf("%ld||\n", msgnum); + return; + } + + cprintf("%ld|%s|%s\n", + msgnum, + (!CM_IsEmpty(msg, eExclusiveID) ? msg->cm_fields[eExclusiveID] : ""), + (!CM_IsEmpty(msg, eTimestamp) ? msg->cm_fields[eTimestamp] : "0")); + CM_Free(msg); +} + + + +/* + * 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]; + char tfield[256]; + char tvalue[256]; + int cm_ref = 0; + int i; + int with_template = 0; + struct CtdlMessage *template = NULL; + char search_string[1024]; + ForEachMsgCallback CallBack; + + if (CtdlAccessCheck(ac_logged_in_or_guest)) return; + + extract_token(which, cmdbuf, 0, '|', sizeof which); + cm_ref = extract_int(cmdbuf, 1); + extract_token(search_string, cmdbuf, 1, '|', sizeof search_string); + with_template = extract_int(cmdbuf, 2); + switch (extract_int(cmdbuf, 3)) + { + default: + case MSG_HDRS_BRIEF: + CallBack = simple_listing; + break; + case MSG_HDRS_ALL: + CallBack = headers_listing; + break; + case MSG_HDRS_EUID: + CallBack = headers_euid; + break; + } + + strcat(which, " "); + if (!strncasecmp(which, "OLD", 3)) + mode = MSGS_OLD; + else if (!strncasecmp(which, "NEW", 3)) + mode = MSGS_NEW; + else if (!strncasecmp(which, "FIRST", 5)) + mode = MSGS_FIRST; + else if (!strncasecmp(which, "LAST", 4)) + mode = MSGS_LAST; + else if (!strncasecmp(which, "GT", 2)) + mode = MSGS_GT; + else if (!strncasecmp(which, "LT", 2)) + mode = MSGS_LT; + else if (!strncasecmp(which, "SEARCH", 6)) + mode = MSGS_SEARCH; + else + mode = MSGS_ALL; + + if ( (mode == MSGS_SEARCH) && (!config.c_enable_fulltext) ) { + cprintf("%d Full text index is not enabled on this server.\n", + ERROR + CMD_NOT_SUPPORTED); + return; + } + + if (with_template) { + unbuffer_output(); + cprintf("%d Send template then receive message list\n", + START_CHAT_MODE); + template = (struct CtdlMessage *) + malloc(sizeof(struct CtdlMessage)); + memset(template, 0, sizeof(struct CtdlMessage)); + template->cm_magic = CTDLMESSAGE_MAGIC; + template->cm_anon_type = MES_NORMAL; + + while(client_getln(buf, sizeof buf) >= 0 && strcmp(buf,"000")) { + long tValueLen; + extract_token(tfield, buf, 0, '|', sizeof tfield); + tValueLen = extract_token(tvalue, buf, 1, '|', sizeof tvalue); + for (i='A'; i<='Z'; ++i) if (msgkeys[i]!=NULL) { + if (!strcasecmp(tfield, msgkeys[i])) { + CM_SetField(template, i, tvalue, tValueLen); + } + } + } + buffer_output(); + } + else { + cprintf("%d \n", LISTING_FOLLOWS); + } + + CtdlForEachMessage(mode, + ( (mode == MSGS_SEARCH) ? 0 : cm_ref ), + ( (mode == MSGS_SEARCH) ? search_string : NULL ), + NULL, + template, + CallBack, + NULL); + if (template != NULL) CM_Free(template); + cprintf("000\n"); +} + +/* + * display a message (mode 0 - Citadel proprietary) + */ +void cmd_msg0(char *cmdbuf) +{ + long msgid; + int headers_only = HEADERS_ALL; + + msgid = extract_long(cmdbuf, 0); + headers_only = extract_int(cmdbuf, 1); + + CtdlOutputMsg(msgid, MT_CITADEL, headers_only, 1, 0, NULL, 0, NULL, NULL); + return; +} + + +/* + * display a message (mode 2 - RFC822) + */ +void cmd_msg2(char *cmdbuf) +{ + long msgid; + int headers_only = HEADERS_ALL; + + msgid = extract_long(cmdbuf, 0); + headers_only = extract_int(cmdbuf, 1); + + CtdlOutputMsg(msgid, MT_RFC822, headers_only, 1, 1, NULL, 0, NULL, NULL); +} + + + +/* + * 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); + 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) +{ + long msgid; + char section[64]; + + msgid = extract_long(cmdbuf, 0); + extract_token(section, cmdbuf, 1, '|', sizeof section); + CtdlOutputMsg(msgid, MT_MIME, 0, 1, 0, (section[0] ? section : NULL) , 0, NULL, NULL); +} + + + +/* + * 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); + } + else { + safestrncpy(CC->preferred_formats, cmdbuf, sizeof(CC->preferred_formats)); + cprintf("%d Preferred MIME formats have been set.\n", CIT_OK); + } +} + + +/* + * Open a component of a MIME message as a download file + */ +void cmd_opna(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); + CtdlOutputMsg(msgid, MT_DOWNLOAD, 0, 1, 1, NULL, 0, NULL, NULL); +} + + +/* + * 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); + CtdlOutputMsg(msgid, MT_SPEW_SECTION, 0, 1, 1, NULL, 0, NULL, NULL); +} + +/* + * message entry - mode 0 (normal) + */ +void cmd_ent0(char *entargs) +{ + struct CitContext *CCC = CC; + int post = 0; + char recp[SIZ]; + char cc[SIZ]; + char bcc[SIZ]; + char supplied_euid[128]; + int anon_flag = 0; + int format_type = 0; + char newusername[256]; + char newuseremail[256]; + struct CtdlMessage *msg; + int anonymous = 0; + char errmsg[SIZ]; + int err = 0; + 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; + long msgnum; + int i, j; + char buf[256]; + int newuseremail_ok = 0; + char references[SIZ]; + char *ptr; + + unbuffer_output(); + + post = extract_int(entargs, 0); + extract_token(recp, entargs, 1, '|', sizeof recp); + anon_flag = extract_int(entargs, 2); + format_type = extract_int(entargs, 3); + extract_token(subject, entargs, 4, '|', sizeof subject); + extract_token(newusername, entargs, 5, '|', sizeof newusername); + do_confirm = extract_int(entargs, 6); + extract_token(cc, entargs, 7, '|', sizeof cc); + extract_token(bcc, entargs, 8, '|', sizeof bcc); + switch(CC->room.QRdefaultview) { + case VIEW_NOTES: + case VIEW_WIKI: + extract_token(supplied_euid, entargs, 9, '|', sizeof supplied_euid); + break; + default: + supplied_euid[0] = 0; + break; + } + extract_token(newuseremail, entargs, 10, '|', sizeof newuseremail); + extract_token(references, entargs, 11, '|', sizeof references); + for (ptr=references; *ptr != 0; ++ptr) { + if (*ptr == '!') *ptr = '|'; + } + + /* first check to make sure the request is valid. */ + + err = CtdlDoIHavePermissionToPostInThisRoom( + errmsg, + sizeof errmsg, + NULL, + POST_LOGGED_IN, + (!IsEmptyStr(references)) /* is this a reply? or a top-level post? */ + ); + if (err) + { + cprintf("%d %s\n", err, errmsg); + return; + } + + /* Check some other permission type things. */ + + if (IsEmptyStr(newusername)) { + strcpy(newusername, CCC->user.fullname); + } + if ( (CCC->user.axlevel < AxAideU) + && (strcasecmp(newusername, CCC->user.fullname)) + && (strcasecmp(newusername, CCC->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)) { + newuseremail_ok = 1; + } + else if (!IsEmptyStr(CCC->cs_inet_other_emails)) { + j = num_tokens(CCC->cs_inet_other_emails, '|'); + for (i=0; ics_inet_other_emails, i, '|', sizeof buf); + if (!strcasecmp(newuseremail, buf)) { + newuseremail_ok = 1; + } + } + } + } + + if (!newuseremail_ok) { + cprintf("%d You don't have permission to author messages as '%s'.\n", + ERROR + HIGHER_ACCESS_REQUIRED, + newuseremail + ); + return; + } + + CCC->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 + */ + + 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) { + strcpy(recp, "sysop"); + strcpy(cc, ""); + strcpy(bcc, ""); + } + + valid_to = validate_recipients(recp, NULL, 0); + if (valid_to->num_error > 0) { + cprintf("%d %s\n", ERROR + NO_SUCH_USER, valid_to->errormsg); + free_recipients(valid_to); + return; + } + + valid_cc = validate_recipients(cc, NULL, 0); + if (valid_cc->num_error > 0) { + cprintf("%d %s\n", ERROR + NO_SUCH_USER, valid_cc->errormsg); + free_recipients(valid_to); + free_recipients(valid_cc); + return; + } + + valid_bcc = validate_recipients(bcc, NULL, 0); + if (valid_bcc->num_error > 0) { + cprintf("%d %s\n", ERROR + NO_SUCH_USER, valid_bcc->errormsg); + free_recipients(valid_to); + free_recipients(valid_cc); + free_recipients(valid_bcc); + return; + } + + /* 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); + free_recipients(valid_bcc); + cprintf("%d At least one recipient is required.\n", ERROR + NO_SUCH_USER); + return; + } + + if (valid_to->num_internet + valid_cc->num_internet + valid_bcc->num_internet > 0) { + if (CtdlCheckInternetMailPermission(&CCC->user)==0) { + cprintf("%d You do not have permission " + "to send Internet mail.\n", + ERROR + HIGHER_ACCESS_REQUIRED); + free_recipients(valid_to); + free_recipients(valid_cc); + free_recipients(valid_bcc); + return; + } + } + + 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); + free_recipients(valid_to); + free_recipients(valid_cc); + free_recipients(valid_bcc); + return; + } + + 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)) { + cprintf("%d You don't have access to Internet mail.\n", + ERROR + HIGHER_ACCESS_REQUIRED); + free_recipients(valid_to); + free_recipients(valid_cc); + free_recipients(valid_bcc); + return; + } + + } + + /* Is this a room which has anonymous-only or anonymous-option? */ + anonymous = MES_NORMAL; + if (CCC->room.QRflags & QR_ANONONLY) { + anonymous = MES_ANONONLY; + } + if (CCC->room.QRflags & QR_ANONOPT) { + if (anon_flag == 1) { /* only if the user requested it */ + anonymous = MES_ANONOPT; + } + } + + if ((CCC->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; + 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 (post == 0) { + cprintf("%d %s|%d\n", CIT_OK, + ((valid_to != NULL) ? valid_to->display_recp : ""), + subject_required); + free_recipients(valid_to); + free_recipients(valid_cc); + free_recipients(valid_bcc); + return; + } + + /* 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. */ + if (do_confirm) { + cprintf("%d send message\n", START_CHAT_MODE); + } else { + cprintf("%d send message\n", SEND_LISTING); + } + + msg = CtdlMakeMessage(&CCC->user, recp, cc, + CCC->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. + */ + char *all_recps = malloc(SIZ * 3); + strcpy(all_recps, recp); + if (!IsEmptyStr(cc)) { + if (!IsEmptyStr(all_recps)) { + strcat(all_recps, ","); + } + strcat(all_recps, cc); + } + if (!IsEmptyStr(bcc)) { + if (!IsEmptyStr(all_recps)) { + strcat(all_recps, ","); + } + strcat(all_recps, bcc); + } + if (!IsEmptyStr(all_recps)) { + valid = validate_recipients(all_recps, NULL, 0); + } + else { + valid = NULL; + } + free(all_recps); + + if ((valid != NULL) && (valid->num_room == 1)) + { + /* posting into an ML room? set the envelope from + * to the actual mail address so others get a valid + * reply-to-header. + */ + msg->cm_fields[eenVelopeTo] = strdup(valid->recp_orgroom); + } + + if (msg != NULL) { + msgnum = CtdlSubmitMsg(msg, valid, "", QP_EADDR); + if (do_confirm) { + cprintf("%ld\n", msgnum); + + if (StrLength(CCC->StatusMessage) > 0) { + cprintf("%s\n", ChrPtr(CCC->StatusMessage)); + } + else if (msgnum >= 0L) { + client_write(HKEY("Message accepted.\n")); + } + else { + client_write(HKEY("Internal error.\n")); + } + + if (!CM_IsEmpty(msg, eExclusiveID)) { + cprintf("%s\n", msg->cm_fields[eExclusiveID]); + } else { + cprintf("\n"); + } + cprintf("000\n"); + } + + CM_Free(msg); + } + if (valid != NULL) { + free_recipients(valid); + } + return; +} + +/* + * Delete message from current room + */ +void cmd_dele(char *args) +{ + int num_deleted; + int i; + char msgset[SIZ]; + char msgtok[32]; + long *msgs; + int num_msgs = 0; + + extract_token(msgset, args, 0, '|', sizeof msgset); + num_msgs = num_tokens(msgset, ','); + if (num_msgs < 1) { + cprintf("%d Nothing to do.\n", CIT_OK); + return; + } + + if (CtdlDoIHavePermissionToDeleteMessagesFromThisRoom() == 0) { + cprintf("%d Higher access required.\n", + ERROR + HIGHER_ACCESS_REQUIRED); + return; + } + + /* + * Build our message set to be moved/copied + */ + msgs = malloc(num_msgs * sizeof(long)); + for (i=0; iroom.QRname, msgs, num_msgs, ""); + free(msgs); + + if (num_deleted) { + cprintf("%d %d message%s deleted.\n", CIT_OK, + num_deleted, ((num_deleted != 1) ? "s" : "")); + } else { + cprintf("%d Message not found.\n", ERROR + MESSAGE_NOT_FOUND); + } +} + + + +/* + * move or copy a message to another room + */ +void cmd_move(char *args) +{ + char msgset[SIZ]; + char msgtok[32]; + long *msgs; + int num_msgs = 0; + + char targ[ROOMNAMELEN]; + struct ctdlroom qtemp; + int err; + int is_copy = 0; + int ra; + int permit = 0; + int i; + + extract_token(msgset, args, 0, '|', sizeof msgset); + num_msgs = num_tokens(msgset, ','); + if (num_msgs < 1) { + cprintf("%d Nothing to do.\n", CIT_OK); + return; + } + + extract_token(targ, args, 1, '|', sizeof targ); + convert_room_name_macros(targ, sizeof targ); + targ[ROOMNAMELEN - 1] = 0; + is_copy = extract_int(args, 2); + + if (CtdlGetRoom(&qtemp, targ) != 0) { + cprintf("%d '%s' does not exist.\n", ERROR + ROOM_NOT_FOUND, targ); + return; + } + + if (!strcasecmp(qtemp.QRname, CC->room.QRname)) { + cprintf("%d Source and target rooms are the same.\n", ERROR + ALREADY_EXISTS); + return; + } + + CtdlGetUser(&CC->user, CC->curr_user); + CtdlRoomAccess(&qtemp, &CC->user, &ra, NULL); + + /* Check for permission to perform this operation. + * Remember: "CC->room" is source, "qtemp" is target. + */ + permit = 0; + + /* Admins can move/copy */ + if (CC->user.axlevel >= AxAideU) permit = 1; + + /* Room aides can move/copy */ + if (CC->user.usernum == CC->room.QRroomaide) permit = 1; + + /* 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 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. */ + if ((CC->room.QRflags & QR_MAILBOX) && + (qtemp.QRflags & UA_POSTALLOWED)) permit = 1; + + /* User must have access to target room */ + if (!(ra & UA_KNOWN)) permit = 0; + + if (!permit) { + cprintf("%d Higher access required.\n", + ERROR + HIGHER_ACCESS_REQUIRED); + return; + } + + /* + * Build our message set to be moved/copied + */ + msgs = malloc(num_msgs * sizeof(long)); + for (i=0; iroom.QRname, msgs, num_msgs, ""); + } + free(msgs); + + cprintf("%d Message(s) %s.\n", CIT_OK, (is_copy ? "copied" : "moved") ); +} + + +/*****************************************************************************/ +/* MODULE INITIALIZATION STUFF */ +/*****************************************************************************/ +CTDL_MODULE_INIT(ctdl_message) +{ + if (!threading) { + + 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"); + CtdlRegisterProtoHook(cmd_dlat, "DLAT", "Download an attachment"); + CtdlRegisterProtoHook(cmd_ent0, "ENT0", "Enter a message"); + CtdlRegisterProtoHook(cmd_dele, "DELE", "Delete a message"); + CtdlRegisterProtoHook(cmd_move, "MOVE", "Move or copy a message to another room"); + } + + /* return our Subversion id for the Log */ + return "ctdl_message"; +} diff --git a/citadel/housekeeping.c b/citadel/housekeeping.c index 108410af2..077b50930 100644 --- a/citadel/housekeeping.c +++ b/citadel/housekeeping.c @@ -49,6 +49,7 @@ #include "room_ops.h" #include "database.h" #include "msgbase.h" +#include "internet_addressing.h" #include "journaling.h" #include "ctdl_module.h" diff --git a/citadel/internet_addressing.h b/citadel/internet_addressing.h index 5f59ac951..74e581883 100644 --- a/citadel/internet_addressing.h +++ b/citadel/internet_addressing.h @@ -8,6 +8,34 @@ struct internet_address_list { char ial_name[SIZ]; }; +/* Data structure returned by validate_recipients() */ +struct recptypes { + int recptypes_magic; + int num_local; + int num_internet; + int num_ignet; + int num_room; + int num_error; + char *errormsg; + char *recp_local; + char *recp_internet; + char *recp_ignet; + char *recp_room; + char *recp_orgroom; + char *display_recp; + char *bounce_to; + char *envelope_from; + char *sending_room; +}; + +#define RECPTYPES_MAGIC 0xfeeb + +struct recptypes *validate_recipients(const char *recipients, + const char *RemoteIdentifier, + int Flags); + +void free_recipients(struct recptypes *); + int fuzzy_match(struct ctdluser *us, char *matchstring); void process_rfc822_addr(const char *rfc822, char *user, char *node, char *name); diff --git a/citadel/modules/migrate/serv_migrate.c b/citadel/modules/migrate/serv_migrate.c index 91815fa79..d60da3e1e 100644 --- a/citadel/modules/migrate/serv_migrate.c +++ b/citadel/modules/migrate/serv_migrate.c @@ -297,7 +297,7 @@ void migr_export_message(long msgnum) { client_write("", 23); xml_strout(smi.meta_content_type); client_write("\n", 25); client_write("", 10); - serialize_message(&smr, msg); + CtdlSerializeMessage(&smr, msg); CM_Free(msg); /* Predict the buffer size we need. Expand the buffer if necessary. */ diff --git a/citadel/modules/network/serv_netmail.c b/citadel/modules/network/serv_netmail.c index f0ca8d928..d44be9074 100644 --- a/citadel/modules/network/serv_netmail.c +++ b/citadel/modules/network/serv_netmail.c @@ -540,7 +540,7 @@ void network_process_ignetpush(SpoolControl *sc, struct CtdlMessage *omsg, long } /* serialize it for transmission */ - serialize_message(&sermsg, msg); + CtdlSerializeMessage(&sermsg, msg); if (sermsg.len > 0) { /* write it to a spool file */ diff --git a/citadel/modules/network/serv_netspool.c b/citadel/modules/network/serv_netspool.c index a309a0b7c..939409175 100644 --- a/citadel/modules/network/serv_netspool.c +++ b/citadel/modules/network/serv_netspool.c @@ -473,7 +473,7 @@ void network_process_buffer(char *buffer, long size, HashList *working_ignetcfg, Netmap_AddMe(msg, HKEY("unknown_user")); /* serialize the message */ - serialize_message(&sermsg, msg); + CtdlSerializeMessage(&sermsg, msg); /* now send it */ if (StrLength(nexthop) == 0) { diff --git a/citadel/modules/rssclient/rss_atom_parser.h b/citadel/modules/rssclient/rss_atom_parser.h index acddbe919..ad0f8b2c4 100644 --- a/citadel/modules/rssclient/rss_atom_parser.h +++ b/citadel/modules/rssclient/rss_atom_parser.h @@ -18,6 +18,7 @@ * */ +#include "internet_addressing.h" #define RSS_UNSET (1<<0) #define RSS_RSS (1<<1) diff --git a/citadel/msgbase.c b/citadel/msgbase.c index 39c79d3d7..03ef35df6 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -351,62 +351,6 @@ struct CtdlMessage * CM_Duplicate(struct CtdlMessage *OrgMsg) -/* - * 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) -{ - struct CtdlMessage *msg; - - msg = CtdlFetchMessage(msgnum, 0); - if (msg == NULL) { - cprintf("%ld|0|||||\n", msgnum); - return; - } - - cprintf("%ld|%s|%s|%s|%s|%s|\n", - 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] : ""), - (!CM_IsEmpty(msg, erFc822Addr) ? msg->cm_fields[erFc822Addr] : ""), - (!CM_IsEmpty(msg, eMsgSubject) ? msg->cm_fields[eMsgSubject] : "") - ); - CM_Free(msg); -} - -/* - * Back end for the MSGS command: output EUID header. - */ -void headers_euid(long msgnum, void *userdata) -{ - struct CtdlMessage *msg; - - msg = CtdlFetchMessage(msgnum, 0); - if (msg == NULL) { - cprintf("%ld||\n", msgnum); - return; - } - - cprintf("%ld|%s|%s\n", - msgnum, - (!CM_IsEmpty(msg, eExclusiveID) ? msg->cm_fields[eExclusiveID] : ""), - (!CM_IsEmpty(msg, eTimestamp) ? msg->cm_fields[eTimestamp] : "0")); - CM_Free(msg); -} - - - /* Determine if a given message matches the fields in a message template. @@ -917,106 +861,6 @@ int CtdlForEachMessage(int mode, long ref, char *search_string, -/* - * 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]; - char tfield[256]; - char tvalue[256]; - int cm_ref = 0; - int i; - int with_template = 0; - struct CtdlMessage *template = NULL; - char search_string[1024]; - ForEachMsgCallback CallBack; - - if (CtdlAccessCheck(ac_logged_in_or_guest)) return; - - extract_token(which, cmdbuf, 0, '|', sizeof which); - cm_ref = extract_int(cmdbuf, 1); - extract_token(search_string, cmdbuf, 1, '|', sizeof search_string); - with_template = extract_int(cmdbuf, 2); - switch (extract_int(cmdbuf, 3)) - { - default: - case MSG_HDRS_BRIEF: - CallBack = simple_listing; - break; - case MSG_HDRS_ALL: - CallBack = headers_listing; - break; - case MSG_HDRS_EUID: - CallBack = headers_euid; - break; - } - - strcat(which, " "); - if (!strncasecmp(which, "OLD", 3)) - mode = MSGS_OLD; - else if (!strncasecmp(which, "NEW", 3)) - mode = MSGS_NEW; - else if (!strncasecmp(which, "FIRST", 5)) - mode = MSGS_FIRST; - else if (!strncasecmp(which, "LAST", 4)) - mode = MSGS_LAST; - else if (!strncasecmp(which, "GT", 2)) - mode = MSGS_GT; - else if (!strncasecmp(which, "LT", 2)) - mode = MSGS_LT; - else if (!strncasecmp(which, "SEARCH", 6)) - mode = MSGS_SEARCH; - else - mode = MSGS_ALL; - - if ( (mode == MSGS_SEARCH) && (!config.c_enable_fulltext) ) { - cprintf("%d Full text index is not enabled on this server.\n", - ERROR + CMD_NOT_SUPPORTED); - return; - } - - if (with_template) { - unbuffer_output(); - cprintf("%d Send template then receive message list\n", - START_CHAT_MODE); - template = (struct CtdlMessage *) - malloc(sizeof(struct CtdlMessage)); - memset(template, 0, sizeof(struct CtdlMessage)); - template->cm_magic = CTDLMESSAGE_MAGIC; - template->cm_anon_type = MES_NORMAL; - - while(client_getln(buf, sizeof buf) >= 0 && strcmp(buf,"000")) { - long tValueLen; - extract_token(tfield, buf, 0, '|', sizeof tfield); - tValueLen = extract_token(tvalue, buf, 1, '|', sizeof tvalue); - for (i='A'; i<='Z'; ++i) if (msgkeys[i]!=NULL) { - if (!strcasecmp(tfield, msgkeys[i])) { - CM_SetField(template, i, tvalue, tValueLen); - } - } - } - buffer_output(); - } - else { - cprintf("%d \n", LISTING_FOLLOWS); - } - - CtdlForEachMessage(mode, - ( (mode == MSGS_SEARCH) ? 0 : cm_ref ), - ( (mode == MSGS_SEARCH) ? search_string : NULL ), - NULL, - template, - CallBack, - NULL); - if (template != NULL) CM_Free(template); - cprintf("000\n"); -} - - /* * memfmout() - Citadel text formatter and paginator. * Although the original purpose of this routine was to format @@ -2415,141 +2259,6 @@ DONE: /* now we're done */ return(om_ok); } - -/* - * display a message (mode 0 - Citadel proprietary) - */ -void cmd_msg0(char *cmdbuf) -{ - long msgid; - int headers_only = HEADERS_ALL; - - msgid = extract_long(cmdbuf, 0); - headers_only = extract_int(cmdbuf, 1); - - CtdlOutputMsg(msgid, MT_CITADEL, headers_only, 1, 0, NULL, 0, NULL, NULL); - return; -} - - -/* - * display a message (mode 2 - RFC822) - */ -void cmd_msg2(char *cmdbuf) -{ - long msgid; - int headers_only = HEADERS_ALL; - - msgid = extract_long(cmdbuf, 0); - headers_only = extract_int(cmdbuf, 1); - - CtdlOutputMsg(msgid, MT_RFC822, headers_only, 1, 1, NULL, 0, NULL, NULL); -} - - - -/* - * 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); - if (msg == NULL) { - cprintf("%d Message %ld not found.\n", - ERROR + MESSAGE_NOT_FOUND, msgnum); - return; - } - - serialize_message(&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) -{ - long msgid; - char section[64]; - - msgid = extract_long(cmdbuf, 0); - extract_token(section, cmdbuf, 1, '|', sizeof section); - CtdlOutputMsg(msgid, MT_MIME, 0, 1, 0, (section[0] ? section : NULL) , 0, NULL, NULL); -} - - - -/* - * 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); - } - else { - safestrncpy(CC->preferred_formats, cmdbuf, sizeof(CC->preferred_formats)); - cprintf("%d Preferred MIME formats have been set.\n", CIT_OK); - } -} - - -/* - * Open a component of a MIME message as a download file - */ -void cmd_opna(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); - CtdlOutputMsg(msgid, MT_DOWNLOAD, 0, 1, 1, NULL, 0, NULL, NULL); -} - - -/* - * 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); - CtdlOutputMsg(msgid, MT_SPEW_SECTION, 0, 1, 1, NULL, 0, NULL, NULL); -} - - /* * Save one or more message pointers into a specified room * (Returns 0 for success, nonzero for failure) @@ -2772,7 +2481,7 @@ long send_message(struct CtdlMessage *msg) { } /* Serialize our data structure for storage in the database */ - serialize_message(&smr, msg); + CtdlSerializeMessage(&smr, msg); if (is_bigmsg) { msg->cm_fields[eMesageText] = holdM; @@ -2819,7 +2528,7 @@ long send_message(struct CtdlMessage *msg) { * contains the length of the serialized message and a pointer to the * serialized message in memory. THE LATTER MUST BE FREED BY THE CALLER. */ -void serialize_message(struct ser_ret *ret, /* return values */ +void CtdlSerializeMessage(struct ser_ret *ret, /* return values */ struct CtdlMessage *msg) /* unserialized msg */ { struct CitContext *CCC = CC; @@ -2833,7 +2542,7 @@ void serialize_message(struct ser_ret *ret, /* return values */ * Check for valid message format */ if (CM_IsValidMsg(msg) == 0) { - MSGM_syslog(LOG_ERR, "serialize_message() aborting due to invalid message\n"); + MSGM_syslog(LOG_ERR, "CtdlSerializeMessage() aborting due to invalid message\n"); ret->len = 0; ret->ser = NULL; return; @@ -2849,7 +2558,7 @@ void serialize_message(struct ser_ret *ret, /* return values */ ret->ser = malloc(ret->len); if (ret->ser == NULL) { - MSG_syslog(LOG_ERR, "serialize_message() malloc(%ld) failed: %s\n", + MSG_syslog(LOG_ERR, "CtdlSerializeMessage() malloc(%ld) failed: %s\n", (long)ret->len, strerror(errno)); ret->len = 0; ret->ser = NULL; @@ -3224,7 +2933,7 @@ long CtdlSubmitMsg(struct CtdlMessage *msg, /* message to save */ extract_token(msg->cm_fields[eRecipient], recipient, 0, '@', SIZ); extract_token(msg->cm_fields[eDestination], recipient, 1, '@', 128); - serialize_message(&smr, msg); + CtdlSerializeMessage(&smr, msg); if (smr.len > 0) { snprintf(submit_filename, sizeof submit_filename, "%s/netmail.%04lx.%04x.%04x", @@ -3880,332 +3589,6 @@ struct CtdlMessage *CtdlMakeMessage( -/* - * message entry - mode 0 (normal) - */ -void cmd_ent0(char *entargs) -{ - struct CitContext *CCC = CC; - int post = 0; - char recp[SIZ]; - char cc[SIZ]; - char bcc[SIZ]; - char supplied_euid[128]; - int anon_flag = 0; - int format_type = 0; - char newusername[256]; - char newuseremail[256]; - struct CtdlMessage *msg; - int anonymous = 0; - char errmsg[SIZ]; - int err = 0; - 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; - long msgnum; - int i, j; - char buf[256]; - int newuseremail_ok = 0; - char references[SIZ]; - char *ptr; - - unbuffer_output(); - - post = extract_int(entargs, 0); - extract_token(recp, entargs, 1, '|', sizeof recp); - anon_flag = extract_int(entargs, 2); - format_type = extract_int(entargs, 3); - extract_token(subject, entargs, 4, '|', sizeof subject); - extract_token(newusername, entargs, 5, '|', sizeof newusername); - do_confirm = extract_int(entargs, 6); - extract_token(cc, entargs, 7, '|', sizeof cc); - extract_token(bcc, entargs, 8, '|', sizeof bcc); - switch(CC->room.QRdefaultview) { - case VIEW_NOTES: - case VIEW_WIKI: - extract_token(supplied_euid, entargs, 9, '|', sizeof supplied_euid); - break; - default: - supplied_euid[0] = 0; - break; - } - extract_token(newuseremail, entargs, 10, '|', sizeof newuseremail); - extract_token(references, entargs, 11, '|', sizeof references); - for (ptr=references; *ptr != 0; ++ptr) { - if (*ptr == '!') *ptr = '|'; - } - - /* first check to make sure the request is valid. */ - - err = CtdlDoIHavePermissionToPostInThisRoom( - errmsg, - sizeof errmsg, - NULL, - POST_LOGGED_IN, - (!IsEmptyStr(references)) /* is this a reply? or a top-level post? */ - ); - if (err) - { - cprintf("%d %s\n", err, errmsg); - return; - } - - /* Check some other permission type things. */ - - if (IsEmptyStr(newusername)) { - strcpy(newusername, CCC->user.fullname); - } - if ( (CCC->user.axlevel < AxAideU) - && (strcasecmp(newusername, CCC->user.fullname)) - && (strcasecmp(newusername, CCC->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)) { - newuseremail_ok = 1; - } - else if (!IsEmptyStr(CCC->cs_inet_other_emails)) { - j = num_tokens(CCC->cs_inet_other_emails, '|'); - for (i=0; ics_inet_other_emails, i, '|', sizeof buf); - if (!strcasecmp(newuseremail, buf)) { - newuseremail_ok = 1; - } - } - } - } - - if (!newuseremail_ok) { - cprintf("%d You don't have permission to author messages as '%s'.\n", - ERROR + HIGHER_ACCESS_REQUIRED, - newuseremail - ); - return; - } - - CCC->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 - */ - - 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) { - strcpy(recp, "sysop"); - strcpy(cc, ""); - strcpy(bcc, ""); - } - - valid_to = validate_recipients(recp, NULL, 0); - if (valid_to->num_error > 0) { - cprintf("%d %s\n", ERROR + NO_SUCH_USER, valid_to->errormsg); - free_recipients(valid_to); - return; - } - - valid_cc = validate_recipients(cc, NULL, 0); - if (valid_cc->num_error > 0) { - cprintf("%d %s\n", ERROR + NO_SUCH_USER, valid_cc->errormsg); - free_recipients(valid_to); - free_recipients(valid_cc); - return; - } - - valid_bcc = validate_recipients(bcc, NULL, 0); - if (valid_bcc->num_error > 0) { - cprintf("%d %s\n", ERROR + NO_SUCH_USER, valid_bcc->errormsg); - free_recipients(valid_to); - free_recipients(valid_cc); - free_recipients(valid_bcc); - return; - } - - /* 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); - free_recipients(valid_bcc); - cprintf("%d At least one recipient is required.\n", ERROR + NO_SUCH_USER); - return; - } - - if (valid_to->num_internet + valid_cc->num_internet + valid_bcc->num_internet > 0) { - if (CtdlCheckInternetMailPermission(&CCC->user)==0) { - cprintf("%d You do not have permission " - "to send Internet mail.\n", - ERROR + HIGHER_ACCESS_REQUIRED); - free_recipients(valid_to); - free_recipients(valid_cc); - free_recipients(valid_bcc); - return; - } - } - - 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); - free_recipients(valid_to); - free_recipients(valid_cc); - free_recipients(valid_bcc); - return; - } - - 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)) { - cprintf("%d You don't have access to Internet mail.\n", - ERROR + HIGHER_ACCESS_REQUIRED); - free_recipients(valid_to); - free_recipients(valid_cc); - free_recipients(valid_bcc); - return; - } - - } - - /* Is this a room which has anonymous-only or anonymous-option? */ - anonymous = MES_NORMAL; - if (CCC->room.QRflags & QR_ANONONLY) { - anonymous = MES_ANONONLY; - } - if (CCC->room.QRflags & QR_ANONOPT) { - if (anon_flag == 1) { /* only if the user requested it */ - anonymous = MES_ANONOPT; - } - } - - if ((CCC->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; - 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 (post == 0) { - cprintf("%d %s|%d\n", CIT_OK, - ((valid_to != NULL) ? valid_to->display_recp : ""), - subject_required); - free_recipients(valid_to); - free_recipients(valid_cc); - free_recipients(valid_bcc); - return; - } - - /* 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. */ - if (do_confirm) { - cprintf("%d send message\n", START_CHAT_MODE); - } else { - cprintf("%d send message\n", SEND_LISTING); - } - - msg = CtdlMakeMessage(&CCC->user, recp, cc, - CCC->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. - */ - char *all_recps = malloc(SIZ * 3); - strcpy(all_recps, recp); - if (!IsEmptyStr(cc)) { - if (!IsEmptyStr(all_recps)) { - strcat(all_recps, ","); - } - strcat(all_recps, cc); - } - if (!IsEmptyStr(bcc)) { - if (!IsEmptyStr(all_recps)) { - strcat(all_recps, ","); - } - strcat(all_recps, bcc); - } - if (!IsEmptyStr(all_recps)) { - valid = validate_recipients(all_recps, NULL, 0); - } - else { - valid = NULL; - } - free(all_recps); - - if ((valid != NULL) && (valid->num_room == 1)) - { - /* posting into an ML room? set the envelope from - * to the actual mail address so others get a valid - * reply-to-header. - */ - msg->cm_fields[eenVelopeTo] = strdup(valid->recp_orgroom); - } - - if (msg != NULL) { - msgnum = CtdlSubmitMsg(msg, valid, "", QP_EADDR); - if (do_confirm) { - cprintf("%ld\n", msgnum); - - if (StrLength(CCC->StatusMessage) > 0) { - cprintf("%s\n", ChrPtr(CCC->StatusMessage)); - } - else if (msgnum >= 0L) { - client_write(HKEY("Message accepted.\n")); - } - else { - client_write(HKEY("Internal error.\n")); - } - - if (!CM_IsEmpty(msg, eExclusiveID)) { - cprintf("%s\n", msg->cm_fields[eExclusiveID]); - } else { - cprintf("\n"); - } - cprintf("000\n"); - } - - CM_Free(msg); - } - if (valid != NULL) { - free_recipients(valid); - } - return; -} - - /* * API function to delete messages which match a set of criteria @@ -4354,163 +3737,6 @@ int CtdlDeleteMessages(char *room_name, /* which room */ return (num_deleted); } -/* - * Delete message from current room - */ -void cmd_dele(char *args) -{ - int num_deleted; - int i; - char msgset[SIZ]; - char msgtok[32]; - long *msgs; - int num_msgs = 0; - - extract_token(msgset, args, 0, '|', sizeof msgset); - num_msgs = num_tokens(msgset, ','); - if (num_msgs < 1) { - cprintf("%d Nothing to do.\n", CIT_OK); - return; - } - - if (CtdlDoIHavePermissionToDeleteMessagesFromThisRoom() == 0) { - cprintf("%d Higher access required.\n", - ERROR + HIGHER_ACCESS_REQUIRED); - return; - } - - /* - * Build our message set to be moved/copied - */ - msgs = malloc(num_msgs * sizeof(long)); - for (i=0; iroom.QRname, msgs, num_msgs, ""); - free(msgs); - - if (num_deleted) { - cprintf("%d %d message%s deleted.\n", CIT_OK, - num_deleted, ((num_deleted != 1) ? "s" : "")); - } else { - cprintf("%d Message not found.\n", ERROR + MESSAGE_NOT_FOUND); - } -} - - - - -/* - * move or copy a message to another room - */ -void cmd_move(char *args) -{ - char msgset[SIZ]; - char msgtok[32]; - long *msgs; - int num_msgs = 0; - - char targ[ROOMNAMELEN]; - struct ctdlroom qtemp; - int err; - int is_copy = 0; - int ra; - int permit = 0; - int i; - - extract_token(msgset, args, 0, '|', sizeof msgset); - num_msgs = num_tokens(msgset, ','); - if (num_msgs < 1) { - cprintf("%d Nothing to do.\n", CIT_OK); - return; - } - - extract_token(targ, args, 1, '|', sizeof targ); - convert_room_name_macros(targ, sizeof targ); - targ[ROOMNAMELEN - 1] = 0; - is_copy = extract_int(args, 2); - - if (CtdlGetRoom(&qtemp, targ) != 0) { - cprintf("%d '%s' does not exist.\n", ERROR + ROOM_NOT_FOUND, targ); - return; - } - - if (!strcasecmp(qtemp.QRname, CC->room.QRname)) { - cprintf("%d Source and target rooms are the same.\n", ERROR + ALREADY_EXISTS); - return; - } - - CtdlGetUser(&CC->user, CC->curr_user); - CtdlRoomAccess(&qtemp, &CC->user, &ra, NULL); - - /* Check for permission to perform this operation. - * Remember: "CC->room" is source, "qtemp" is target. - */ - permit = 0; - - /* Admins can move/copy */ - if (CC->user.axlevel >= AxAideU) permit = 1; - - /* Room aides can move/copy */ - if (CC->user.usernum == CC->room.QRroomaide) permit = 1; - - /* 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 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. */ - if ((CC->room.QRflags & QR_MAILBOX) && - (qtemp.QRflags & UA_POSTALLOWED)) permit = 1; - - /* User must have access to target room */ - if (!(ra & UA_KNOWN)) permit = 0; - - if (!permit) { - cprintf("%d Higher access required.\n", - ERROR + HIGHER_ACCESS_REQUIRED); - return; - } - - /* - * Build our message set to be moved/copied - */ - msgs = malloc(num_msgs * sizeof(long)); - for (i=0; iroom.QRname, msgs, num_msgs, ""); - } - free(msgs); - - cprintf("%d Message(s) %s.\n", CIT_OK, (is_copy ? "copied" : "moved") ); -} @@ -4882,18 +4108,6 @@ CTDL_MODULE_INIT(msgbase) { if (!threading) { CtdlRegisterDebugFlagHook(HKEY("messages"), SetMessageDebugEnabled, &MessageDebugEnabled); - - 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"); - CtdlRegisterProtoHook(cmd_dlat, "DLAT", "Download an attachment"); - CtdlRegisterProtoHook(cmd_ent0, "ENT0", "Enter a message"); - CtdlRegisterProtoHook(cmd_dele, "DELE", "Delete a message"); - CtdlRegisterProtoHook(cmd_move, "MOVE", "Move or copy a message to another room"); } /* return our Subversion id for the Log */ diff --git a/citadel/msgbase.h b/citadel/msgbase.h index 1d01a24e1..59ee421e0 100644 --- a/citadel/msgbase.h +++ b/citadel/msgbase.h @@ -59,27 +59,6 @@ struct repl { /* Info for replication checking */ }; -/* Data structure returned by validate_recipients() */ -struct recptypes { - int recptypes_magic; - int num_local; - int num_internet; - int num_ignet; - int num_room; - int num_error; - char *errormsg; - char *recp_local; - char *recp_internet; - char *recp_ignet; - char *recp_room; - char *recp_orgroom; - char *display_recp; - char *bounce_to; - char *envelope_from; - char *sending_room; -}; - -#define RECPTYPES_MAGIC 0xfeeb /* * This is a list of "harvested" email addresses that we might want to @@ -94,17 +73,8 @@ struct addresses_to_be_filed { extern struct addresses_to_be_filed *atbf; -void cmd_msgs (char *cmdbuf); - void memfmout (char *mptr, const char *nl); void output_mime_parts(char *); -void cmd_msg0 (char *cmdbuf); -void cmd_msg2 (char *cmdbuf); -void cmd_msg3 (char *cmdbuf); -void cmd_msg4 (char *cmdbuf); -void cmd_msgp (char *cmdbuf); -void cmd_opna (char *cmdbuf); -void cmd_dlat (char *cmdbuf); long send_message (struct CtdlMessage *); void loadtroom (void); long CtdlSubmitMsg(struct CtdlMessage *, struct recptypes *, const char *, int); @@ -131,9 +101,6 @@ void flood_protect_quickie_message(const char *from, long ioid, time_t NOW); -void cmd_ent0 (char *entargs); -void cmd_dele (char *delstr); -void cmd_move (char *args); void GetMetaData(struct MetaData *, long); void PutMetaData(struct MetaData *); void AdjRefCount(long, int); @@ -177,7 +144,7 @@ void CM_Free (struct CtdlMessage *msg); void CM_FreeContents (struct CtdlMessage *msg); int CM_IsValidMsg (struct CtdlMessage *msg); -void serialize_message(struct ser_ret *, struct CtdlMessage *); +void CtdlSerializeMessage(struct ser_ret *, struct CtdlMessage *); void ReplicationChecks(struct CtdlMessage *); int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newmsgs, int do_repl_check, struct CtdlMessage *supplied_msg, int suppress_refcount_adj); @@ -228,11 +195,6 @@ void CtdlSetSeen(long *target_msgnums, int num_target_msgnums, struct ctdluser *which_user, struct ctdlroom *which_room); void CtdlGetSeen(char *buf, int which_set); -struct recptypes *validate_recipients(const char *recipients, - const char *RemoteIdentifier, - int Flags); - -void free_recipients(struct recptypes *); struct CtdlMessage *CtdlMakeMessage( struct ctdluser *author, /* author's user structure */ diff --git a/citadel/netconfig.c b/citadel/netconfig.c index d1a7539ff..b673d389e 100644 --- a/citadel/netconfig.c +++ b/citadel/netconfig.c @@ -30,6 +30,7 @@ #include "include/ctdl_module.h" #include "serv_extensions.h" +#include "config.h" void vFreeRoomNetworkStruct(void *vOneRoomNetCfg); void FreeRoomNetworkStructContent(OneRoomNetCfg *OneRNCfg); diff --git a/citadel/scripts/mk_module_init.sh b/citadel/scripts/mk_module_init.sh index ee11a42b6..5f4505511 100755 --- a/citadel/scripts/mk_module_init.sh +++ b/citadel/scripts/mk_module_init.sh @@ -30,7 +30,7 @@ U_FILE="$CUR_DIR/modules_upgrade.c" /usr/bin/printf "Scanning extension modules for entry points.\n" -STATIC_FIRST_MODULES="citserver control modules euidindex file_ops msgbase room_ops user_ops nttlist database internet_addressing" +STATIC_FIRST_MODULES="citserver control modules euidindex file_ops msgbase ctdl_message room_ops user_ops nttlist database internet_addressing" DYNAMIC_MODULES=`grep CTDL_MODULE_INIT modules/*/*.c |$SED 's;.*(\(.*\));\1;'` if test -d user_modules; then USER_MODULES=`grep CTDL_MODULE_INIT user_modules/*/*.c |$SED 's;.*(\(.*\));\1;'` diff --git a/citadel/user_ops.c b/citadel/user_ops.c index 7c7e226a7..eb91dcdac 100644 --- a/citadel/user_ops.c +++ b/citadel/user_ops.c @@ -61,6 +61,7 @@ #include "context.h" #include "ctdl_module.h" #include "user_ops.h" +#include "internet_addressing.h" /* These pipes are used to talk to the chkpwd daemon, which is forked during startup */ int chkpwd_write_pipe[2]; -- 2.30.2