changeset 235:e6c66640f6f9

Add SRS decoding to envelope addresses
author Carl Byington <carl@five-ten-sg.com>
date Tue, 09 Jun 2009 08:36:34 -0700
parents 1c45d50cbbc6
children c0d2e99c0a1d
files ChangeLog NEWS configure.in dnsbl.spec.in src/dnsbl.cpp
diffstat 5 files changed, 38 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon May 25 17:48:40 2009 -0700
+++ b/ChangeLog	Tue Jun 09 08:36:34 2009 -0700
@@ -1,3 +1,6 @@
+6.24 2009-06-09
+    Add SRS decoding to envelope addresses.
+
 6.23 2009-05-25
     Add whitelisting by regex expression filtering.
     Add queueid to whitelist extension log message.
--- a/NEWS	Mon May 25 17:48:40 2009 -0700
+++ b/NEWS	Tue Jun 09 08:36:34 2009 -0700
@@ -1,3 +1,4 @@
+6.24 2009-06-09 Add SRS decoding to envelope addresses.
 6.23 2009-05-25 Add whitelisting by regex expression filtering.
 6.22 2009-05-08 Prevent auto whitelisting due to outgoing multipart/report delivery notifications.
 6.21 2009-01-03 Fixes to compile on old systems without memrchr or string::clear().
--- a/configure.in	Mon May 25 17:48:40 2009 -0700
+++ b/configure.in	Tue Jun 09 08:36:34 2009 -0700
@@ -1,6 +1,6 @@
 
 AC_PREREQ(2.59)
-AC_INIT(dnsbl,6.23,carl@five-ten-sg.com)
+AC_INIT(dnsbl,6.24,carl@five-ten-sg.com)
 AC_CONFIG_SRCDIR([config.h.in])
 AC_CONFIG_HEADER([config.h])
 
--- a/dnsbl.spec.in	Mon May 25 17:48:40 2009 -0700
+++ b/dnsbl.spec.in	Tue Jun 09 08:36:34 2009 -0700
@@ -96,6 +96,9 @@
 
 
 %changelog
+* Tue Jun 09 2009 Carl Byington <carl@five-ten-sg.com> - 6.24-1
+- Add SRS decoding to envelope addresses.
+
 * Mon May 25 2009 Carl Byington <carl@five-ten-sg.com> - 6.23-1
 - Add whitelisting by regex expression filtering.
 
--- a/src/dnsbl.cpp	Mon May 25 17:48:40 2009 -0700
+++ b/src/dnsbl.cpp	Tue Jun 09 08:36:34 2009 -0700
@@ -1,6 +1,6 @@
 /*
 
-Copyright (c) 2007 Carl Byington - 510 Software Group, released under
+Copyright (c) 2009 Carl Byington - 510 Software Group, released under
 the GPL version 3 or any later version at your choice available at
 http://www.gnu.org/licenses/gpl-3.0.txt
 
@@ -96,6 +96,7 @@
 CONFIG   *config = NULL;    // protected by the config_mutex
 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
 
 pthread_mutex_t  config_mutex;
 pthread_mutex_t  syslog_mutex;
@@ -969,7 +970,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.
+// so we strip those as well. We also remove the SRS coding.
 //
 const char *to_lower_string(const char *email);
 const char *to_lower_string(const char *email) {
@@ -987,6 +988,27 @@
     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)) {
+        // might have srs coding to be removed
+        const int nmatch = 6;
+        regmatch_t match[nmatch];
+        if (0 == regexec(&srs_pattern, key, nmatch, match, 0)) {
+            int s4 = match[4].rm_so;    // domain
+            int e4 = match[4].rm_eo;
+            int s5 = match[5].rm_so;    // user
+            int e5 = match[5].rm_eo;
+            if ((s4 != -1) && (s5 != -1)) {
+                char *newkey = strdup(key);   // large enough
+                key[e4] = '\0';
+                key[e5] = '\0';
+                strcpy(newkey, key+s5); // user
+                strcat(newkey, "@");    // @
+                strcat(newkey, key+s4); // domain
+                free(key);
+                key = newkey;
+            }
+        }
+    }
     return key;
 }
 
@@ -1491,6 +1513,12 @@
     const char *args = "b:r:p:t:e:d:chs";
     extern char *optarg;
 
+    // setup srs coding detection
+    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);
+    }
+
     // Process command line options
     while ((c = getopt(argc, argv, args)) != -1) {
         switch (c) {