diff src/sm-archive.cpp @ 21:09564d4acd9e stable-1-0-8

patches from Marco d'Itri for postfix
author Carl Byington <carl@five-ten-sg.com>
date Fri, 24 Dec 2010 15:13:18 -0800
parents b24369330483
children 9298f8b00db2
line wrap: on
line diff
--- 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<n; i++) key[i] = tolower(key[i]);
+	char *key, *p;
+	int i;
+
+	if (strcmp(email, "<>") == 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++) {