validate_recipients() - completed removal of unused param
[citadel.git] / citadel / server / modules / ctdlproto / serv_messages.c
index 4036c9e0a3331ee782caa9d3ea72ba4236c7f4c2..2c3b4371eef2230e470772ed5267ee01c0f26616 100644 (file)
@@ -1,14 +1,9 @@
 // Message-related protocol commands for Citadel clients
 //
-// Copyright (c) 1987-2022 by the citadel.org team
+// Copyright (c) 1987-2024 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.
+// This program is open source software.  Use, duplication, or disclosure
+// is subject to the terms of the GNU General Public License version 3.
 
 #include <stdio.h>
 #include <libcitadel.h>
@@ -31,7 +26,7 @@ void simple_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;
+       int output_mode = *(int *)userdata;
 
        msg = CtdlFetchMessage(msgnum, 0);
        if (msg == NULL) {
@@ -154,7 +149,7 @@ void cmd_msgs(char *cmdbuf) {
        int cm_ref = 0;
        int with_template = 0;
        struct CtdlMessage *template = NULL;
-        msg_filter filt;
+       msg_filter filt;
        char search_string[1024];
        ForEachMsgCallback CallBack;
 
@@ -210,10 +205,8 @@ void cmd_msgs(char *cmdbuf) {
        if (with_template == 1) {
                memset(buf, 0, 5);
                unbuffer_output();
-               cprintf("%d Send template then receive message list\n",
-                       START_CHAT_MODE);
-               template = (struct CtdlMessage *)
-                       malloc(sizeof(struct CtdlMessage));
+               cprintf("%d Send template then receive message list\n", SEND_THEN_RECV);
+               template = (struct CtdlMessage *) malloc(sizeof(struct CtdlMessage));
                memset(template, 0, sizeof(struct CtdlMessage));
                template->cm_magic = CTDLMESSAGE_MAGIC;
                template->cm_anon_type = MES_NORMAL;
@@ -223,11 +216,10 @@ void cmd_msgs(char *cmdbuf) {
                        long tValueLen;
 
                        tValueLen = extract_token(tfield, buf, 0, '|', sizeof tfield);
-                       if ((tValueLen == 4) && GetFieldFromMnemonic(&f, tfield))
-                       {
+                       if ((tValueLen == 4) && GetFieldFromMnemonic(&f, tfield)) {
                                tValueLen = extract_token(tvalue, buf, 1, '|', sizeof tvalue);
                                if (tValueLen >= 0) {
-                                       CM_SetField(template, f, tvalue, tValueLen);
+                                       CM_SetField(template, f, tvalue);
                                }
                        }
                }
@@ -236,15 +228,13 @@ void cmd_msgs(char *cmdbuf) {
        else if (with_template == 2) {
                long i = 0;
                memset(buf, 0, 5);
-               cprintf("%d Send list of headers\n",
-                       START_CHAT_MODE);
+               cprintf("%d Send list of headers\n", SEND_THEN_RECV);
                filt.Filter = NewHash(1, lFlathash);
                filt.buffer = NewStrBufPlain(NULL, 1024);
                while(client_getln(buf, sizeof buf) >= 0 && strcmp(buf,"000")) {
                        eMsgField f;
        
-                       if (GetFieldFromMnemonic(&f, buf))
-                       {
+                       if (GetFieldFromMnemonic(&f, buf)) {
                                Put(filt.Filter, LKEY(i), (void*)f, reference_free_handler);
                                i++;
                        }
@@ -258,22 +248,24 @@ void cmd_msgs(char *cmdbuf) {
 
        if (with_template < 2) {
                CtdlForEachMessage(mode,
-                                  ( (mode == MSGS_SEARCH) ? 0 : cm_ref ),
-                                  ( (mode == MSGS_SEARCH) ? search_string : NULL ),
-                                  NULL,
-                                  template,
-                                  CallBack,
-                                  &output_mode);
+                       ( (mode == MSGS_SEARCH) ? 0 : cm_ref ),
+                       ( (mode == MSGS_SEARCH) ? search_string : NULL ),
+                       NULL,
+                       template,
+                       CallBack,
+                       &output_mode
+               );
                if (template != NULL) CM_Free(template);
        }
        else {
                CtdlForEachMessage(mode,
-                                  ( (mode == MSGS_SEARCH) ? 0 : cm_ref ),
-                                  ( (mode == MSGS_SEARCH) ? search_string : NULL ),
-                                  NULL,
-                                  NULL,
-                                  CallBack,
-                                  &filt);
+                       ( (mode == MSGS_SEARCH) ? 0 : cm_ref ),
+                       ( (mode == MSGS_SEARCH) ? search_string : NULL ),
+                       NULL,
+                       NULL,
+                       CallBack,
+                       &filt
+               );
                DeleteHashPos(&filt.p);
                DeleteHash(&filt.Filter);
                FreeStrBuf(&filt.buffer);
@@ -283,11 +275,8 @@ void cmd_msgs(char *cmdbuf) {
 }
 
 
-/*
- * display a message (mode 0 - Citadel proprietary)
- */
-void cmd_msg0(char *cmdbuf)
-{
+// display a message (mode 0 - Citadel proprietary)
+void cmd_msg0(char *cmdbuf) {
        long msgid;
        int headers_only = HEADERS_ALL;
 
@@ -342,8 +331,7 @@ void cmd_opna(char *cmdbuf) {
 
        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_DOWNLOAD, 0, 1, 1, NULL, 0, NULL, NULL, NULL);
 }                      
 
@@ -415,7 +403,7 @@ void cmd_ent0(char *entargs) {
                if (*ptr == '!') *ptr = '|';
        }
 
-       /* first check to make sure the request is valid. */
+       // first check to make sure the request is valid.
 
        err = CtdlDoIHavePermissionToPostInThisRoom(
                errmsg,
@@ -428,14 +416,14 @@ void cmd_ent0(char *entargs) {
                return;
        }
 
-       /* Check some other permission type things. */
+       // Check some other permission type things.
 
        if (IsEmptyStr(newusername)) {
                strcpy(newusername, CC->user.fullname);
        }
-       if (  (CC->user.axlevel < AxAideU)
-             && (strcasecmp(newusername, CC->user.fullname))
-             && (strcasecmp(newusername, CC->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,
@@ -467,7 +455,7 @@ void cmd_ent0(char *entargs) {
                cprintf("%d You don't have permission to author messages as '%s'.\n",
                        ERROR + HIGHER_ACCESS_REQUIRED,
                        newuseremail
-                       );
+               );
                return;
        }
 
@@ -488,14 +476,14 @@ void cmd_ent0(char *entargs) {
                        strcpy(bcc, "");
                }
 
-               valid_to = validate_recipients(recp, NULL, 0);
+               valid_to = validate_recipients(recp, 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);
+               valid_cc = validate_recipients(cc, 0);
                if (valid_cc->num_error > 0) {
                        cprintf("%d %s\n", ERROR + NO_SUCH_USER, valid_cc->errormsg);
                        free_recipients(valid_to);
@@ -503,7 +491,7 @@ void cmd_ent0(char *entargs) {
                        return;
                }
 
-               valid_bcc = validate_recipients(bcc, NULL, 0);
+               valid_bcc = validate_recipients(bcc, 0);
                if (valid_bcc->num_error > 0) {
                        cprintf("%d %s\n", ERROR + NO_SUCH_USER, valid_bcc->errormsg);
                        free_recipients(valid_to);
@@ -523,8 +511,7 @@ void cmd_ent0(char *entargs) {
 
                if (valid_to->num_internet + valid_cc->num_internet + valid_bcc->num_internet > 0) {
                        if (CtdlCheckInternetMailPermission(&CC->user)==0) {
-                               cprintf("%d You do not have permission "
-                                       "to send Internet mail.\n",
+                               cprintf("%d You do not have permission to send Internet mail.\n",
                                        ERROR + HIGHER_ACCESS_REQUIRED);
                                free_recipients(valid_to);
                                free_recipients(valid_cc);
@@ -541,12 +528,12 @@ void cmd_ent0(char *entargs) {
                        return;
                }
        
-               if ((RESTRICT_INTERNET == 1)
-                   && (valid_to->num_internet + valid_cc->num_internet + valid_bcc->num_internet > 0)
-                   && ((CC->user.flags & US_INTERNET) == 0)
-                   && (!CC->internal_pgm)) {
-                       cprintf("%d You don't have access to Internet mail.\n",
-                               ERROR + HIGHER_ACCESS_REQUIRED);
+               if (    (RESTRICT_INTERNET == 1)
+                       && (valid_to->num_internet + valid_cc->num_internet + valid_bcc->num_internet > 0)
+                       && ((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);
                        free_recipients(valid_cc);
                        free_recipients(valid_bcc);
@@ -597,17 +584,19 @@ void cmd_ent0(char *entargs) {
 
        // Read in the message from the client.
        if (do_confirm) {
-               cprintf("%d send message\n", START_CHAT_MODE);
+               cprintf("%d send message\n", SEND_THEN_RECV);
        }
        else {
                cprintf("%d send message\n", SEND_LISTING);
        }
 
-       msg = CtdlMakeMessage(&CC->user, recp, cc,
-                             CC->room.QRname, anonymous, format_type,
-                             newusername, newuseremail, subject,
-                             ((!IsEmptyStr(supplied_euid)) ? supplied_euid : NULL),
-                             NULL, references);
+       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.
        char *all_recps = malloc(SIZ * 3);
@@ -625,7 +614,7 @@ void cmd_ent0(char *entargs) {
                strcat(all_recps, bcc);
        }
        if (!IsEmptyStr(all_recps)) {
-               valid = validate_recipients(all_recps, NULL, 0);
+               valid = validate_recipients(all_recps, 0);
        }
        else {
                valid = NULL;
@@ -635,7 +624,7 @@ void cmd_ent0(char *entargs) {
        // 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));
+               CM_SetField(msg, eenVelopeTo, valid->recp_orgroom);
        }
 
        if (msg != NULL) {
@@ -655,7 +644,8 @@ void cmd_ent0(char *entargs) {
 
                        if (!CM_IsEmpty(msg, eExclusiveID)) {
                                cprintf("%s\n", msg->cm_fields[eExclusiveID]);
-                       } else {
+                       }
+                       else {
                                cprintf("\n");
                        }
                        cprintf("000\n");
@@ -687,8 +677,7 @@ void cmd_dele(char *args) {
        }
 
        if (CtdlDoIHavePermissionToDeleteMessagesFromThisRoom() == 0) {
-               cprintf("%d Higher access required.\n",
-                       ERROR + HIGHER_ACCESS_REQUIRED);
+               cprintf("%d Higher access required.\n", ERROR + HIGHER_ACCESS_REQUIRED);
                return;
        }
 
@@ -703,9 +692,9 @@ void cmd_dele(char *args) {
        free(msgs);
 
        if (num_deleted) {
-               cprintf("%d %d message%s deleted.\n", CIT_OK,
-                       num_deleted, ((num_deleted != 1) ? "s" : ""));
-       else {
+               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);
        }
 }
@@ -762,8 +751,11 @@ void cmd_move(char *args) {
        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;
+       if (    (CC->room.QRflags & QR_MAILBOX)
+               && (qtemp.QRflags & QR_MAILBOX)
+       ) {
+               permit = 1;
+       }
 
        // Permit only copy from public to personal room
        if (    (is_copy)
@@ -777,15 +769,19 @@ void cmd_move(char *args) {
        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;
+       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 (!(ra & UA_KNOWN)) {
+               permit = 0;
+       }
 
        if (!permit) {
-               cprintf("%d Higher access required.\n",
-                       ERROR + HIGHER_ACCESS_REQUIRED);
+               cprintf("%d Higher access required.\n", ERROR + HIGHER_ACCESS_REQUIRED);
                return;
        }
 
@@ -799,8 +795,7 @@ void cmd_move(char *args) {
        // Do the copy
        err = CtdlSaveMsgPointersInRoom(targ, msgs, num_msgs, 1, NULL, 0);
        if (err != 0) {
-               cprintf("%d Cannot store message(s) in %s: error %d\n",
-                       err, targ, err);
+               cprintf("%d Cannot store message(s) in %s: error %d\n", err, targ, err);
                free(msgs);
                return;
        }
@@ -815,9 +810,7 @@ void cmd_move(char *args) {
 }
 
 
-/*****************************************************************************/
-/*                      MODULE INITIALIZATION STUFF                          */
-/*****************************************************************************/
+// Initialization function, called from modules_init.c
 char *ctdl_module_init_ctdl_message(void) {
        if (!threading) {
                CtdlRegisterProtoHook(cmd_msgs, "MSGS", "Output a list of messages in the current room");
@@ -832,6 +825,6 @@ char *ctdl_module_init_ctdl_message(void) {
                CtdlRegisterProtoHook(cmd_move, "MOVE", "Move or copy a message to another room");
        }
 
-        /* return our Subversion id for the Log */
+       // return a module name for the log
        return "ctdl_message";
 }