diff src/dnsbl.cpp @ 246:8b0f16abee53 stable-6-0-28

Add prvs decoding to envelope addresses
author Carl Byington <carl@five-ten-sg.com>
date Fri, 30 Sep 2011 15:29:07 -0700
parents ef97c7cd4a6e
children b0738685bf51
line wrap: on
line diff
--- a/src/dnsbl.cpp	Mon Aug 15 21:19:13 2011 -0700
+++ b/src/dnsbl.cpp	Fri Sep 30 15:29:07 2011 -0700
@@ -97,6 +97,7 @@
 int   generation = 0;       // protected by the config_mutex
 const int maxlen = 1000;    // used for snprintf buffers
 regex_t srs_pattern;        // used to detect srs coding in mail addresses
+regex_t prvs_pattern;       // used to detect prvs coding in mail addresses
 
 pthread_mutex_t  config_mutex;
 pthread_mutex_t  syslog_mutex;
@@ -991,7 +992,7 @@
 // that.  So the <> wrapper is now optional.  It may have mixed case, just
 // as the mail client sent it.  We dup the string and convert the duplicate
 // to lower case. Some clients enclose the entire address in single quotes,
-// so we strip those as well. We also remove the SRS coding.
+// so we strip those as well. We also remove the SRS and prvs coding.
 //
 const char *to_lower_string(const char *email);
 const char *to_lower_string(const char *email) {
@@ -1009,7 +1010,7 @@
     char *key = strdup(email);
     key[n] = '\0';
     for (int i=0; i<n; i++) key[i] = tolower(key[i]);
-    if ((n > 12) && (strncmp(key, "srs", 3) == 0)) {
+    if ((n > 14) && (strncmp(key, "srs", 3) == 0)) {
         // might have srs coding to be removed
         const int nmatch = 6;
         regmatch_t match[nmatch];
@@ -1030,6 +1031,19 @@
             }
         }
     }
+    if ((n > 7) && (strncmp(key, "prvs", 4) == 0)) {
+        // might have prvs coding to be removed
+        const int nmatch = 3;
+        regmatch_t match[nmatch];
+        if (0 == regexec(&prvs_pattern, key, nmatch, match, 0)) {
+            int s2 = match[2].rm_so;    // user@domain
+            if (s2 != -1) {
+                char *newkey = strdup(key+s2);  // user@domain
+                free(key);
+                key = newkey;
+            }
+        }
+    }
     return key;
 }
 
@@ -1559,11 +1573,17 @@
     extern char *optarg;
 
     // setup srs coding detection
-    if (regcomp(&srs_pattern, "^srs(0|1)=([^=]*)=([^=]*)=([^=]*)=([^@]*)@", REG_ICASE | REG_EXTENDED)) {
+    if (regcomp(&srs_pattern, "^srs(0|1)=([^=]+)=([^=]+)=([^=]+)=([^@]+)@", REG_ICASE | REG_EXTENDED)) {
         printf("cannot compile regex pattern to find srs coding in mail addresses\n");
         exit(3);
     }
 
+    // setup prvs coding detection
+    if (regcomp(&prvs_pattern, "^prvs=([^=]+)=(.+)$", REG_ICASE | REG_EXTENDED)) {
+        printf("cannot compile regex pattern to find prvs coding in mail addresses\n");
+        exit(3);
+    }
+
     // Process command line options
     while ((c = getopt(argc, argv, args)) != -1) {
         switch (c) {