#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>
// 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) {
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
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
// Deliver the message
quickie_message(
- NULL,
+ " ",
msg->cm_fields[eenVelopeTo],
sender,
- NULL,
+ MAILROOM,
reject_text,
FMT_RFC822,
"Delivery status notification"
// Deliver the auto-reply.
quickie_message(
- NULL,
+ "",
msg->cm_fields[eenVelopeTo],
sender,
- NULL,
+ MAILROOM,
ChrPtr(reject_text),
FMT_RFC822,
"Delivery status notification"
struct MetaData smi; // If we are loading the metadata to compare, put it here.
int rule_activated = 0; // On each rule, this is set if the compare succeeds and the rule activates.
char compare_me[SIZ]; // On each rule, we will store the field to be compared here.
+ int compare_compound = 0; // Set to 1 when we are comparing both display name and email address
int keep_message = 1; // Nonzero to keep the message in the inbox after processing, 0 to delete it.
int i;
// If the rule involves a field comparison, load the field to be compared.
compare_me[0] = 0;
+ compare_compound = 0;
switch(ii->rules[i].compared_field) {
-
case field_from: // From:
- if (!IsEmptyStr(msg->cm_fields[erFc822Addr])) {
+ if ( (!IsEmptyStr(msg->cm_fields[erFc822Addr])) && (!IsEmptyStr(msg->cm_fields[erFc822Addr])) ) {
+ snprintf(compare_me, sizeof compare_me, "%s|%s",
+ msg->cm_fields[eAuthor],
+ msg->cm_fields[erFc822Addr]
+ );
+ compare_compound = 1; // there will be two fields to compare "name|address"
+ }
+ else if (!IsEmptyStr(msg->cm_fields[erFc822Addr])) {
safestrncpy(compare_me, msg->cm_fields[erFc822Addr], sizeof compare_me);
}
+ else if (!IsEmptyStr(msg->cm_fields[eAuthor])) {
+ safestrncpy(compare_me, msg->cm_fields[eAuthor], sizeof compare_me);
+ }
break;
case field_tocc: // To: or Cc:
if (!IsEmptyStr(msg->cm_fields[eRecipient])) {
// For all of the above fields, we can compare the field we've loaded into the buffer.
syslog(LOG_DEBUG, "Value of field to compare is: <%s>", compare_me);
+ int substring_match = (bmstrcasestr(compare_me, ii->rules[i].compared_value) ? 1 : 0);
+ int exact_match = 0;
+ if (compare_compound) {
+ char *sep = strchr(compare_me, '|');
+ if (sep) {
+ *sep = 0;
+ exact_match =
+ (strcasecmp(compare_me, ii->rules[i].compared_value) ? 0 : 1)
+ + (strcasecmp(++sep, ii->rules[i].compared_value) ? 0 : 1)
+ ;
+ }
+ }
+ else {
+ exact_match = (strcasecmp(compare_me, ii->rules[i].compared_value) ? 0 : 1);
+ }
+ syslog(LOG_DEBUG, "substring match: %d", substring_match);
+ syslog(LOG_DEBUG, "exact match: %d", exact_match);
switch(ii->rules[i].field_compare_op) {
case fcomp_contains:
case fcomp_matches:
- rule_activated = (bmstrcasestr(compare_me, ii->rules[i].compared_value) ? 1 : 0);
+ rule_activated = substring_match;
break;
case fcomp_notcontains:
case fcomp_notmatches:
- rule_activated = (bmstrcasestr(compare_me, ii->rules[i].compared_value) ? 0 : 1);
+ rule_activated = !substring_match;
break;
case fcomp_is:
- rule_activated = (strcasecmp(compare_me, ii->rules[i].compared_value) ? 0 : 1);
+ rule_activated = exact_match;
break;
case fcomp_isnot:
- rule_activated = (strcasecmp(compare_me, ii->rules[i].compared_value) ? 1 : 0);
+ rule_activated = !exact_match;
break;
}
break;
* 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]);
}
* 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)) {
// 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);
}