# HG changeset patch # User Carl Byington # Date 1293232398 28800 # Node ID 09564d4acd9eabf06e2ca3b04a6628c201b48ba3 # Parent a7564d29fd53ef2469609ce904e9370372c1ca79 patches from Marco d'Itri for postfix diff -r a7564d29fd53 -r 09564d4acd9e AUTHORS --- a/AUTHORS Thu Jun 12 18:19:42 2008 -0700 +++ b/AUTHORS Fri Dec 24 15:13:18 2010 -0800 @@ -1,2 +1,3 @@ 510 Software Group Sergey Shapovalov +Marco d'Itri diff -r a7564d29fd53 -r 09564d4acd9e ChangeLog --- a/ChangeLog Thu Jun 12 18:19:42 2008 -0700 +++ b/ChangeLog Fri Dec 24 15:13:18 2010 -0800 @@ -1,3 +1,6 @@ +1.8 2010-12-24 + patches from Marco d'Itri for postfix + 1.7 2008-06-12 Fedora 9 compile and const correctness. diff -r a7564d29fd53 -r 09564d4acd9e NEWS --- a/NEWS Thu Jun 12 18:19:42 2008 -0700 +++ b/NEWS Fri Dec 24 15:13:18 2010 -0800 @@ -1,3 +1,4 @@ +1.8 2010-12-24 patches from Marco d'Itri for postfix 1.7 2008-06-12 Fedora 9 compile and const correctness. 1.6 2008-03-21 Add src/daemon* missing from source control. 1.5 2007-08-24 GPL3. Can now remove original recipients. diff -r a7564d29fd53 -r 09564d4acd9e configure.in --- a/configure.in Thu Jun 12 18:19:42 2008 -0700 +++ b/configure.in Fri Dec 24 15:13:18 2010 -0800 @@ -1,5 +1,5 @@ AC_PREREQ(2.59) -AC_INIT(sm-archive,1.7,carl@five-ten-sg.com) +AC_INIT(sm-archive,1.8,carl@five-ten-sg.com) AC_CONFIG_SRCDIR([config.h.in]) AC_CONFIG_HEADER([config.h]) diff -r a7564d29fd53 -r 09564d4acd9e sm-archive.spec.in --- a/sm-archive.spec.in Thu Jun 12 18:19:42 2008 -0700 +++ b/sm-archive.spec.in Fri Dec 24 15:13:18 2010 -0800 @@ -83,6 +83,9 @@ %changelog +* Fri Dec 24 2010 Carl Byington - 1.8-1 +- patches from Marco d'Itri for postfix + * Thu Jun 12 2008 Carl Byington - 1.7-1 - Fedora 9 compile and const correctness. diff -r a7564d29fd53 -r 09564d4acd9e src/context.cpp --- a/src/context.cpp Thu Jun 12 18:19:42 2008 -0700 +++ b/src/context.cpp Fri Dec 24 15:13:18 2010 -0800 @@ -33,15 +33,13 @@ bool CONFIG::find(const char *needle, string_set &haystack) { string_set::iterator i = haystack.find(needle); if (i != haystack.end()) return true; // found user@domain.tld key - char *x = strchr(needle, '@'); + const char *x = strchr(needle, '@'); if (x) { x++; i = haystack.find(x); if (i != haystack.end()) return true; // found domain.tld key - char y = *x; - *x = '\0'; - i = haystack.find(needle); - *x = y; + string userpart(needle, x-needle); + i = haystack.find(userpart.c_str()); if (i != haystack.end()) return true; // found user@ key } return false; @@ -51,15 +49,13 @@ const char *CONFIG::find(const char *needle, string_map &haystack) { string_map::iterator i = haystack.find(needle); if (i != haystack.end()) return (*i).second; // found user@domain.tld key - char *x = strchr(needle, '@'); + const char *x = strchr(needle, '@'); if (x) { x++; i = haystack.find(x); if (i != haystack.end()) return (*i).second; // found domain.tld key - char y = *x; - *x = '\0'; - i = haystack.find(needle); - *x = y; + string userpart(needle, x-needle); + i = haystack.find(userpart.c_str()); if (i != haystack.end()) return (*i).second; // found user@ key } return NULL; diff -r a7564d29fd53 -r 09564d4acd9e src/sm-archive.cpp --- a/src/sm-archive.cpp Thu Jun 12 18:19:42 2008 -0700 +++ b/src/sm-archive.cpp Fri Dec 24 15:13:18 2010 -0800 @@ -108,7 +108,8 @@ void my_syslog(mlfiPriv *priv, const char *text) { char buf[maxlen]; if (priv) { - snprintf(buf, sizeof(buf), "%s: %s", priv->queueid, text); + snprintf(buf, sizeof(buf), "%s: %s", + priv->queueid ? priv->queueid : "NOQUEUE", text); text = buf; } if (use_syslog) { @@ -135,14 +136,21 @@ // always be enclosed in <>. It may have mixed case, just // as the mail client sent it. We dup the string and convert // the duplicate to lower case. +// Postfix will return addresses without <> if they have been provided +// this way in the SMTP dialog. // const char *to_lower_string(const char *email); const char *to_lower_string(const char *email) { - int n = strlen(email)-2; - if (n < 1) return strdup(email); - char *key = strdup(email+1); - key[n] = '\0'; - for (int i=0; i") == 0) return strdup(email); + if (email[0] == '<') p = (char *) email + 1; + else p = (char *) email; + key = (char *) malloc(strlen(p) + 1); + for (i = 0; p[i] != '\0'; i++) key[i] = tolower(p[i]); + if (p[i - 1] == '>') i--; + key[i] = '\0'; return key; } @@ -189,7 +197,8 @@ { mlfiPriv &priv = *MLFIPRIV; CONFIG &dc = *priv.pc; - if (!priv.queueid) priv.queueid = strdup(smfi_getsymval(ctx, (char*)"i")); + const char *i_macro = smfi_getsymval(ctx, (char*)"i"); + if (!priv.queueid && i_macro) priv.queueid = strdup(i_macro); const char *rcptaddr = to_lower_string(rcpt[0]); if (debug_syslog > 1) { char msg[maxlen]; @@ -208,6 +217,8 @@ { mlfiPriv &priv = *MLFIPRIV; CONFIG &dc = *priv.pc; + const char *i_macro = smfi_getsymval(ctx, (char*)"i"); + if (!priv.queueid && i_macro) priv.queueid = strdup(i_macro); const char *target = dc.find_from(priv.mailaddr); add_target(priv, target); for (string_set::iterator i=priv.targets.begin(); i!=priv.targets.end(); i++) {