diff src/spamass.cpp.in @ 168:6bac960af6b4

add generic reverse dns filtering regex
author carl
date Thu, 30 Aug 2007 11:08:46 -0700
parents 9b129ed78d7d
children bd33eaccfed8
line wrap: on
line diff
--- a/src/spamass.cpp.in	Mon Aug 27 20:49:19 2007 -0700
+++ b/src/spamass.cpp.in	Thu Aug 30 11:08:46 2007 -0700
@@ -93,45 +93,25 @@
         strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", localtime(&tval));
         macro_b = date;
 
-        /* queue ID */
+        // queue ID
         macro_i = queueid;
 
-        /* FQDN of this site */
-        macro_j = smfi_getsymval(ctx, "j");
-        if (!macro_j) {
-            macro_j = "localhost";
-            warnmacro("j", "ENVRCPT");
-        }
+        // FQDN of this site
+        macro_j = getorwarnmacro(ctx, "j", "localhost", "ENVRCPT");
 
-        /* Protocol used to receive the message */
-        macro_r = smfi_getsymval(ctx, "r");
-        if (!macro_r) {
-            macro_r = "SMTP";
-            warnmacro("r", "ENVRCPT");
-        }
+        // Protocol used to receive the message */
+        macro_r = getorwarnmacro(ctx, "r", "SMTP",      "ENVRCPT");
 
         macro_s = helo;
 
-        /* Sendmail binary version */
-        macro_v = smfi_getsymval(ctx, "v");
-        if (!macro_v) {
-            macro_v = "8.13.0";
-            warnmacro("v", "ENVRCPT");
-        }
+        // Sendmail binary version
+        macro_v = getorwarnmacro(ctx, "v", "8.13.0",    "ENVRCPT");
 
-        /* Sendmail .cf version */
-        macro_Z = smfi_getsymval(ctx, "Z");
-        if (!macro_Z) {
-            macro_Z = "8.13.0";
-            warnmacro("Z", "ENVRCPT");
-        }
+        // Sendmail .cf version
+        macro_Z = getorwarnmacro(ctx, "Z", "8.13.0",    "ENVRCPT");
 
-        /* Validated sending site's address */
-        macro__ = smfi_getsymval(ctx, "_");
-        if (!macro__) {
-            macro__ = "unknown";
-            warnmacro("_", "ENVRCPT");
-        }
+        // Validated sending site's address
+        macro__ = getorwarnmacro(ctx, "_", "unknown",   "ENVRCPT");
 
         output(string("Received: from ") + macro_s + " (" + macro__+ ")\r\n\t" +
                "by " + macro_j + " (" + macro_v + "/" + macro_Z + ") with " + macro_r + " id " + macro_i + "\r\n\t" +
@@ -413,6 +393,17 @@
 }
 
 
+char *SpamAssassin::getorwarnmacro(SMFICTX *ctx, char *macro, char *def, char *scope)
+{
+    char *rc = smfi_getsymval(ctx, macro);
+    if (!rc) {
+        rc = def;
+        warnmacro(macro, scope);
+    }
+    return rc;
+}
+
+
 void SpamAssassin::warnmacro(char *macro, char *scope)
 {
     if (warnedmacro) return;