diff src/dnsbl.cpp @ 331:9800776436b9

allow dkim whitelisting to override uribl hosts in the mail body
author Carl Byington <carl@five-ten-sg.com>
date Mon, 19 Dec 2016 15:32:32 -0800
parents b5b93a7e1e6d
children 89574f8a2f64
line wrap: on
line diff
--- a/src/dnsbl.cpp	Mon Dec 19 12:05:06 2016 -0800
+++ b/src/dnsbl.cpp	Mon Dec 19 15:32:32 2016 -0800
@@ -1116,7 +1116,7 @@
     if (n ==0) return strdup("<>");
     char *key = strdup(email);
     key[n] = '\0';
-    for (int i=0; i<n; i++) key[i] = tolower(key[i]);
+    for (size_t i=0; i<n; i++) key[i] = tolower(key[i]);
     if ((n > 14) && (strncmp(key, "srs", 3) == 0)) {
         // might have srs coding to be removed
         const int nmatch = 7;
@@ -1594,7 +1594,8 @@
 
         char buf[maxlen];
         string msg;
-        string_set alive;
+        string_set unknowns;
+        string_set whites;
         bool random = false;
         int  limit  = 0;
         if (priv.dkim_signers.empty()) {
@@ -1613,21 +1614,26 @@
         for (context_map::iterator i=priv.env_to.begin(); i!=priv.env_to.end(); i++) {
             const char *rcpt   = (*i).first;
             CONTEXT &con = *((*i).second);
-            if (!con.acceptable_content(*priv.memory, score, bulk, priv.queueid, priv.dkim_signers, priv.fromaddr, msg)) {
+            const char *st = con.acceptable_content(*priv.memory, score, bulk, priv.queueid, priv.dkim_signers, priv.fromaddr, msg);
+            if (st == token_black) {
                 // bad html tags or excessive hosts or
                 // high spam assassin score or dcc bulk threshold exceedeed
                 // or signed by a dkim signer that we don't like
                 // or header from requires dkim signer that is missing
                 smfi_delrcpt(ctx, (char*)rcpt);
             }
-            else {
-                alive.insert(rcpt);
+            else if (st == token_unknown) {
+                unknowns.insert(rcpt);
                 random |= con.get_host_random();
                 limit   = max(limit, con.get_host_limit());
             }
+            else if (st == token_white) {
+                whites.insert(rcpt);
         }
-        bool rejecting = alive.empty(); // if alive is empty, we must have set msg above in acceptable_content()
-        if (!rejecting) {
+        }
+        bool rejecting = unknowns.empty() && whites.empty();
+        if (!unknowns.empty()) {
+            // check hosts for those recipients
             const char *fmt;
             const char *found;
             if (check_hosts(priv, random, limit, fmt, host, ip, found)) {
@@ -1653,7 +1659,7 @@
             }
             else rc = SMFIS_CONTINUE;
         }
-        else if (!priv.have_whites) {
+        else if (!priv.have_whites && whites.empty()) {
             // can reject the entire message
             snprintf(buf, sizeof(buf), "%s", msg.c_str());
             smfi_setreply(ctx, (char*)"550", (char*)"5.7.1", buf);
@@ -1661,7 +1667,7 @@
         }
         else {
             // need to accept it but remove the recipients that don't want it
-            for (string_set::iterator i=alive.begin(); i!=alive.end(); i++) {
+            for (string_set::iterator i=unknowns.begin(); i!=unknowns.end(); i++) {
                 const char *rcpt = *i;
                 smfi_delrcpt(ctx, (char*)rcpt);
             }