validate_recipients() remove extra copy of recipients
authorArt Cancro <ajc@citadel.org>
Wed, 27 Mar 2024 15:47:55 +0000 (08:47 -0700)
committerArt Cancro <ajc@citadel.org>
Wed, 27 Mar 2024 15:47:55 +0000 (08:47 -0700)
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
citadel/server/modules/imap/imap_fetch.c
citadel/server/modules/imap/imap_search.c
citadel/server/modules/smtp/smtp_util.c
citadel/server/msgbase.c

index f9bd07309c38e8b1e171d08f6fcbda27e3a4839a..0bc7507043ca955a99fbfe271a076cf35e294641 100644 (file)
@@ -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 <stdlib.h>
@@ -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);
        }
index 42dc3d7cab15b676163a76b056113922c8e30f5a..75e49e8e764938d4f672795c166a661d410c7b55 100644 (file)
@@ -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<num_sets; ++s) {
-               extract_token(setstr, actual_range, s, ',', sizeof setstr);
+               extract_token(setstr, range, s, ',', sizeof setstr);
 
                extract_token(lostr, setstr, 0, ':', sizeof lostr);
                if (num_tokens(setstr, ':') >= 2) {
index c3b3b7ae741644e6e5738d51443c4b4849eec3f4..1ea13ad3e024243fc1dae7b4da369ee68bff4eff 100644 (file)
@@ -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"
  * 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;
index e025db9ddb5514f7d8f6f0000b7a7f09176c4c1b..29534ab69ca53fe312a976341bbfaafa04dd3ea8 100644 (file)
@@ -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);
index f3188bcbd66dedf1c920da97c37e97f33ffcd884..fb3f74ae791b6cf99b50fe2cebb4783512f6fbc2 100644 (file)
@@ -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<num_msgs_to_be_merged; ++i) {
                        msgid = msgs_to_be_merged[i];
        
-                       if (supplied_msg != NULL) {
-                               msg = supplied_msg;
+                       if (msg_in != NULL) {
+                               msg = msg_in;
                        }
                        else {
                                msg = CtdlFetchMessage(msgid, 0);
@@ -2233,7 +2233,7 @@ int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newms
                                }
 
                                // Free up the memory we may have allocated
-                               if (msg != supplied_msg) {
+                               if (msg != msg_in) {
                                        CM_Free(msg);
                                }
                        }
@@ -2270,8 +2270,8 @@ int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newms
 
 
 // This is the same as CtdlSaveMsgPointersInRoom() but it only accepts a single message.
-int CtdlSaveMsgPointerInRoom(char *roomname, long msgid, int do_repl_check, struct CtdlMessage *supplied_msg) {
-       return CtdlSaveMsgPointersInRoom(roomname, &msgid, 1, do_repl_check, supplied_msg, 0);
+int CtdlSaveMsgPointerInRoom(char *roomname, long msgid, int do_repl_check, struct CtdlMessage *msg_in) {
+       return CtdlSaveMsgPointersInRoom(roomname, &msgid, 1, do_repl_check, msg_in, 0);
 }
 
 
@@ -2883,7 +2883,7 @@ struct CtdlMessage *CtdlMakeMessage(
         char *fake_name,                // who we're masquerading as
        char *my_email,                 // which of my email addresses to use (empty is ok)
         char *subject,                  // Subject (optional)
-       char *supplied_euid,            // ...or NULL if this is irrelevant
+       char *euid_in,          // ...or NULL if this is irrelevant
         char *preformatted_text,        // ...or NULL to read text from client
        char *references                // Thread references
 ) {
@@ -2903,8 +2903,8 @@ struct CtdlMessage *CtdlMakeMessage(
                (my_email)?strlen(my_email): 0,
                subject,                                // Subject (optional)
                (subject)?strlen(subject): 0,
-               supplied_euid,                          // ...or NULL if this is irrelevant
-               (supplied_euid)?strlen(supplied_euid):0,
+               euid_in,                                // ...or NULL if this is irrelevant
+               (euid_in)?strlen(euid_in):0,
                preformatted_text,                      // ...or NULL to read text from client
                (preformatted_text)?strlen(preformatted_text) : 0,
                references,                             // Thread references
@@ -2934,7 +2934,7 @@ struct CtdlMessage *CtdlMakeMessageLen(
        long myelen,
        char *subject,                  // Subject (optional)
        long subjlen,
-       char *supplied_euid,            // ...or NULL if this is irrelevant
+       char *euid_in,          // ...or NULL if this is irrelevant
        long euidlen,
        char *preformatted_text,        // ...or NULL to read text from client
        long textlen,
@@ -3025,7 +3025,7 @@ struct CtdlMessage *CtdlMakeMessageLen(
        }
 
        if (euidlen > 0) {
-               CM_SetField(msg, eExclusiveID, supplied_euid);
+               CM_SetField(msg, eExclusiveID, euid_in);
        }
 
        if (reflen > 0) {