From 724bf4e35d6067c6646430953d685931b5f16b0c Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Wed, 27 Mar 2024 08:47:55 -0700 Subject: [PATCH] validate_recipients() remove extra copy of recipients We no longer need to copy recipients_in to recipients, because we no longer destructively tokenize it. Now we non-destructively tokenize it into an array. Also I discovered that there is an unused parameter in that call. Removed it and the one place where it was being non-functionally called. --- citadel/server/internet_addressing.c | 18 ++++------------ citadel/server/modules/imap/imap_fetch.c | 14 ++++++------ citadel/server/modules/imap/imap_search.c | 24 +++++++-------------- citadel/server/modules/smtp/smtp_util.c | 16 ++------------ citadel/server/msgbase.c | 26 +++++++++++------------ 5 files changed, 34 insertions(+), 64 deletions(-) diff --git a/citadel/server/internet_addressing.c b/citadel/server/internet_addressing.c index f9bd07309..0bc750704 100644 --- a/citadel/server/internet_addressing.c +++ b/citadel/server/internet_addressing.c @@ -3,8 +3,7 @@ // // Copyright (c) 1987-2024 by the citadel.org team // -// This program is open source software. Use, duplication, or disclosure -// is subject to the terms of the GNU General Public License, version 3. +// This program is open source software. Use, duplication, or disclosure is subject to the GNU General Public License version 3. #include "sysdep.h" #include @@ -296,9 +295,8 @@ Array *split_recps(char *addresses, Array *append_to) { // // Caller needs to free the result using free_recipients() // -struct recptypes *validate_recipients(char *supplied_recipients, const char *RemoteIdentifier, int Flags) { +struct recptypes *validate_recipients(char *recipients_in, const char *REMOVE_THIS_UNUSED_VARIABLE, int Flags) { struct recptypes *ret; - char *recipients = NULL; char append[SIZ]; long len; int mailtype; @@ -314,14 +312,7 @@ struct recptypes *validate_recipients(char *supplied_recipients, const char *Rem if (ret == NULL) return(NULL); memset(ret, 0, sizeof(struct recptypes)); // set all values to null/zero - if (supplied_recipients == NULL) { - recipients = strdup(""); - } - else { - recipients = strdup(supplied_recipients); - } - - len = strlen(recipients) + 1024; // allocate memory + len = strlen(recipients_in) + 1024; // allocate memory ret->errormsg = malloc(len); ret->recp_local = malloc(len); ret->recp_internet = malloc(len); @@ -337,7 +328,7 @@ struct recptypes *validate_recipients(char *supplied_recipients, const char *Rem ret->display_recp[0] = 0; ret->recptypes_magic = RECPTYPES_MAGIC; - Array *recp_array = split_recps(supplied_recipients, NULL); + Array *recp_array = split_recps(recipients_in, NULL); char *aliases = CtdlGetSysConfig(GLOBAL_ALIASES); // First hit the Global Alias Table @@ -509,7 +500,6 @@ struct recptypes *validate_recipients(char *supplied_recipients, const char *Rem ret->num_local, ret->num_room, ret->num_internet, ret->num_error ); - free(recipients); if (recp_array) { array_free(recp_array); } diff --git a/citadel/server/modules/imap/imap_fetch.c b/citadel/server/modules/imap/imap_fetch.c index 42dc3d7ca..75e49e8e7 100644 --- a/citadel/server/modules/imap/imap_fetch.c +++ b/citadel/server/modules/imap/imap_fetch.c @@ -1201,21 +1201,21 @@ int imap_extract_data_items(citimap_command *Cmd) { // message included in the specified range. // // Set is_uid to 1 to fetch by UID instead of sequence number. -void imap_pick_range(const char *supplied_range, int is_uid) { +void imap_pick_range(const char *range_in, int is_uid) { citimap *Imap = IMAP; int i; int num_sets; int s; char setstr[SIZ], lostr[SIZ], histr[SIZ]; long lo, hi; - char actual_range[SIZ]; + char range[SIZ]; // Handle the "ALL" macro - if (!strcasecmp(supplied_range, "ALL")) { - safestrncpy(actual_range, "1:*", sizeof actual_range); + if (!strcasecmp(range_in, "ALL")) { + safestrncpy(range, "1:*", sizeof range); } else { - safestrncpy(actual_range, supplied_range, sizeof actual_range); + safestrncpy(range, range_in, sizeof range); } // Clear out the IMAP_SELECTED flags for all messages. @@ -1224,9 +1224,9 @@ void imap_pick_range(const char *supplied_range, int is_uid) { } // Now set it for all specified messages. - num_sets = num_tokens(actual_range, ','); + num_sets = num_tokens(range, ','); for (s=0; s= 2) { diff --git a/citadel/server/modules/imap/imap_search.c b/citadel/server/modules/imap/imap_search.c index c3b3b7ae7..1ea13ad3e 100644 --- a/citadel/server/modules/imap/imap_search.c +++ b/citadel/server/modules/imap/imap_search.c @@ -1,16 +1,8 @@ -/* - * Implements IMAP's gratuitously complex SEARCH command. - * - * Copyright (c) 2001-2020 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. - */ +// Implements IMAP's gratuitously complex SEARCH command. +// +// Copyright (c) 2001-2024 by the citadel.org team +// +// This program is open source software. Use, duplication, or disclosure is subject to the GNU General Public License v3. #include "../../ctdl_module.h" #include "../../sysdep.h" @@ -51,11 +43,11 @@ * message after it has been fetched from the disk. This function returns * nonzero if there is a match. * - * supplied_msg MAY be used to pass a pointer to the message in memory, + * msg_in MAY be used to pass a pointer to the message in memory, * if for some reason it's already been loaded. If not, the message will * be loaded only if one or more search criteria require it. */ -int imap_do_search_msg(int seq, struct CtdlMessage *supplied_msg, +int imap_do_search_msg(int seq, struct CtdlMessage *msg_in, int num_items, ConstStr *itemlist, int is_uid) { citimap *Imap = IMAP; @@ -71,7 +63,7 @@ int imap_do_search_msg(int seq, struct CtdlMessage *supplied_msg, if (num_items == 0) { return(0); } - msg = supplied_msg; + msg = msg_in; /* Initially we start at the beginning. */ pos = 0; diff --git a/citadel/server/modules/smtp/smtp_util.c b/citadel/server/modules/smtp/smtp_util.c index e025db9dd..29534ab69 100644 --- a/citadel/server/modules/smtp/smtp_util.c +++ b/citadel/server/modules/smtp/smtp_util.c @@ -53,8 +53,9 @@ const char *smtp_get_Recipients(void) { struct citsmtp *sSMTP = SMTP; - if (sSMTP == NULL) + if (sSMTP == NULL) { return NULL; + } else return ChrPtr(sSMTP->from); } @@ -82,7 +83,6 @@ void smtp_do_bounce(const char *instr, int is_final) { int num_bounces = 0; int bounce_this = 0; struct CtdlMessage *bmsg = NULL; - struct recptypes *valid; int successful_bounce = 0; static int seq = 0; StrBuf *BounceMB; @@ -225,24 +225,12 @@ void smtp_do_bounce(const char *instr, int is_final) { else { syslog(LOG_DEBUG, "bounce to user <%s>", bounceto); } - /* Can we deliver the bounce to the original sender? */ - valid = validate_recipients(bounceto, smtp_get_Recipients (), 0); - if (valid != NULL) { - if (valid->num_error == 0) { - CtdlSubmitMsg(bmsg, valid, ""); - successful_bounce = 1; - } - } /* If not, post it in the Aide> room */ if (successful_bounce == 0) { CtdlSubmitMsg(bmsg, NULL, CtdlGetConfigStr("c_aideroom")); } - /* Free up the memory we used */ - if (valid != NULL) { - free_recipients(valid); - } } FreeStrBuf(&boundary); CM_Free(bmsg); diff --git a/citadel/server/msgbase.c b/citadel/server/msgbase.c index f3188bcbd..fb3f74ae7 100644 --- a/citadel/server/msgbase.c +++ b/citadel/server/msgbase.c @@ -2122,14 +2122,14 @@ DONE: // now we're done // (Returns 0 for success, nonzero for failure) // roomname may be NULL to use the current room // -// Note that the 'supplied_msg' field may be set to NULL, in which case +// Note that the 'msg_in' field may be set to NULL, in which case // the message will be fetched from disk, by number, if we need to perform // replication checks. This adds an additional database read, so if the // caller already has the message in memory then it should be supplied. (Obviously // this mode of operation only works if we're saving a single message.) // int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newmsgs, - int do_repl_check, struct CtdlMessage *supplied_msg, int suppress_refcount_adj + int do_repl_check, struct CtdlMessage *msg_in, int suppress_refcount_adj ) { int i, j, unique; char hold_rm[ROOMNAMELEN]; @@ -2154,7 +2154,7 @@ int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newms // Sanity checks if (newmsgidlist == NULL) return(ERROR + INTERNAL_ERROR); if (num_newmsgs < 1) return(ERROR + INTERNAL_ERROR); - if (num_newmsgs > 1) supplied_msg = NULL; + if (num_newmsgs > 1) msg_in = NULL; // Now the regular stuff if (CtdlGetRoomLock(&CC->room, ((roomname != NULL) ? roomname : CC->room.QRname) ) != 0) { @@ -2217,8 +2217,8 @@ int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newms for (i=0; i 0) { - CM_SetField(msg, eExclusiveID, supplied_euid); + CM_SetField(msg, eExclusiveID, euid_in); } if (reflen > 0) { -- 2.30.2