Repository: james-project
Updated Branches:
  refs/heads/master 1ed1e4634 -> 5c80ce22d


JAMES-2341 Move SpamAssassinListenerModule to its own project


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/b92f3e94
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/b92f3e94
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/b92f3e94

Branch: refs/heads/master
Commit: b92f3e948b2b55c3b9facb5f1fcea2d8fc2eeb10
Parents: 2b62f54
Author: Antoine Duprat <[email protected]>
Authored: Wed Feb 28 15:42:50 2018 +0100
Committer: Antoine Duprat <[email protected]>
Committed: Thu Mar 8 10:36:33 2018 +0100

----------------------------------------------------------------------
 server/container/guice/cassandra-guice/pom.xml  |  8 +-
 .../apache/james/CassandraJamesServerMain.java  |  2 +-
 .../SpamAssassinConfigurationLoader.java        | 49 ----------
 .../mailbox/SpamAssassinListenerModule.java     | 72 --------------
 .../SpamAssassinConfigurationLoaderTest.java    | 59 ------------
 .../guice/mailbox-plugin-spamassassin/pom.xml   | 62 ++++++++++++
 .../SpamAssassinConfigurationLoader.java        | 49 ++++++++++
 .../SpamAssassinListenerModule.java             | 99 ++++++++++++++++++++
 .../SpamAssassinConfigurationLoaderTest.java    | 60 ++++++++++++
 server/container/guice/pom.xml                  |  6 ++
 10 files changed, 281 insertions(+), 185 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/b92f3e94/server/container/guice/cassandra-guice/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/pom.xml 
b/server/container/guice/cassandra-guice/pom.xml
index affbae2..3f0a07f 100644
--- a/server/container/guice/cassandra-guice/pom.xml
+++ b/server/container/guice/cassandra-guice/pom.xml
@@ -78,10 +78,6 @@
         </dependency>
         <dependency>
             <groupId>${project.groupId}</groupId>
-            <artifactId>apache-james-mailbox-spamassassin</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>${project.groupId}</groupId>
             <artifactId>apache-james-mailbox-tika</artifactId>
             <type>test-jar</type>
             <scope>test</scope>
@@ -146,6 +142,10 @@
         </dependency>
         <dependency>
             <groupId>${project.groupId}</groupId>
+            
<artifactId>james-server-guice-mailbox-plugin-spamassassin</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
             <artifactId>james-server-guice-managedsieve</artifactId>
         </dependency>
         <dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/b92f3e94/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
 
b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
index bfd1c84..d9d5a1e 100644
--- 
a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
+++ 
b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
@@ -29,7 +29,6 @@ import 
org.apache.james.modules.data.CassandraUsersRepositoryModule;
 import org.apache.james.modules.mailbox.CassandraMailboxModule;
 import org.apache.james.modules.mailbox.CassandraSessionModule;
 import org.apache.james.modules.mailbox.ElasticSearchMailboxModule;
-import org.apache.james.modules.mailbox.SpamAssassinListenerModule;
 import org.apache.james.modules.mailbox.TikaMailboxModule;
 import org.apache.james.modules.metrics.CassandraMetricsModule;
 import org.apache.james.modules.protocols.IMAPServerModule;
@@ -49,6 +48,7 @@ import 
org.apache.james.modules.server.MailRepositoriesRoutesModule;
 import org.apache.james.modules.server.MailboxRoutesModule;
 import org.apache.james.modules.server.SwaggerRoutesModule;
 import org.apache.james.modules.server.WebAdminServerModule;
+import org.apache.james.modules.spamassassin.SpamAssassinListenerModule;
 
 import com.google.inject.Module;
 import com.google.inject.util.Modules;

http://git-wip-us.apache.org/repos/asf/james-project/blob/b92f3e94/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/SpamAssassinConfigurationLoader.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/SpamAssassinConfigurationLoader.java
 
b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/SpamAssassinConfigurationLoader.java
deleted file mode 100644
index 35a2077..0000000
--- 
a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/SpamAssassinConfigurationLoader.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you 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.modules.mailbox;
-
-import java.util.Optional;
-
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.PropertiesConfiguration;
-import org.apache.james.mailbox.spamassassin.SpamAssassinConfiguration;
-import org.apache.james.util.Host;
-
-public class SpamAssassinConfigurationLoader {
-
-    private static final String SPAMASSASSIN_HOST = "spamassassin.host";
-    private static final String SPAMASSASSIN_PORT = "spamassassin.port";
-    public static final String DEFAULT_HOST = "127.0.0.1";
-    public static final int DEFAULT_PORT = 783;
-
-    public static SpamAssassinConfiguration disable() {
-        return new SpamAssassinConfiguration(Optional.empty());
-    }
-
-    public static SpamAssassinConfiguration 
fromProperties(PropertiesConfiguration configuration) throws 
ConfigurationException {
-        Host host = getHost(configuration);
-        return new SpamAssassinConfiguration(Optional.of(host));
-    }
-
-    private static Host getHost(PropertiesConfiguration propertiesReader) 
throws ConfigurationException {
-        return Host.from(propertiesReader.getString(SPAMASSASSIN_HOST, 
DEFAULT_HOST), 
-                propertiesReader.getInteger(SPAMASSASSIN_PORT, DEFAULT_PORT));
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/b92f3e94/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/SpamAssassinListenerModule.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/SpamAssassinListenerModule.java
 
b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/SpamAssassinListenerModule.java
deleted file mode 100644
index ce83ba9..0000000
--- 
a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/SpamAssassinListenerModule.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you 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.modules.mailbox;
-
-import java.io.FileNotFoundException;
-
-import javax.inject.Singleton;
-
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.PropertiesConfiguration;
-import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.spamassassin.SpamAssassin;
-import org.apache.james.mailbox.spamassassin.SpamAssassinConfiguration;
-import org.apache.james.mailbox.spamassassin.SpamAssassinListener;
-import org.apache.james.mailbox.store.StoreMailboxManager;
-import org.apache.james.mailbox.store.event.SpamEventListener;
-import org.apache.james.utils.PropertiesProvider;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.inject.AbstractModule;
-import com.google.inject.Provides;
-
-public class SpamAssassinListenerModule extends AbstractModule {
-    private static final Logger LOGGER = 
LoggerFactory.getLogger(SpamAssassinListenerModule.class);
-
-    public static final String SPAMASSASSIN_CONFIGURATION_NAME = 
"spamassassin";
-
-    @Override
-    protected void configure() {
-    }
-
-    @Provides
-    @Singleton
-    public SpamEventListener 
provideSpamEventListener(SpamAssassinConfiguration spamAssassinConfiguration, 
StoreMailboxManager storeMailboxManager) throws MailboxException {
-        SpamAssassinListener spamAssassinListener = new 
SpamAssassinListener(new SpamAssassin(spamAssassinConfiguration));
-        MailboxSession session = null;
-        storeMailboxManager.addGlobalListener(spamAssassinListener, session);
-        return spamAssassinListener;
-    }
-
-    @Provides
-    @Singleton
-    private SpamAssassinConfiguration 
getSpamAssassinConfiguration(PropertiesProvider propertiesProvider) throws 
ConfigurationException {
-        try {
-            PropertiesConfiguration configuration = 
propertiesProvider.getConfiguration(SPAMASSASSIN_CONFIGURATION_NAME);
-            return 
SpamAssassinConfigurationLoader.fromProperties(configuration);
-        } catch (FileNotFoundException e) {
-            LOGGER.warn("Could not find " + SPAMASSASSIN_CONFIGURATION_NAME + 
" configuration file. Disabling this service.");
-            return SpamAssassinConfigurationLoader.disable();
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/b92f3e94/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/SpamAssassinConfigurationLoaderTest.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/SpamAssassinConfigurationLoaderTest.java
 
b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/SpamAssassinConfigurationLoaderTest.java
deleted file mode 100644
index a2c8f31..0000000
--- 
a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/SpamAssassinConfigurationLoaderTest.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you 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.modules.mailbox;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import org.apache.commons.configuration.PropertiesConfiguration;
-import org.apache.james.mailbox.spamassassin.SpamAssassinConfiguration;
-import org.apache.james.util.Host;
-import org.junit.Test;
-
-public class SpamAssassinConfigurationLoaderTest {
-
-    @Test
-    public void isEnableShouldReturnFalseWhenDisable() {
-        SpamAssassinConfiguration configuration = 
SpamAssassinConfigurationLoader.disable();
-        assertThat(configuration.isEnable()).isFalse();
-    }
-
-    @Test
-    public void isEnableShouldReturnTrueWhenEnable() throws Exception {
-        SpamAssassinConfiguration configuration = 
SpamAssassinConfigurationLoader.fromProperties(new PropertiesConfiguration());
-        assertThat(configuration.isEnable()).isTrue();
-    }
-
-    @Test
-    public void hostShouldReturnDefaultWhenConfigurationIsEmpty() throws 
Exception {
-        SpamAssassinConfiguration configuration = 
SpamAssassinConfigurationLoader.fromProperties(new PropertiesConfiguration());
-        
assertThat(configuration.getHost().get()).isEqualTo(Host.from(SpamAssassinConfigurationLoader.DEFAULT_HOST,
 SpamAssassinConfigurationLoader.DEFAULT_PORT));
-    }
-
-    @Test
-    public void hostShouldReturnCustomWhenConfigurationIsProvided() throws 
Exception {
-        PropertiesConfiguration propertiesConfiguration = new 
PropertiesConfiguration();
-        String host = "10.69.1.123";
-        propertiesConfiguration.addProperty("spamassassin.host", host);
-        int port = 1783;
-        propertiesConfiguration.addProperty("spamassassin.port", port);
-
-        SpamAssassinConfiguration configuration = 
SpamAssassinConfigurationLoader.fromProperties(propertiesConfiguration);
-        assertThat(configuration.getHost().get()).isEqualTo(Host.from(host, 
port));
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/b92f3e94/server/container/guice/mailbox-plugin-spamassassin/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/guice/mailbox-plugin-spamassassin/pom.xml 
b/server/container/guice/mailbox-plugin-spamassassin/pom.xml
new file mode 100644
index 0000000..ce12d12
--- /dev/null
+++ b/server/container/guice/mailbox-plugin-spamassassin/pom.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements. See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership. The ASF licenses this file
+    to you 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.james</groupId>
+        <artifactId>james-server-guice</artifactId>
+        <version>3.1.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>james-server-guice-mailbox-plugin-spamassassin</artifactId>
+
+    <name>Apache James :: Server :: Guice :: Mailbox :: Plugin :: 
SpamAssassin</name>
+    <description>Mailbox modules for Guice implementation of James 
server</description>
+
+    <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>apache-james-mailbox-spamassassin</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>james-server-guice-configuration</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.google.inject</groupId>
+            <artifactId>guice</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.google.inject.extensions</groupId>
+            <artifactId>guice-multibindings</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>commons-configuration</groupId>
+            <artifactId>commons-configuration</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+</project>

http://git-wip-us.apache.org/repos/asf/james-project/blob/b92f3e94/server/container/guice/mailbox-plugin-spamassassin/src/main/java/org/apache/james/modules/spamassassin/SpamAssassinConfigurationLoader.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/mailbox-plugin-spamassassin/src/main/java/org/apache/james/modules/spamassassin/SpamAssassinConfigurationLoader.java
 
b/server/container/guice/mailbox-plugin-spamassassin/src/main/java/org/apache/james/modules/spamassassin/SpamAssassinConfigurationLoader.java
new file mode 100644
index 0000000..9eaf2b2
--- /dev/null
+++ 
b/server/container/guice/mailbox-plugin-spamassassin/src/main/java/org/apache/james/modules/spamassassin/SpamAssassinConfigurationLoader.java
@@ -0,0 +1,49 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you 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.modules.spamassassin;
+
+import java.util.Optional;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.james.mailbox.spamassassin.SpamAssassinConfiguration;
+import org.apache.james.util.Host;
+
+public class SpamAssassinConfigurationLoader {
+
+    private static final String SPAMASSASSIN_HOST = "spamassassin.host";
+    private static final String SPAMASSASSIN_PORT = "spamassassin.port";
+    public static final String DEFAULT_HOST = "127.0.0.1";
+    public static final int DEFAULT_PORT = 783;
+
+    public static SpamAssassinConfiguration disable() {
+        return new SpamAssassinConfiguration(Optional.empty());
+    }
+
+    public static SpamAssassinConfiguration 
fromProperties(PropertiesConfiguration configuration) throws 
ConfigurationException {
+        Host host = getHost(configuration);
+        return new SpamAssassinConfiguration(Optional.of(host));
+    }
+
+    private static Host getHost(PropertiesConfiguration propertiesReader) 
throws ConfigurationException {
+        return Host.from(propertiesReader.getString(SPAMASSASSIN_HOST, 
DEFAULT_HOST), 
+                propertiesReader.getInteger(SPAMASSASSIN_PORT, DEFAULT_PORT));
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/b92f3e94/server/container/guice/mailbox-plugin-spamassassin/src/main/java/org/apache/james/modules/spamassassin/SpamAssassinListenerModule.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/mailbox-plugin-spamassassin/src/main/java/org/apache/james/modules/spamassassin/SpamAssassinListenerModule.java
 
b/server/container/guice/mailbox-plugin-spamassassin/src/main/java/org/apache/james/modules/spamassassin/SpamAssassinListenerModule.java
new file mode 100644
index 0000000..8054bd4
--- /dev/null
+++ 
b/server/container/guice/mailbox-plugin-spamassassin/src/main/java/org/apache/james/modules/spamassassin/SpamAssassinListenerModule.java
@@ -0,0 +1,99 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you 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.modules.spamassassin;
+
+import java.io.FileNotFoundException;
+import java.util.List;
+
+import javax.inject.Singleton;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.james.lifecycle.api.Configurable;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.spamassassin.SpamAssassin;
+import org.apache.james.mailbox.spamassassin.SpamAssassinConfiguration;
+import org.apache.james.mailbox.spamassassin.SpamAssassinListener;
+import org.apache.james.mailbox.store.StoreMailboxManager;
+import org.apache.james.utils.ConfigurationPerformer;
+import org.apache.james.utils.PropertiesProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Throwables;
+import com.google.common.collect.ImmutableList;
+import com.google.inject.AbstractModule;
+import com.google.inject.Inject;
+import com.google.inject.Provides;
+import com.google.inject.multibindings.Multibinder;
+
+public class SpamAssassinListenerModule extends AbstractModule {
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(SpamAssassinListenerModule.class);
+
+    public static final String SPAMASSASSIN_CONFIGURATION_NAME = 
"spamassassin";
+
+    @Override
+    protected void configure() {
+        Multibinder.newSetBinder(binder(), 
ConfigurationPerformer.class).addBinding().to(SpamAssassinListenerConfigurationPerformer.class);
+    }
+    
+    @Singleton
+    public static class SpamAssassinListenerConfigurationPerformer implements 
ConfigurationPerformer {
+
+        private final SpamAssassinConfiguration spamAssassinConfiguration;
+        private final StoreMailboxManager storeMailboxManager;
+
+        @Inject
+        public 
SpamAssassinListenerConfigurationPerformer(SpamAssassinConfiguration 
spamAssassinConfiguration, StoreMailboxManager storeMailboxManager) {
+            this.spamAssassinConfiguration = spamAssassinConfiguration;
+            this.storeMailboxManager = storeMailboxManager;
+        }
+
+        @Override
+        public void initModule() {
+            try {
+                SpamAssassinListener spamAssassinListener = new 
SpamAssassinListener(new SpamAssassin(spamAssassinConfiguration));
+                MailboxSession session = null;
+                storeMailboxManager.addGlobalListener(spamAssassinListener, 
session);
+            } catch (MailboxException e) {
+                Throwables.propagate(e);
+            }
+        }
+
+        @Override
+        public List<Class<? extends Configurable>> forClasses() {
+            return ImmutableList.of();
+        }
+    }
+
+    @Provides
+    @Singleton
+    private SpamAssassinConfiguration 
getSpamAssassinConfiguration(PropertiesProvider propertiesProvider) throws 
ConfigurationException {
+        try {
+            PropertiesConfiguration configuration = 
propertiesProvider.getConfiguration(SPAMASSASSIN_CONFIGURATION_NAME);
+            return 
SpamAssassinConfigurationLoader.fromProperties(configuration);
+        } catch (FileNotFoundException e) {
+            LOGGER.warn("Could not find " + SPAMASSASSIN_CONFIGURATION_NAME + 
" configuration file. Disabling this service.");
+            return SpamAssassinConfigurationLoader.disable();
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/b92f3e94/server/container/guice/mailbox-plugin-spamassassin/src/test/java/org/apache/james/modules/spamassassin/SpamAssassinConfigurationLoaderTest.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/mailbox-plugin-spamassassin/src/test/java/org/apache/james/modules/spamassassin/SpamAssassinConfigurationLoaderTest.java
 
b/server/container/guice/mailbox-plugin-spamassassin/src/test/java/org/apache/james/modules/spamassassin/SpamAssassinConfigurationLoaderTest.java
new file mode 100644
index 0000000..81a3341
--- /dev/null
+++ 
b/server/container/guice/mailbox-plugin-spamassassin/src/test/java/org/apache/james/modules/spamassassin/SpamAssassinConfigurationLoaderTest.java
@@ -0,0 +1,60 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you 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.modules.spamassassin;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.james.mailbox.spamassassin.SpamAssassinConfiguration;
+import org.apache.james.modules.spamassassin.SpamAssassinConfigurationLoader;
+import org.apache.james.util.Host;
+import org.junit.Test;
+
+public class SpamAssassinConfigurationLoaderTest {
+
+    @Test
+    public void isEnableShouldReturnFalseWhenDisable() {
+        SpamAssassinConfiguration configuration = 
SpamAssassinConfigurationLoader.disable();
+        assertThat(configuration.isEnable()).isFalse();
+    }
+
+    @Test
+    public void isEnableShouldReturnTrueWhenEnable() throws Exception {
+        SpamAssassinConfiguration configuration = 
SpamAssassinConfigurationLoader.fromProperties(new PropertiesConfiguration());
+        assertThat(configuration.isEnable()).isTrue();
+    }
+
+    @Test
+    public void hostShouldReturnDefaultWhenConfigurationIsEmpty() throws 
Exception {
+        SpamAssassinConfiguration configuration = 
SpamAssassinConfigurationLoader.fromProperties(new PropertiesConfiguration());
+        
assertThat(configuration.getHost().get()).isEqualTo(Host.from(SpamAssassinConfigurationLoader.DEFAULT_HOST,
 SpamAssassinConfigurationLoader.DEFAULT_PORT));
+    }
+
+    @Test
+    public void hostShouldReturnCustomWhenConfigurationIsProvided() throws 
Exception {
+        PropertiesConfiguration propertiesConfiguration = new 
PropertiesConfiguration();
+        String host = "10.69.1.123";
+        propertiesConfiguration.addProperty("spamassassin.host", host);
+        int port = 1783;
+        propertiesConfiguration.addProperty("spamassassin.port", port);
+
+        SpamAssassinConfiguration configuration = 
SpamAssassinConfigurationLoader.fromProperties(propertiesConfiguration);
+        assertThat(configuration.getHost().get()).isEqualTo(Host.from(host, 
port));
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/b92f3e94/server/container/guice/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/guice/pom.xml b/server/container/guice/pom.xml
index 4b1dda7..346c5cf 100644
--- a/server/container/guice/pom.xml
+++ b/server/container/guice/pom.xml
@@ -44,6 +44,7 @@
         <module>jpa-guice</module>
         <module>jpa-smtp</module>
         <module>mailbox</module>
+        <module>mailbox-plugin-spamassassin</module>
         <module>mailet</module>
         <module>memory-guice</module>
         <module>onami</module>
@@ -108,6 +109,11 @@
             </dependency>
             <dependency>
                 <groupId>${project.groupId}</groupId>
+                
<artifactId>james-server-guice-mailbox-plugin-spamassassin</artifactId>
+                <version>${project.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>${project.groupId}</groupId>
                 <artifactId>james-server-guice-mailet</artifactId>
                 <version>${project.version}</version>
             </dependency>


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to