When comparing the sender, compare both the name and address.
authorArt Cancro <ajc@citadel.org>
Sun, 29 Nov 2020 00:24:28 +0000 (19:24 -0500)
committerArt Cancro <ajc@citadel.org>
Sun, 29 Nov 2020 00:24:28 +0000 (19:24 -0500)
citadel/internet_addressing.c
citadel/modules/inboxrules/serv_inboxrules.c
citadel/user_ops.c

index 90794b87a24b01cc271465cf3c07df7cc1ccec74..9f24a46ee390c4afa291baabb2858d9014378f03 100644 (file)
@@ -1670,6 +1670,7 @@ void AutoGenerateEmailAddressForUser(struct ctdluser *user)
                        snprintf(synthetic_email_addr, sizeof synthetic_email_addr, "ctdl%08x@%s", i, CtdlGetConfigStr("c_fqdn"));
                }
                u = CtdlDirectoryLookup(NULL, synthetic_email_addr, 0);
+               syslog(LOG_DEBUG, "\033[33mAddress <%s> lookup <%d>\033[0m", synthetic_email_addr, u);
        }
 
        CtdlSetEmailAddressesForUser(user->fullname, synthetic_email_addr);
index fa30f2534bacb6f731e536bfc0a56548a17f8429..a381d4e17c696f32fa19c888f94bf1af3709ab52 100644 (file)
@@ -501,6 +501,7 @@ void inbox_do_msg(long msgnum, void *userdata) {
        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;
 
@@ -571,12 +572,22 @@ void inbox_do_msg(long msgnum, void *userdata) {
 
                // 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])) {
@@ -644,20 +655,37 @@ void inbox_do_msg(long msgnum, void *userdata) {
 
                                // 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;
index 168f224fbc3a183cad447d978e61f09c4099334b..df9c920fc3b73a90455ba56b2d76ea5345eee04c 100644 (file)
@@ -699,7 +699,7 @@ void do_login(void)
        }
 
        /* Populate the user principal identity, which is consistent and never aliased */
-       strcpy(CC->cs_principal_id, "wowowowow");
+       strcpy(CC->cs_principal_id, "");
        makeuserkey(CC->cs_principal_id, CC->user.fullname);
        strcat(CC->cs_principal_id, "@");
        strcat(CC->cs_principal_id, CtdlGetConfigStr("c_fqdn"));