james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r420088 - in /james/server/trunk/src/java/org/apache/james: transport/mailets/SpamAssassin.java util/SpamAssassinInvoker.java
Date Sat, 08 Jul 2006 08:30:05 GMT
Author: norman
Date: Sat Jul  8 01:30:04 2006
New Revision: 420088

URL: http://svn.apache.org/viewvc?rev=420088&view=rev
Log:
Move headergeneration to util class

Modified:
    james/server/trunk/src/java/org/apache/james/transport/mailets/SpamAssassin.java
    james/server/trunk/src/java/org/apache/james/util/SpamAssassinInvoker.java

Modified: james/server/trunk/src/java/org/apache/james/transport/mailets/SpamAssassin.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/transport/mailets/SpamAssassin.java?rev=420088&r1=420087&r2=420088&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/transport/mailets/SpamAssassin.java (original)
+++ james/server/trunk/src/java/org/apache/james/transport/mailets/SpamAssassin.java Sat Jul
 8 01:30:04 2006
@@ -16,6 +16,8 @@
  ***********************************************************************/
 package org.apache.james.transport.mailets;
 
+import java.util.Iterator;
+
 import org.apache.james.util.SpamAssassinInvoker;
 import org.apache.mailet.GenericMailet;
 import org.apache.mailet.Mail;
@@ -43,8 +45,6 @@
 
     int spamdPort;
 
-    String subjectPrefix;
-
     public void init() throws MessagingException {
         spamdHost = getInitParameter("spamdHost");
         if (spamdHost == null || spamdHost.equals("")) {
@@ -73,23 +73,16 @@
             // Invoke spamassian connection and scan the message
             SpamAssassinInvoker sa = new SpamAssassinInvoker(spamdHost,
                     spamdPort);
-            boolean spam = sa.scanMail(message);
-            String hits = sa.getHits();
-            String required = sa.getRequiredHits();
-
-            // message was spam
-            if (spam) {
-                // add headers
-                message.setHeader("X-Spam-Flag", "YES");
-                message.setHeader("X-Spam-Status", new StringBuffer(
-                        "Yes, hits=").append(hits).append(" required=").append(
-                        required).toString());
-            } else {
-                // add headers
-                message.setHeader("X-Spam-Status",
-                        new StringBuffer("No, hits=").append(hits).append(
-                                " required=").append(required).toString());
+            sa.scanMail(message);
+
+            Iterator headers = sa.getHeaders().keySet().iterator();
+
+            // Add headers 
+            while (headers.hasNext()) {
+                String key = headers.next().toString();
+                message.setHeader(key, (String) sa.getHeaders().get(key));
             }
+
             message.saveChanges();
         } catch (MessagingException e) {
             log(e.getMessage());

Modified: james/server/trunk/src/java/org/apache/james/util/SpamAssassinInvoker.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/util/SpamAssassinInvoker.java?rev=420088&r1=420087&r2=420088&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/util/SpamAssassinInvoker.java (original)
+++ james/server/trunk/src/java/org/apache/james/util/SpamAssassinInvoker.java Sat Jul  8
01:30:04 2006
@@ -24,6 +24,7 @@
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
+import java.util.HashMap;
 import java.util.StringTokenizer;
 
 /**
@@ -42,6 +43,8 @@
 
     String required = "?";
 
+    HashMap headers = new HashMap();
+
     public SpamAssassinInvoker(String spamdHost, int spamdPort) {
         this.spamdHost = spamdHost;
         this.spamdPort = spamdPort;
@@ -88,9 +91,20 @@
                     required = t.nextToken();
 
                     if (spam) {
+                        // message was spam
+                        headers.put("X-Spam-Flag", "YES");
+                        headers.put("X-Spam-Status", new StringBuffer(
+                                "Yes, hits=").append(hits).append(" required=")
+                                .append(required).toString());
+
                         // spam detected
                         return true;
                     } else {
+                        // add headers
+                        headers.put("X-Spam-Status", new StringBuffer(
+                                "No, hits=").append(hits).append(" required=")
+                                .append(required).toString());
+
                         return false;
                     }
                 }
@@ -133,5 +147,14 @@
      */
     public String getRequiredHits() {
         return required;
+    }
+
+    /**
+     * Return the headers which spamd should add
+     * 
+     * @return headers HashMap of headers to add
+     */
+    public HashMap getHeaders() {
+        return headers;
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message