diff src/dnsbl.cpp @ 167:9b129ed78d7d stable-6-0-6

actually use spamassassin result, allow build without spam assassin, only call it if some recipient needs it.
author carl
date Mon, 27 Aug 2007 20:49:19 -0700
parents bf828f785407
children 6bac960af6b4
line wrap: on
line diff
--- a/src/dnsbl.cpp	Sun Aug 26 20:54:59 2007 -0700
+++ b/src/dnsbl.cpp	Mon Aug 27 20:49:19 2007 -0700
@@ -251,6 +251,7 @@
 	authenticated		= NULL;
 	have_whites 		= false;
 	only_whites 		= true;
+	want_spamassassin	= false;
 	memory				= NULL;
 	scanner 			= NULL;
 	assassin			= NULL;
@@ -286,6 +287,7 @@
 		authenticated		= NULL;
 		have_whites 		= false;
 		only_whites 		= true;
+		want_spamassassin	= false;
 		memory				= NULL;
 		scanner 			= NULL;
 		assassin			= NULL;
@@ -964,10 +966,9 @@
 	priv.queueid	   = strdup(smfi_getsymval(ctx, "i"));
 	priv.authenticated = smfi_getsymval(ctx, "{auth_authen}");
 	if (priv.authenticated) priv.authenticated = strdup(priv.authenticated);
-	priv.assassin	   = new SpamAssassin;
-	priv.assassin->mlfi_connect(&priv, priv.ip);
-	priv.assassin->mlfi_helo(priv.helo);
-	priv.assassin->mlfi_envfrom(priv.mailaddr, priv.queueid);
+	if (spamc != spamc_empty) {
+		priv.assassin  = new SpamAssassin(&priv, priv.ip, priv.helo, priv.mailaddr, priv.queueid);
+	}
 	return SMFIS_CONTINUE;
 }
 
@@ -978,7 +979,7 @@
 	CONFIG &dc = *priv.pc;
 	char  *rcptaddr  = rcpt[0];
 	char  *loto 	 = to_lower_string(rcptaddr);
-	priv.assassin->mlfi_envrcpt(ctx, loto);
+	if (priv.assassin) priv.assassin->mlfi_envrcpt(ctx, loto);
 	// priv.mailaddr sending original message to loto
 	CONTEXT 	&con = *(dc.find_context(loto)->find_context(priv.mailaddr));
 	VERIFYP 	 ver = con.find_verify(loto);
@@ -1070,6 +1071,8 @@
 		// but remember the non-whites
 		priv.need_content_filter(rcptaddr, con);
 		priv.only_whites = false;
+		priv.want_spamassassin |= (priv.assassin) &&					// have spam assassin available and
+								  (con.get_spamassassin_limit() != 0);	// want to use it with a non-zero score
 	}
 	if (st == white) {
 		priv.have_whites = true;
@@ -1082,7 +1085,7 @@
 	mlfiPriv &priv = *MLFIPRIV;
 	if (priv.authenticated) 	  return SMFIS_CONTINUE;
 	if (priv.only_whites)		  return SMFIS_CONTINUE;
-	priv.assassin->mlfi_header(headerf, headerv);
+	if (priv.want_spamassassin) priv.assassin->mlfi_header(headerf, headerv);
 	return SMFIS_CONTINUE;
 }
 
@@ -1091,7 +1094,7 @@
 	mlfiPriv &priv = *MLFIPRIV;
 	if (priv.authenticated) 	  return SMFIS_CONTINUE;
 	if (priv.only_whites)		  return SMFIS_CONTINUE;
-	priv.assassin->mlfi_eoh();
+	if (priv.want_spamassassin) priv.assassin->mlfi_eoh();
 	return SMFIS_CONTINUE;
 }
 
@@ -1100,7 +1103,7 @@
 	mlfiPriv &priv = *MLFIPRIV;
 	if (priv.authenticated) 	  return SMFIS_CONTINUE;
 	if (priv.only_whites)		  return SMFIS_CONTINUE;
-	priv.assassin->mlfi_body(data, len);
+	if (priv.want_spamassassin) priv.assassin->mlfi_body(data, len);
 	priv.scanner->scan(data, len);
 	return SMFIS_CONTINUE;
 }
@@ -1116,10 +1119,10 @@
 	// process end of message
 	if (priv.authenticated || priv.only_whites) rc = SMFIS_CONTINUE;
 	else {
-		int score = priv.assassin->mlfi_eom();
+		int score = (priv.want_spamassassin) ? priv.assassin->mlfi_eom() : 0;
 		// assert env_to not empty
 		char buf[maxlen];
-		char *msg = NULL;
+		string msg;
 		string_set alive;
 		bool random = false;
 		int  limit	= 0;
@@ -1151,7 +1154,7 @@
 					inet_ntop(AF_INET, (const u_char *)&ip, adr, sizeof(adr));
 					snprintf(buf, sizeof(buf), fmt, host, adr);
 				}
-				msg = buf;
+				msg = string(buf);
 				rejecting = true;
 			}
 		}
@@ -1160,7 +1163,8 @@
 		}
 		else if (!priv.have_whites) {
 			// can reject the entire message
-			smfi_setreply(ctx, "550", "5.7.1", msg);
+			snprintf(buf, sizeof(buf), "%s", msg.c_str());
+			smfi_setreply(ctx, "550", "5.7.1", buf);
 			rc = SMFIS_REJECT;
 		}
 		else {