james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r420110 - in /james/server/trunk/src/java/org/apache/james: transport/LinearProcessor.java util/MatcherInverter.java
Date Sat, 08 Jul 2006 13:59:53 GMT
Author: norman
Date: Sat Jul  8 06:59:52 2006
New Revision: 420110

URL: http://svn.apache.org/viewvc?rev=420110&view=rev
Log:
Allow to "invert" a matcher by config it with notmatch=matcher. See JAMES-556

Added:
    james/server/trunk/src/java/org/apache/james/util/MatcherInverter.java
Modified:
    james/server/trunk/src/java/org/apache/james/transport/LinearProcessor.java

Modified: james/server/trunk/src/java/org/apache/james/transport/LinearProcessor.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/transport/LinearProcessor.java?rev=420110&r1=420109&r2=420110&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/transport/LinearProcessor.java (original)
+++ james/server/trunk/src/java/org/apache/james/transport/LinearProcessor.java Sat Jul  8
06:59:52 2006
@@ -32,6 +32,7 @@
 import org.apache.james.services.MailetLoader;
 import org.apache.james.services.MatcherLoader;
 import org.apache.james.services.SpoolRepository;
+import org.apache.james.util.MatcherInverter;
 import org.apache.mailet.GenericMailet;
 import org.apache.mailet.GenericMatcher;
 import org.apache.mailet.Mail;
@@ -573,11 +574,28 @@
         {
             Configuration c = mailetConfs[j];
             String mailetClassName = c.getAttribute("class");
-            String matcherName = c.getAttribute("match");
+            String matcherName = c.getAttribute("match",null);
+            String invertedMatcherName = c.getAttribute("notmatch",null);
+
             Mailet mailet = null;
             Matcher matcher = null;
             try {
-                matcher = matchLoader.getMatcher(matcherName);
+
+                if (matcherName != null && invertedMatcherName != null) {
+                    // if no matcher is configured throw an Exception
+                    throw new ConfigurationException(
+                            "Please configure only match or nomatch per mailet");
+                } else if (matcherName != null) {
+                    matcher = matchLoader.getMatcher(matcherName);
+                } else if (invertedMatcherName != null) {
+                    matcher = new MatcherInverter(matchLoader
+                            .getMatcher(invertedMatcherName));
+                   
+                } else {
+                    // default matcher is All
+                    matcher = matchLoader.getMatcher("All");
+                }
+                
                 //The matcher itself should log that it's been inited.
                 if (getLogger().isInfoEnabled()) {
                     StringBuffer infoBuffer =

Added: james/server/trunk/src/java/org/apache/james/util/MatcherInverter.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/util/MatcherInverter.java?rev=420110&view=auto
==============================================================================
--- james/server/trunk/src/java/org/apache/james/util/MatcherInverter.java (added)
+++ james/server/trunk/src/java/org/apache/james/util/MatcherInverter.java Sat Jul  8 06:59:52
2006
@@ -0,0 +1,80 @@
+/***********************************************************************
+ * Copyright (c) 1999-2006 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You    *
+ * may obtain a copy of the License at:                                *
+ *                                                                     *
+ *     http://www.apache.org/licenses/LICENSE-2.0                      *
+ *                                                                     *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS,   *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
+ * implied.  See the License for the specific language governing       *
+ * permissions and limitations under the License.                      *
+ ***********************************************************************/
+package org.apache.james.util;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.mail.MessagingException;
+
+import org.apache.mailet.Mail;
+import org.apache.mailet.Matcher;
+import org.apache.mailet.MatcherConfig;
+
+/**
+ * This class can be used as a wrapper for getting the "not matched" recipients
+ * 
+ */
+public class MatcherInverter implements Matcher {
+
+    private Matcher wrappedMatcher;
+
+    public MatcherInverter(Matcher wrappedMatcher) {
+        this.wrappedMatcher = wrappedMatcher;
+    }
+
+    /**
+     * @see org.apache.Mailet.Matcher#destroy()
+     */
+    public void destroy() {
+        wrappedMatcher.destroy();
+    }
+
+    /**
+     * @see org.apache.Mailet.Matcher#getMatcherConfig()
+     */
+    public MatcherConfig getMatcherConfig() {
+        return wrappedMatcher.getMatcherConfig();
+    }
+
+    /**
+     * @see org.apache.Mailet.Matcher#getMatcherInfo()
+     */
+    public String getMatcherInfo() {
+        return wrappedMatcher.getMatcherInfo();
+    }
+
+    /**
+     * @see org.apache.Mailet.Matcher#destroy()
+     */
+    public void init(MatcherConfig config) throws MessagingException {
+        wrappedMatcher.init(config);
+    }
+
+    /**
+     * Return a Collection of "not matched" recipients
+     */
+    public Collection match(Mail mail) throws MessagingException {
+        // Create a new recipient Collection cause mail.getRecipients() give a reference
to the internal 
+        // list of recipients. If we make changes there the original collection whould be
corrupted
+        Collection recipients = new ArrayList(mail.getRecipients());
+       
+        recipients.removeAll(wrappedMatcher.match(mail));
+        return recipients;
+    }
+
+}



---------------------------------------------------------------------
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