Removed traces after realizing that I was hitting config.c_maxmsglen and not an actua...
[citadel.git] / citadel / modules / inboxrules / serv_inboxrules.c
index a381d4e17c696f32fa19c888f94bf1af3709ab52..a1a5f7c9bff25166ef7c08486d276238111f23e1 100644 (file)
@@ -1,16 +1,14 @@
-/*
- * Inbox handling rules
- *
- * Copyright (c) 1987-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.
- */
+// Inbox handling rules
+//
+// Copyright (c) 1987-2022 by the citadel.org team
+//
+// This program is open source software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 3.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
 
 #include "sysdep.h"
 #include <stdlib.h>
 #include <pwd.h>
 #include <errno.h>
 #include <sys/types.h>
-
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-#  include <sys/time.h>
-# else
-#  include <time.h>
-# endif
-#endif
-
+#include <time.h>
 #include <sys/wait.h>
 #include <string.h>
 #include <limits.h>
@@ -48,9 +35,7 @@
 #include "ctdl_module.h"
 
 
-/*
- * The next sections are enums and keys that drive the serialize/deserialize functions for the inbox rules/state configuration.
- */
+// The next sections are enums and keys that drive the serialize/deserialize functions for the inbox rules/state configuration.
 
 // Fields to be compared
 enum {
@@ -181,7 +166,7 @@ struct inboxrules *deserialize_inbox_rules(char *serialized_rules) {
                return NULL;
        }
 
-       /* Make a copy of the supplied buffer because we're going to shit all over it with strtok_r() */
+       // Make a copy of the supplied buffer because we're going to shit all over it with strtok_r()
        char *sr = strdup(serialized_rules);
        if (!sr) {
                return NULL;
@@ -198,8 +183,8 @@ struct inboxrules *deserialize_inbox_rules(char *serialized_rules) {
        while ((token = strtok_r(rest, "\n", &rest))) {
 
                // For backwards compatibility, "# WEBCIT_RULE" is an alias for "rule".
-               // Prior to version 930, WebCit converted its rules to Sieve scripts, but saved the rules as comments for later re-editing.
-               // Now, the rules hidden in the comments become the real rules.
+               // Prior to version 930, WebCit converted its rules to Sieve scripts, but saved the rules as comments for
+               // later re-editing.  Now, the rules hidden in the comments become the real rules.
                if (!strncasecmp(token, "# WEBCIT_RULE|", 14)) {
                        strcpy(token, "rule|"); 
                        strcpy(&token[5], &token[14]);
@@ -218,7 +203,8 @@ struct inboxrules *deserialize_inbox_rules(char *serialized_rules) {
                        // We have a rule , now parse it
                        char rtoken[SIZ];
                        int nt = num_tokens(decoded_rule, '|');
-                       for (int t=0; t<nt; ++t) {
+                       int t = 0;
+                       for (t=0; t<nt; ++t) {
                                extract_token(rtoken, decoded_rule, t, '|', sizeof(rtoken));
                                striplt(rtoken);
                                switch(t) {
@@ -355,7 +341,7 @@ int inbox_do_redirect(struct irule *rule, long msgnum) {
                return(1);                                      // don't delete the inbox copy if this failed
        }
 
-       recptypes *valid = validate_recipients(rule->redirect_to, NULL, 0);
+       struct recptypes *valid = validate_recipients(rule->redirect_to, NULL, 0);
        if (valid == NULL) {
                syslog(LOG_WARNING, "inboxrules: inbox_do_redirect() invalid recipient <%s>", rule->redirect_to);
                return(1);                                      // don't delete the inbox copy if this failed
@@ -373,16 +359,14 @@ int inbox_do_redirect(struct irule *rule, long msgnum) {
                return(1);                                      // don't delete the inbox copy if this failed
        }
 
-       CtdlSubmitMsg(msg, valid, NULL, 0);                     // send the message to the new recipient
+       CtdlSubmitMsg(msg, valid, NULL);                        // send the message to the new recipient
        free_recipients(valid);
        CM_Free(msg);
        return(0);                                              // delete the inbox copy
 }
 
 
-/*
- * Perform the "reject" action (delete the message, and tell the sender we deleted it)
- */
+// Perform the "reject" action (delete the message, and tell the sender we deleted it)
 void inbox_do_reject(struct irule *rule, struct CtdlMessage *msg) {
        syslog(LOG_DEBUG, "inbox_do_reject: sender: <%s>, reject", msg->cm_fields[erFc822Addr]);
 
@@ -417,10 +401,10 @@ void inbox_do_reject(struct irule *rule, struct CtdlMessage *msg) {
 
        // Deliver the message
        quickie_message(
-               NULL,
+               " ",
                msg->cm_fields[eenVelopeTo],
                sender,
-               NULL,
+               MAILROOM,
                reject_text,
                FMT_RFC822,
                "Delivery status notification"
@@ -429,9 +413,7 @@ void inbox_do_reject(struct irule *rule, struct CtdlMessage *msg) {
 }
 
 
-/*
- * Perform the "vacation" action (send an automatic response)
- */
+// Perform the "vacation" action (send an automatic response)
 void inbox_do_vacation(struct irule *rule, struct CtdlMessage *msg) {
        syslog(LOG_DEBUG, "inbox_do_vacation: sender: <%s>, vacation", msg->cm_fields[erFc822Addr]);
 
@@ -476,10 +458,10 @@ void inbox_do_vacation(struct irule *rule, struct CtdlMessage *msg) {
        
                // Deliver the auto-reply.
                quickie_message(
-                       NULL,
+                       "",
                        msg->cm_fields[eenVelopeTo],
                        sender,
-                       NULL,
+                       MAILROOM,
                        ChrPtr(reject_text),
                        FMT_RFC822,
                        "Delivery status notification"
@@ -836,11 +818,13 @@ int num_urip_alloc = 0;
  * Perform inbox processing for all rooms which require it
  */
 void perform_inbox_processing(void) {
+       int i = 0;
+
        if (num_urip == 0) {
                return;                                                                                 // no action required
        }
 
-       for (int i=0; i<num_urip; ++i) {
+       for (i=0; i<num_urip; ++i) {
                do_inbox_processing_for_user(users_requiring_inbox_processing[i]);
        }
 
@@ -856,6 +840,7 @@ void perform_inbox_processing(void) {
  * If it's someone's inbox, we have to check for inbox rules
  */
 int serv_inboxrules_roomhook(struct ctdlroom *room) {
+       int i = 0;
 
        // Is this someone's inbox?
        if (!strcasecmp(&room->QRname[11], MAILROOM)) {
@@ -864,7 +849,7 @@ int serv_inboxrules_roomhook(struct ctdlroom *room) {
 
                        // first check to see if this user is already on the list
                        if (num_urip > 0) {
-                               for (int i=0; i<=num_urip; ++i) {
+                               for (i=0; i<=num_urip; ++i) {
                                        if (users_requiring_inbox_processing[i] == usernum) {           // already on the list!
                                                return(0);
                                        }