JAMES-1902 create jmap module

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

Branch: refs/heads/master
Commit: 3d0e2ae7163338870b09b6c3192be50759b8ffec
Parents: 5e965d8
Author: Antoine Duprat <adup...@linagora.com>
Authored: Tue Mar 7 11:12:53 2017 +0100
Committer: benwa <btell...@linagora.com>
Committed: Tue Mar 14 18:13:55 2017 +0700

----------------------------------------------------------------------
 mpt/impl/smtp/cassandra/pom.xml                 |  12 ++
 mpt/pom.xml                                     |   6 +
 server/container/guice/cassandra-guice/pom.xml  |   6 +
 .../modules/mailbox/CassandraMailboxModule.java |   4 +
 .../guice/cassandra-ldap-guice/pom.xml          |   6 +
 server/container/guice/configuration/pom.xml    |   8 +
 .../java/org/apache/james/utils/GuiceProbe.java |  22 ++
 .../apache/james/utils/PropertiesProvider.java  |  46 +++++
 server/container/guice/guice-common/pom.xml     |   8 +-
 .../main/java/org/apache/james/JmapServer.java  |  26 ---
 .../org/apache/james/jmap/JMAPCommonModule.java |  95 ---------
 .../java/org/apache/james/jmap/JMAPModule.java  | 142 -------------
 .../org/apache/james/jmap/MethodsModule.java    |  84 --------
 .../modules/protocols/JMAPServerModule.java     |  83 --------
 .../java/org/apache/james/utils/GuiceProbe.java |  22 --
 .../apache/james/utils/GuiceServerProbe.java    |   2 +-
 .../org/apache/james/utils/JmapGuiceProbe.java  |  78 -------
 .../apache/james/utils/PropertiesProvider.java  |  46 -----
 .../james/modules/TestJMAPServerModule.java     |  68 -------
 .../modules/mailbox/MemoryMailboxModule.java    |   4 +
 server/container/guice/pom.xml                  |  12 ++
 server/container/guice/protocols/jmap/pom.xml   | 203 +++++++++++++++++++
 .../main/java/org/apache/james/JmapServer.java  |  26 +++
 .../org/apache/james/jmap/JMAPCommonModule.java |  91 +++++++++
 .../java/org/apache/james/jmap/JMAPModule.java  | 142 +++++++++++++
 .../org/apache/james/jmap/MethodsModule.java    |  84 ++++++++
 .../modules/protocols/JMAPServerModule.java     |  83 ++++++++
 .../org/apache/james/utils/JmapGuiceProbe.java  |  78 +++++++
 .../james/jmap/MailetPreconditionTest.java      | 122 +++++++++++
 .../james/modules/TestJMAPServerModule.java     |  68 +++++++
 .../cassandra-jmap-integration-testing/pom.xml  |   6 +
 .../protocols/webadmin-integration-test/pom.xml |   6 +
 32 files changed, 1040 insertions(+), 649 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/3d0e2ae7/mpt/impl/smtp/cassandra/pom.xml
----------------------------------------------------------------------
diff --git a/mpt/impl/smtp/cassandra/pom.xml b/mpt/impl/smtp/cassandra/pom.xml
index 2ac1e1c..ad2afd7 100644
--- a/mpt/impl/smtp/cassandra/pom.xml
+++ b/mpt/impl/smtp/cassandra/pom.xml
@@ -189,6 +189,12 @@
                     <type>test-jar</type>
                 </dependency>
                 <dependency>
+                    <groupId>org.apache.james</groupId>
+                    <artifactId>james-server-guice-jmap</artifactId>
+                    <scope>test</scope>
+                    <type>test-jar</type>
+                </dependency>
+                <dependency>
                     <groupId>com.google.guava</groupId>
                     <artifactId>guava</artifactId>
                     <version>18.0</version>
@@ -288,6 +294,12 @@
                     <type>test-jar</type>
                 </dependency>
                 <dependency>
+                    <groupId>org.apache.james</groupId>
+                    <artifactId>james-server-guice-jmap</artifactId>
+                    <scope>test</scope>
+                    <type>test-jar</type>
+                </dependency>
+                <dependency>
                     <groupId>com.google.guava</groupId>
                     <artifactId>guava</artifactId>
                     <version>18.0</version>

http://git-wip-us.apache.org/repos/asf/james-project/blob/3d0e2ae7/mpt/pom.xml
----------------------------------------------------------------------
diff --git a/mpt/pom.xml b/mpt/pom.xml
index c8fdf5d..08450d8 100644
--- a/mpt/pom.xml
+++ b/mpt/pom.xml
@@ -315,6 +315,12 @@
             </dependency>
             <dependency>
                 <groupId>org.apache.james</groupId>
+                <artifactId>james-server-guice-jmap</artifactId>
+                <version>${project.version}</version>
+                <type>test-jar</type>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.james</groupId>
                 <artifactId>james-server-util-java8</artifactId>
                 <version>${project.version}</version>
                 <type>test-jar</type>

http://git-wip-us.apache.org/repos/asf/james-project/blob/3d0e2ae7/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 957f51d..65b2c2e 100644
--- a/server/container/guice/cassandra-guice/pom.xml
+++ b/server/container/guice/cassandra-guice/pom.xml
@@ -267,6 +267,12 @@
                 </dependency>
                 <dependency>
                     <groupId>${project.groupId}</groupId>
+                    <artifactId>james-server-guice-jmap</artifactId>
+                    <type>test-jar</type>
+                    <scope>test</scope>
+                </dependency>
+                <dependency>
+                    <groupId>${project.groupId}</groupId>
                     <artifactId>james-server-util-java8</artifactId>
                     <scope>test</scope>
                     <type>test-jar</type>

http://git-wip-us.apache.org/repos/asf/james-project/blob/3d0e2ae7/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java
 
b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java
index a6e6ac3..1ba4213 100644
--- 
a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java
+++ 
b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java
@@ -23,6 +23,7 @@ import javax.inject.Singleton;
 import org.apache.james.adapter.mailbox.store.UserRepositoryAuthenticator;
 import org.apache.james.adapter.mailbox.store.UserRepositoryAuthorizator;
 import org.apache.james.backends.cassandra.components.CassandraModule;
+import org.apache.james.mailbox.AttachmentManager;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxPathLocker;
 import org.apache.james.mailbox.MessageIdManager;
@@ -45,6 +46,7 @@ import org.apache.james.mailbox.store.Authenticator;
 import org.apache.james.mailbox.store.Authorizator;
 import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
 import org.apache.james.mailbox.store.NoMailboxPathLocker;
+import org.apache.james.mailbox.store.StoreAttachmentManager;
 import org.apache.james.mailbox.store.StoreMessageIdManager;
 import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.AttachmentMapperFactory;
@@ -87,6 +89,7 @@ public class CassandraMailboxModule extends AbstractModule {
         bind(CassandraMessageIdToImapUidDAO.class).in(Scopes.SINGLETON);
         bind(MailboxEventDispatcher.class).in(Scopes.SINGLETON);
         bind(StoreMessageIdManager.class).in(Scopes.SINGLETON);
+        bind(StoreAttachmentManager.class).in(Scopes.SINGLETON);
 
         
bind(MessageMapperFactory.class).to(CassandraMailboxSessionMapperFactory.class);
         
bind(MailboxMapperFactory.class).to(CassandraMailboxSessionMapperFactory.class);
@@ -103,6 +106,7 @@ public class CassandraMailboxModule extends AbstractModule {
         bind(MailboxId.Factory.class).to(CassandraId.Factory.class);
         bind(MessageId.Factory.class).to(CassandraMessageId.Factory.class);
         bind(MessageIdManager.class).to(StoreMessageIdManager.class);
+        bind(AttachmentManager.class).to(StoreAttachmentManager.class);
 
         Multibinder<CassandraModule> cassandraDataDefinitions = 
Multibinder.newSetBinder(binder(), CassandraModule.class);
         
cassandraDataDefinitions.addBinding().to(org.apache.james.mailbox.cassandra.modules.CassandraAclModule.class);

http://git-wip-us.apache.org/repos/asf/james-project/blob/3d0e2ae7/server/container/guice/cassandra-ldap-guice/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-ldap-guice/pom.xml 
b/server/container/guice/cassandra-ldap-guice/pom.xml
index 4ce7530..ca14cb8 100644
--- a/server/container/guice/cassandra-ldap-guice/pom.xml
+++ b/server/container/guice/cassandra-ldap-guice/pom.xml
@@ -238,6 +238,12 @@
                 </dependency>
                 <dependency>
                     <groupId>${project.groupId}</groupId>
+                    <artifactId>james-server-guice-jmap</artifactId>
+                    <type>test-jar</type>
+                    <scope>test</scope>
+                </dependency>
+                <dependency>
+                    <groupId>${project.groupId}</groupId>
                     <artifactId>james-server-util-java8</artifactId>
                     <scope>test</scope>
                     <type>test-jar</type>

http://git-wip-us.apache.org/repos/asf/james-project/blob/3d0e2ae7/server/container/guice/configuration/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/guice/configuration/pom.xml 
b/server/container/guice/configuration/pom.xml
index f535d43..eb2672f 100644
--- a/server/container/guice/configuration/pom.xml
+++ b/server/container/guice/configuration/pom.xml
@@ -133,8 +133,16 @@
             <dependencies>
                 <dependency>
                     <groupId>${project.groupId}</groupId>
+                    <artifactId>james-server-filesystem-api</artifactId>
+                </dependency>
+                <dependency>
+                    <groupId>${project.groupId}</groupId>
                     <artifactId>james-server-lifecycle-api</artifactId>
                 </dependency>
+                <dependency>
+                    <groupId>com.google.guava</groupId>
+                    <artifactId>guava</artifactId>
+                </dependency>
             </dependencies>
         </profile>
         <profile>

http://git-wip-us.apache.org/repos/asf/james-project/blob/3d0e2ae7/server/container/guice/configuration/src/main/java/org/apache/james/utils/GuiceProbe.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/configuration/src/main/java/org/apache/james/utils/GuiceProbe.java
 
b/server/container/guice/configuration/src/main/java/org/apache/james/utils/GuiceProbe.java
new file mode 100644
index 0000000..4d3b520
--- /dev/null
+++ 
b/server/container/guice/configuration/src/main/java/org/apache/james/utils/GuiceProbe.java
@@ -0,0 +1,22 @@
+/****************************************************************
+ * 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.utils;
+
+public interface GuiceProbe {
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/3d0e2ae7/server/container/guice/configuration/src/main/java/org/apache/james/utils/PropertiesProvider.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/configuration/src/main/java/org/apache/james/utils/PropertiesProvider.java
 
b/server/container/guice/configuration/src/main/java/org/apache/james/utils/PropertiesProvider.java
new file mode 100644
index 0000000..780b5ee
--- /dev/null
+++ 
b/server/container/guice/configuration/src/main/java/org/apache/james/utils/PropertiesProvider.java
@@ -0,0 +1,46 @@
+/****************************************************************
+ * 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.utils;
+
+import java.io.FileNotFoundException;
+
+import javax.inject.Inject;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.james.filesystem.api.FileSystem;
+
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+
+public class PropertiesProvider {
+
+    private final FileSystem fileSystem;
+
+    @Inject
+    public PropertiesProvider(FileSystem fileSystem) {
+        this.fileSystem = fileSystem;
+    }
+
+    public PropertiesConfiguration getConfiguration(String fileName) throws 
FileNotFoundException, ConfigurationException {
+        Preconditions.checkArgument(!Strings.isNullOrEmpty(fileName));
+        return new 
PropertiesConfiguration(fileSystem.getFile(FileSystem.FILE_PROTOCOL_AND_CONF + 
fileName + ".properties"));
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/3d0e2ae7/server/container/guice/guice-common/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/pom.xml 
b/server/container/guice/guice-common/pom.xml
index 6071182..d294ca2 100644
--- a/server/container/guice/guice-common/pom.xml
+++ b/server/container/guice/guice-common/pom.xml
@@ -181,6 +181,10 @@
                 </dependency>
                 <dependency>
                     <groupId>${project.groupId}</groupId>
+                    <artifactId>james-server-guice-jmap</artifactId>
+                </dependency>
+                <dependency>
+                    <groupId>${project.groupId}</groupId>
                     <artifactId>james-server-guice-lmtp</artifactId>
                 </dependency>
                 <dependency>
@@ -205,10 +209,6 @@
                 </dependency>
                 <dependency>
                     <groupId>${project.groupId}</groupId>
-                    <artifactId>james-server-jmap</artifactId>
-                </dependency>
-                <dependency>
-                    <groupId>${project.groupId}</groupId>
                     <artifactId>james-server-mailets</artifactId>
                 </dependency>
                 <dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/3d0e2ae7/server/container/guice/guice-common/src/main/java/org/apache/james/JmapServer.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/guice-common/src/main/java/org/apache/james/JmapServer.java
 
b/server/container/guice/guice-common/src/main/java/org/apache/james/JmapServer.java
deleted file mode 100644
index 218c879..0000000
--- 
a/server/container/guice/guice-common/src/main/java/org/apache/james/JmapServer.java
+++ /dev/null
@@ -1,26 +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;
-
-import org.apache.james.utils.JmapGuiceProbe;
-
-public interface JmapServer {
-    JmapGuiceProbe getJmapProbe();
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/3d0e2ae7/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPCommonModule.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPCommonModule.java
 
b/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPCommonModule.java
deleted file mode 100644
index c6bd8a3..0000000
--- 
a/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPCommonModule.java
+++ /dev/null
@@ -1,95 +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.jmap;
-
-import java.util.List;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.james.jmap.api.AccessTokenManager;
-import org.apache.james.jmap.api.SimpleTokenFactory;
-import org.apache.james.jmap.api.SimpleTokenManager;
-import org.apache.james.jmap.api.access.AccessTokenRepository;
-import org.apache.james.jmap.crypto.AccessTokenManagerImpl;
-import org.apache.james.jmap.crypto.JamesSignatureHandler;
-import org.apache.james.jmap.crypto.SignatureHandler;
-import org.apache.james.jmap.crypto.SignedTokenFactory;
-import org.apache.james.jmap.crypto.SignedTokenManager;
-import org.apache.james.jmap.model.MailboxFactory;
-import org.apache.james.jmap.model.MessageContentExtractor;
-import org.apache.james.jmap.model.MessageFactory;
-import org.apache.james.jmap.model.MessagePreviewGenerator;
-import org.apache.james.jmap.send.MailFactory;
-import org.apache.james.jmap.send.MailSpool;
-import org.apache.james.jmap.utils.HeadersAuthenticationExtractor;
-import org.apache.james.mailbox.AttachmentManager;
-import org.apache.james.mailbox.store.StoreAttachmentManager;
-import org.apache.james.util.date.DefaultZonedDateTimeProvider;
-import org.apache.james.util.date.ZonedDateTimeProvider;
-import org.apache.mailet.base.AutomaticallySentMailDetector;
-import org.apache.mailet.base.AutomaticallySentMailDetectorImpl;
-
-import com.google.common.collect.ImmutableList;
-import com.google.inject.AbstractModule;
-import com.google.inject.Provides;
-import com.google.inject.Scopes;
-import com.google.inject.name.Names;
-
-public class JMAPCommonModule extends AbstractModule {
-    
-    private static final long DEFAULT_TOKEN_EXPIRATION_IN_MS = 
TimeUnit.MILLISECONDS.convert(15, TimeUnit.MINUTES);
-
-    @Override
-    protected void configure() {
-        bind(JamesSignatureHandler.class).in(Scopes.SINGLETON);
-        bind(DefaultZonedDateTimeProvider.class).in(Scopes.SINGLETON);
-        bind(SignedTokenManager.class).in(Scopes.SINGLETON);
-        bind(AccessTokenManagerImpl.class).in(Scopes.SINGLETON);
-        bind(MailSpool.class).in(Scopes.SINGLETON);
-        bind(MailFactory.class).in(Scopes.SINGLETON);
-        bind(AutomaticallySentMailDetectorImpl.class).in(Scopes.SINGLETON);
-        bind(MailboxFactory.class).in(Scopes.SINGLETON);
-        bind(MessageFactory.class).in(Scopes.SINGLETON);
-        bind(MessagePreviewGenerator.class).in(Scopes.SINGLETON);
-        bind(MessageContentExtractor.class).in(Scopes.SINGLETON);
-        bind(HeadersAuthenticationExtractor.class).in(Scopes.SINGLETON);
-        bind(StoreAttachmentManager.class).in(Scopes.SINGLETON);
-
-        bind(SignatureHandler.class).to(JamesSignatureHandler.class);
-        
bind(ZonedDateTimeProvider.class).to(DefaultZonedDateTimeProvider.class);
-        bind(SimpleTokenManager.class).to(SignedTokenManager.class);
-        bind(SimpleTokenFactory.class).to(SignedTokenFactory.class);
-        
bind(AutomaticallySentMailDetector.class).to(AutomaticallySentMailDetectorImpl.class);
-
-        
bindConstant().annotatedWith(Names.named(AccessTokenRepository.TOKEN_EXPIRATION_IN_MS)).to(DEFAULT_TOKEN_EXPIRATION_IN_MS);
-        bind(AccessTokenManager.class).to(AccessTokenManagerImpl.class);
-        bind(AttachmentManager.class).to(StoreAttachmentManager.class);
-    }
-
-    @Provides
-    public List<AuthenticationStrategy> authStrategies(
-            AccessTokenAuthenticationStrategy 
accessTokenAuthenticationStrategy,
-            JWTAuthenticationStrategy jwtAuthenticationStrategy,
-            QueryParameterAccessTokenAuthenticationStrategy 
queryParameterAuthenticationStrategy) {
-
-        return ImmutableList.of(
-                jwtAuthenticationStrategy,
-                accessTokenAuthenticationStrategy,
-                queryParameterAuthenticationStrategy);
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/3d0e2ae7/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPModule.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPModule.java
 
b/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPModule.java
deleted file mode 100644
index 7269cb1..0000000
--- 
a/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPModule.java
+++ /dev/null
@@ -1,142 +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.jmap;
-
-import java.io.IOException;
-import java.util.EnumSet;
-import java.util.List;
-import java.util.Optional;
-
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.PropertiesConfiguration;
-import org.apache.commons.io.FileUtils;
-import org.apache.james.filesystem.api.FileSystem;
-import org.apache.james.jmap.mailet.VacationMailet;
-import org.apache.james.jmap.methods.RequestHandler;
-import org.apache.james.jmap.send.PostDequeueDecoratorFactory;
-import org.apache.james.jmap.utils.HtmlTextExtractor;
-import org.apache.james.jmap.utils.MailboxBasedHtmlTextExtractor;
-import org.apache.james.jmap.utils.SystemMailboxesProvider;
-import org.apache.james.jmap.utils.SystemMailboxesProviderImpl;
-import org.apache.james.lifecycle.api.Configurable;
-import org.apache.james.mailbox.MailboxManager;
-import org.apache.james.mailbox.MailboxManager.SearchCapabilities;
-import org.apache.james.mailetcontainer.impl.MatcherMailetPair;
-import org.apache.james.modules.server.CamelMailetContainerModule;
-import org.apache.james.queue.api.MailQueueItemDecoratorFactory;
-import org.apache.james.transport.matchers.RecipientIsLocal;
-import org.apache.james.utils.ConfigurationPerformer;
-import org.apache.james.utils.PropertiesProvider;
-
-import com.github.fge.lambdas.Throwing;
-import com.google.common.base.Preconditions;
-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.Scopes;
-import com.google.inject.Singleton;
-import com.google.inject.multibindings.Multibinder;
-
-public class JMAPModule extends AbstractModule {
-    private static final int DEFAULT_JMAP_PORT = 80;
-
-    @Override
-    protected void configure() {
-        install(new JMAPCommonModule());
-        install(new MethodsModule());
-        bind(JMAPServer.class).in(Scopes.SINGLETON);
-        bind(RequestHandler.class).in(Scopes.SINGLETON);
-        bind(UploadHandler.class).in(Scopes.SINGLETON);
-        bind(MailboxBasedHtmlTextExtractor.class).in(Scopes.SINGLETON);
-        bind(SystemMailboxesProviderImpl.class).in(Scopes.SINGLETON);
-
-        bind(HtmlTextExtractor.class).to(MailboxBasedHtmlTextExtractor.class);
-        Multibinder.newSetBinder(binder(), 
ConfigurationPerformer.class).addBinding().to(RequiredCapabilitiesPrecondition.class);
-
-        Multibinder<CamelMailetContainerModule.TransportProcessorCheck> 
transportProcessorChecks = Multibinder.newSetBinder(binder(), 
CamelMailetContainerModule.TransportProcessorCheck.class);
-        transportProcessorChecks.addBinding().to(VacationMailetCheck.class);
-        
-        
bind(SystemMailboxesProvider.class).to(SystemMailboxesProviderImpl.class);
-        
bind(MailQueueItemDecoratorFactory.class).to(PostDequeueDecoratorFactory.class).in(Scopes.SINGLETON);
-    }
-
-    @Provides
-    @Singleton
-    JMAPConfiguration provideConfiguration(PropertiesProvider 
propertiesProvider, FileSystem fileSystem) throws ConfigurationException, 
IOException{
-        PropertiesConfiguration configuration = 
propertiesProvider.getConfiguration("jmap");
-        return JMAPConfiguration.builder()
-                .keystore(configuration.getString("tls.keystoreURL"))
-                .secret(configuration.getString("tls.secret"))
-                .jwtPublicKeyPem(loadPublicKey(fileSystem, 
Optional.ofNullable(configuration.getString("jwt.publickeypem.url"))))
-                .port(configuration.getInt("jmap.port", DEFAULT_JMAP_PORT))
-                .build();
-    }
-
-    private Optional<String> loadPublicKey(FileSystem fileSystem, 
Optional<String> jwtPublickeyPemUrl) {
-        return jwtPublickeyPemUrl.map(Throwing.function(url -> 
FileUtils.readFileToString(fileSystem.getFile(url))));
-    }
-
-    @Singleton
-    public static class RequiredCapabilitiesPrecondition implements 
ConfigurationPerformer {
-
-        private final MailboxManager mailboxManager;
-
-        @Inject
-        public RequiredCapabilitiesPrecondition(MailboxManager mailboxManager) 
{
-            this.mailboxManager = mailboxManager;
-        }
-
-        @Override
-        public void initModule() {
-            
Preconditions.checkArgument(mailboxManager.hasCapability(MailboxManager.MailboxCapabilities.Move),
-                    "MOVE support in MailboxManager is required by JMAP 
Module");
-
-            EnumSet<MailboxManager.MessageCapabilities> messageCapabilities = 
mailboxManager.getSupportedMessageCapabilities();
-            
Preconditions.checkArgument(messageCapabilities.contains(MailboxManager.MessageCapabilities.Attachment),
-                    "Attachment support in MailboxManager is required by JMAP 
Module");
-            
Preconditions.checkArgument(messageCapabilities.contains(MailboxManager.MessageCapabilities.UniqueID),
-                    "MessageIdManager is not defined by this Mailbox 
implementation");
-
-            EnumSet<SearchCapabilities> searchCapabilities = 
mailboxManager.getSupportedSearchCapabilities();
-            
Preconditions.checkArgument(searchCapabilities.contains(MailboxManager.SearchCapabilities.MultimailboxSearch),
-                    "Multimailbox search in MailboxManager is required by JMAP 
Module");
-            
Preconditions.checkArgument(searchCapabilities.contains(MailboxManager.SearchCapabilities.Text),
-                    "Text support in MailboxManager is required by JMAP 
Module");
-        }
-
-        @Override
-        public List<Class<? extends Configurable>> forClasses() {
-            return ImmutableList.of();
-        }
-    }
-
-    public static class VacationMailetCheck implements 
CamelMailetContainerModule.TransportProcessorCheck {
-        @Override
-        public void check(List<MatcherMailetPair> pairs) throws 
ConfigurationException {
-            Preconditions.checkNotNull(pairs);
-            pairs.stream()
-                .filter(pair -> 
pair.getMailet().getClass().equals(VacationMailet.class))
-                .filter(pair -> 
pair.getMatcher().getClass().equals(RecipientIsLocal.class))
-                .findAny()
-                .orElseThrow(() -> new ConfigurationException("Missing " + 
VacationMailet.class.getName() + " in mailets configuration (mailetcontainer -> 
processors -> transport)"));
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/3d0e2ae7/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/MethodsModule.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/MethodsModule.java
 
b/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/MethodsModule.java
deleted file mode 100644
index 9feb897..0000000
--- 
a/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/MethodsModule.java
+++ /dev/null
@@ -1,84 +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.jmap;
-
-import org.apache.james.jmap.json.ObjectMapperFactory;
-import org.apache.james.jmap.methods.GetMailboxesMethod;
-import org.apache.james.jmap.methods.GetMessageListMethod;
-import org.apache.james.jmap.methods.GetMessagesMethod;
-import org.apache.james.jmap.methods.GetVacationResponseMethod;
-import org.apache.james.jmap.methods.JmapRequestParser;
-import org.apache.james.jmap.methods.JmapRequestParserImpl;
-import org.apache.james.jmap.methods.JmapResponseWriter;
-import org.apache.james.jmap.methods.JmapResponseWriterImpl;
-import org.apache.james.jmap.methods.Method;
-import org.apache.james.jmap.methods.SetMailboxesCreationProcessor;
-import org.apache.james.jmap.methods.SetMailboxesDestructionProcessor;
-import org.apache.james.jmap.methods.SetMailboxesMethod;
-import org.apache.james.jmap.methods.SetMailboxesProcessor;
-import org.apache.james.jmap.methods.SetMailboxesUpdateProcessor;
-import org.apache.james.jmap.methods.SetMessagesCreationProcessor;
-import org.apache.james.jmap.methods.SetMessagesDestructionProcessor;
-import org.apache.james.jmap.methods.SetMessagesMethod;
-import org.apache.james.jmap.methods.SetMessagesProcessor;
-import org.apache.james.jmap.methods.SetMessagesUpdateProcessor;
-import org.apache.james.jmap.methods.SetVacationResponseMethod;
-
-import com.google.inject.AbstractModule;
-import com.google.inject.Scopes;
-import com.google.inject.multibindings.Multibinder;
-import com.google.inject.name.Names;
-
-public class MethodsModule extends AbstractModule {
-
-    @Override
-    protected void configure() {
-        bind(JmapRequestParserImpl.class).in(Scopes.SINGLETON);
-        bind(JmapResponseWriterImpl.class).in(Scopes.SINGLETON);
-        bind(ObjectMapperFactory.class).in(Scopes.SINGLETON);
-
-        bind(JmapRequestParser.class).to(JmapRequestParserImpl.class);
-        bind(JmapResponseWriter.class).to(JmapResponseWriterImpl.class);
-
-        
bindConstant().annotatedWith(Names.named(GetMessageListMethod.MAXIMUM_LIMIT)).to(GetMessageListMethod.DEFAULT_MAXIMUM_LIMIT);
-
-        Multibinder<Method> methods = Multibinder.newSetBinder(binder(), 
Method.class);
-        methods.addBinding().to(GetMailboxesMethod.class);
-        methods.addBinding().to(GetMessageListMethod.class);
-        methods.addBinding().to(GetMessagesMethod.class);
-        methods.addBinding().to(SetMessagesMethod.class);
-        methods.addBinding().to(SetMailboxesMethod.class);
-        methods.addBinding().to(GetVacationResponseMethod.class);
-        methods.addBinding().to(SetVacationResponseMethod.class);
-
-        Multibinder<SetMailboxesProcessor> setMailboxesProcessor =
-            Multibinder.newSetBinder(binder(), SetMailboxesProcessor.class);
-        
setMailboxesProcessor.addBinding().to(SetMailboxesCreationProcessor.class);
-        
setMailboxesProcessor.addBinding().to(SetMailboxesUpdateProcessor.class);
-        
setMailboxesProcessor.addBinding().to(SetMailboxesDestructionProcessor.class);
-
-        Multibinder<SetMessagesProcessor> setMessagesProcessors =
-                Multibinder.newSetBinder(binder(), SetMessagesProcessor.class);
-        
setMessagesProcessors.addBinding().to(SetMessagesUpdateProcessor.class);
-        
setMessagesProcessors.addBinding().to(SetMessagesCreationProcessor.class);
-        
setMessagesProcessors.addBinding().to(SetMessagesDestructionProcessor.class);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/3d0e2ae7/server/container/guice/guice-common/src/main/java/org/apache/james/modules/protocols/JMAPServerModule.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/protocols/JMAPServerModule.java
 
b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/protocols/JMAPServerModule.java
deleted file mode 100644
index a04e1db..0000000
--- 
a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/protocols/JMAPServerModule.java
+++ /dev/null
@@ -1,83 +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.protocols;
-
-import java.security.Security;
-import java.util.List;
-
-import org.apache.james.jmap.JMAPModule;
-import org.apache.james.jmap.JMAPServer;
-import org.apache.james.jmap.crypto.JamesSignatureHandler;
-import org.apache.james.lifecycle.api.Configurable;
-import org.apache.james.utils.ConfigurationPerformer;
-import org.apache.james.utils.GuiceProbe;
-import org.apache.james.utils.JmapGuiceProbe;
-import org.bouncycastle.jce.provider.BouncyCastleProvider;
-
-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.Singleton;
-import com.google.inject.multibindings.Multibinder;
-
-public class JMAPServerModule extends AbstractModule {
-
-    @Override
-    protected void configure() {
-        install(new JMAPModule());
-        Multibinder.newSetBinder(binder(), 
ConfigurationPerformer.class).addBinding().to(JMAPModuleConfigurationPerformer.class);
-        Multibinder.newSetBinder(binder(), 
GuiceProbe.class).addBinding().to(JmapGuiceProbe.class);
-    }
-
-    @Singleton
-    public static class JMAPModuleConfigurationPerformer implements 
ConfigurationPerformer {
-
-        private final JMAPServer server;
-        private final JamesSignatureHandler signatureHandler;
-
-        @Inject
-        public JMAPModuleConfigurationPerformer(JMAPServer server, 
JamesSignatureHandler signatureHandler) {
-            this.server = server;
-            this.signatureHandler = signatureHandler;
-        }
-
-        @Override
-        public void initModule() {
-            try {
-                signatureHandler.init();
-                server.configure(null);
-                registerPEMWithSecurityProvider();
-            } catch (Exception e) {
-                Throwables.propagate(e);
-            }
-        }
-
-        private void registerPEMWithSecurityProvider() {
-            Security.addProvider(new BouncyCastleProvider());
-        }
-
-        @Override
-        public List<Class<? extends Configurable>> forClasses() {
-            return ImmutableList.of(JMAPServer.class);
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/3d0e2ae7/server/container/guice/guice-common/src/main/java/org/apache/james/utils/GuiceProbe.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/guice-common/src/main/java/org/apache/james/utils/GuiceProbe.java
 
b/server/container/guice/guice-common/src/main/java/org/apache/james/utils/GuiceProbe.java
deleted file mode 100644
index 4d3b520..0000000
--- 
a/server/container/guice/guice-common/src/main/java/org/apache/james/utils/GuiceProbe.java
+++ /dev/null
@@ -1,22 +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.utils;
-
-public interface GuiceProbe {
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/3d0e2ae7/server/container/guice/guice-common/src/main/java/org/apache/james/utils/GuiceServerProbe.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/guice-common/src/main/java/org/apache/james/utils/GuiceServerProbe.java
 
b/server/container/guice/guice-common/src/main/java/org/apache/james/utils/GuiceServerProbe.java
index fa28cd0..ec9bcc8 100644
--- 
a/server/container/guice/guice-common/src/main/java/org/apache/james/utils/GuiceServerProbe.java
+++ 
b/server/container/guice/guice-common/src/main/java/org/apache/james/utils/GuiceServerProbe.java
@@ -58,7 +58,7 @@ import com.google.common.collect.Iterables;
 
 public class GuiceServerProbe implements ExtendedServerProbe, GuiceProbe {
 
-    private static final Logger LOGGER = 
LoggerFactory.getLogger(JmapGuiceProbe.class);
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(GuiceServerProbe.class);
 
     private final MailboxManager mailboxManager;
     private final MailboxMapperFactory mailboxMapperFactory;

http://git-wip-us.apache.org/repos/asf/james-project/blob/3d0e2ae7/server/container/guice/guice-common/src/main/java/org/apache/james/utils/JmapGuiceProbe.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/guice-common/src/main/java/org/apache/james/utils/JmapGuiceProbe.java
 
b/server/container/guice/guice-common/src/main/java/org/apache/james/utils/JmapGuiceProbe.java
deleted file mode 100644
index 627d1c6..0000000
--- 
a/server/container/guice/guice-common/src/main/java/org/apache/james/utils/JmapGuiceProbe.java
+++ /dev/null
@@ -1,78 +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.utils;
-
-import java.util.Arrays;
-
-import javax.inject.Inject;
-
-import org.apache.james.jmap.JMAPServer;
-import org.apache.james.jmap.api.vacation.AccountId;
-import org.apache.james.jmap.api.vacation.Vacation;
-import org.apache.james.jmap.api.vacation.VacationPatch;
-import org.apache.james.jmap.api.vacation.VacationRepository;
-import org.apache.james.mailbox.MailboxListener;
-import org.apache.james.mailbox.MailboxManager;
-import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.MessageIdManager;
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.model.MailboxId;
-import org.apache.james.mailbox.model.MessageId;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class JmapGuiceProbe implements GuiceProbe {
-
-    private static final Logger LOGGER = 
LoggerFactory.getLogger(JmapGuiceProbe.class);
-
-    private final VacationRepository vacationRepository;
-    private final JMAPServer jmapServer;
-    private final MessageIdManager messageIdManager;
-    private final MailboxManager mailboxManager;
-
-    @Inject
-    private JmapGuiceProbe(VacationRepository vacationRepository, JMAPServer 
jmapServer, MessageIdManager messageIdManager, MailboxManager mailboxManager) {
-        this.vacationRepository = vacationRepository;
-        this.jmapServer = jmapServer;
-        this.messageIdManager = messageIdManager;
-        this.mailboxManager = mailboxManager;
-    }
-
-    public int getJmapPort() {
-        return jmapServer.getPort();
-    }
-
-    public void addMailboxListener(MailboxListener listener) throws 
MailboxException {
-        mailboxManager.addGlobalListener(listener, 
mailboxManager.createSystemSession("jmap", LOGGER));
-    }
-
-    public void modifyVacation(AccountId accountId, VacationPatch 
vacationPatch) {
-        vacationRepository.modifyVacation(accountId, vacationPatch).join();
-    }
-
-    public Vacation retrieveVacation(AccountId accountId) {
-        return vacationRepository.retrieveVacation(accountId).join();
-    }
-
-    public void setInMailboxes(MessageId messageId, String username, 
MailboxId... mailboxIds) throws MailboxException {
-        MailboxSession mailboxSession = 
mailboxManager.createSystemSession(username, LOGGER);
-        messageIdManager.setInMailboxes(messageId, Arrays.asList(mailboxIds), 
mailboxSession);
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/3d0e2ae7/server/container/guice/guice-common/src/main/java/org/apache/james/utils/PropertiesProvider.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/guice-common/src/main/java/org/apache/james/utils/PropertiesProvider.java
 
b/server/container/guice/guice-common/src/main/java/org/apache/james/utils/PropertiesProvider.java
deleted file mode 100644
index 780b5ee..0000000
--- 
a/server/container/guice/guice-common/src/main/java/org/apache/james/utils/PropertiesProvider.java
+++ /dev/null
@@ -1,46 +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.utils;
-
-import java.io.FileNotFoundException;
-
-import javax.inject.Inject;
-
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.PropertiesConfiguration;
-import org.apache.james.filesystem.api.FileSystem;
-
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
-
-public class PropertiesProvider {
-
-    private final FileSystem fileSystem;
-
-    @Inject
-    public PropertiesProvider(FileSystem fileSystem) {
-        this.fileSystem = fileSystem;
-    }
-
-    public PropertiesConfiguration getConfiguration(String fileName) throws 
FileNotFoundException, ConfigurationException {
-        Preconditions.checkArgument(!Strings.isNullOrEmpty(fileName));
-        return new 
PropertiesConfiguration(fileSystem.getFile(FileSystem.FILE_PROTOCOL_AND_CONF + 
fileName + ".properties"));
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/3d0e2ae7/server/container/guice/guice-common/src/test/java/org/apache/james/modules/TestJMAPServerModule.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/guice-common/src/test/java/org/apache/james/modules/TestJMAPServerModule.java
 
b/server/container/guice/guice-common/src/test/java/org/apache/james/modules/TestJMAPServerModule.java
deleted file mode 100644
index 6512fac..0000000
--- 
a/server/container/guice/guice-common/src/test/java/org/apache/james/modules/TestJMAPServerModule.java
+++ /dev/null
@@ -1,68 +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;
-
-import java.io.FileNotFoundException;
-import java.util.Optional;
-
-import javax.inject.Singleton;
-
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.james.jmap.JMAPConfiguration;
-import org.apache.james.jmap.methods.GetMessageListMethod;
-
-import com.google.inject.AbstractModule;
-import com.google.inject.Provides;
-import com.google.inject.name.Names;
-
-public class TestJMAPServerModule extends AbstractModule{
-
-    private static final String PUBLIC_PEM_KEY = "-----BEGIN PUBLIC 
KEY-----\n" +
-            
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtlChO/nlVP27MpdkG0Bh\n" +
-            
"16XrMRf6M4NeyGa7j5+1UKm42IKUf3lM28oe82MqIIRyvskPc11NuzSor8HmvH8H\n" +
-            
"lhDs5DyJtx2qp35AT0zCqfwlaDnlDc/QDlZv1CoRZGpQk1Inyh6SbZwYpxxwh0fi\n" +
-            
"+d/4RpE3LBVo8wgOaXPylOlHxsDizfkL8QwXItyakBfMO6jWQRrj7/9WDhGf4Hi+\n" +
-            
"GQur1tPGZDl9mvCoRHjFrD5M/yypIPlfMGWFVEvV5jClNMLAQ9bYFuOc7H1fEWw6\n" +
-            
"U1LZUUbJW9/CH45YXz82CYqkrfbnQxqRb2iVbVjs/sHopHd1NTiCfUtwvcYJiBVj\n" +
-            "kwIDAQAB\n" +
-            "-----END PUBLIC KEY-----";
-
-    private final int maximumLimit;
-
-    public TestJMAPServerModule(int maximumLimit) {
-        this.maximumLimit = maximumLimit;
-    }
-
-    @Override
-    protected void configure() {
-        
bindConstant().annotatedWith(Names.named(GetMessageListMethod.MAXIMUM_LIMIT)).to(maximumLimit);
-    }
-
-    @Provides
-    @Singleton
-    JMAPConfiguration provideConfiguration() throws FileNotFoundException, 
ConfigurationException{
-        return JMAPConfiguration.builder()
-                .keystore("keystore")
-                .secret("james72laBalle")
-                .jwtPublicKeyPem(Optional.of(PUBLIC_PEM_KEY))
-                .randomPort()
-                .build();
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/3d0e2ae7/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/mailbox/MemoryMailboxModule.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/mailbox/MemoryMailboxModule.java
 
b/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/mailbox/MemoryMailboxModule.java
index 09fd4f0..5716639 100644
--- 
a/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/mailbox/MemoryMailboxModule.java
+++ 
b/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/mailbox/MemoryMailboxModule.java
@@ -23,6 +23,7 @@ import javax.inject.Singleton;
 
 import org.apache.james.adapter.mailbox.store.UserRepositoryAuthenticator;
 import org.apache.james.adapter.mailbox.store.UserRepositoryAuthorizator;
+import org.apache.james.mailbox.AttachmentManager;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxPathLocker;
 import org.apache.james.mailbox.MessageIdManager;
@@ -47,6 +48,7 @@ import org.apache.james.mailbox.store.Authenticator;
 import org.apache.james.mailbox.store.Authorizator;
 import org.apache.james.mailbox.store.JVMMailboxPathLocker;
 import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
+import org.apache.james.mailbox.store.StoreAttachmentManager;
 import org.apache.james.mailbox.store.StoreSubscriptionManager;
 import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.AttachmentMapperFactory;
@@ -89,6 +91,7 @@ public class MemoryMailboxModule extends AbstractModule {
         bind(MessageIdManager.class).to(InMemoryMessageIdManager.class);
         bind(MailboxACLResolver.class).to(UnionMailboxACLResolver.class);
         
bind(GroupMembershipResolver.class).to(SimpleGroupMembershipResolver.class);
+        bind(AttachmentManager.class).to(StoreAttachmentManager.class);
 
         bind(MessageSearchIndex.class).to(SimpleMessageSearchIndex.class);
         bind(TextExtractor.class).to(JsoupTextExtractor.class);
@@ -106,6 +109,7 @@ public class MemoryMailboxModule extends AbstractModule {
         bind(InMemoryMessageId.Factory.class).in(Scopes.SINGLETON);
         bind(InMemoryMessageIdManager.class).in(Scopes.SINGLETON);
         bind(MailboxEventDispatcher.class).in(Scopes.SINGLETON);
+        bind(StoreAttachmentManager.class).in(Scopes.SINGLETON);
     }
 
     @Provides @Named(Names.MAILBOXMANAGER_NAME) @Singleton

http://git-wip-us.apache.org/repos/asf/james-project/blob/3d0e2ae7/server/container/guice/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/guice/pom.xml b/server/container/guice/pom.xml
index f762e63..44fdf85 100644
--- a/server/container/guice/pom.xml
+++ b/server/container/guice/pom.xml
@@ -46,6 +46,17 @@
             </dependency>
             <dependency>
                 <groupId>${project.groupId}</groupId>
+                <artifactId>james-server-guice-jmap</artifactId>
+                <version>3.0.0-beta6-SNAPSHOT</version>
+            </dependency>
+            <dependency>
+                <groupId>${project.groupId}</groupId>
+                <artifactId>james-server-guice-jmap</artifactId>
+                <version>3.0.0-beta6-SNAPSHOT</version>
+                <type>test-jar</type>
+            </dependency>
+            <dependency>
+                <groupId>${project.groupId}</groupId>
                 <artifactId>james-server-guice-lmtp</artifactId>
                 <version>3.0.0-beta6-SNAPSHOT</version>
             </dependency>
@@ -88,6 +99,7 @@
         <module>jpa-guice</module>
         <module>onami</module>
         <module>protocols/imap</module>
+        <module>protocols/jmap</module>
         <module>protocols/lmtp</module>
         <module>protocols/managedsieve</module>
         <module>protocols/pop</module>

http://git-wip-us.apache.org/repos/asf/james-project/blob/3d0e2ae7/server/container/guice/protocols/jmap/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/guice/protocols/jmap/pom.xml 
b/server/container/guice/protocols/jmap/pom.xml
new file mode 100644
index 0000000..b9f9d75
--- /dev/null
+++ b/server/container/guice/protocols/jmap/pom.xml
@@ -0,0 +1,203 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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";>
+    <parent>
+        <artifactId>james-server-guice</artifactId>
+        <groupId>org.apache.james</groupId>
+        <version>3.0.0-beta6-SNAPSHOT</version>
+        <relativePath>../../pom.xml</relativePath>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>james-server-guice-jmap</artifactId>
+
+    <name>Apache James :: Server :: Guice :: Jmap</name>
+    <description>Jmap modules for Guice implementation of James 
server</description>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+            </plugin>
+        </plugins>
+    </build>
+
+    <profiles>
+        <profile>
+            <id>disable-build-for-older-jdk</id>
+            <activation>
+                <jdk>(,1.8)</jdk>
+            </activation>
+            <build>
+                <plugins>
+                    <plugin>
+                        <artifactId>maven-jar-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>default-jar</id>
+                                <phase>none</phase>
+                            </execution>
+                            <execution>
+                                <id>jar</id>
+                                <phase>none</phase>
+                            </execution>
+                            <execution>
+                                <id>test-jar</id>
+                                <phase>none</phase>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    <plugin>
+                        <artifactId>maven-compiler-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>default-compile</id>
+                                <phase>none</phase>
+                            </execution>
+                            <execution>
+                                <id>default-testCompile</id>
+                                <phase>none</phase>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    <plugin>
+                        <artifactId>maven-surefire-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>default-test</id>
+                                <phase>none</phase>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    <plugin>
+                        <artifactId>maven-source-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>attach-sources</id>
+                                <phase>none</phase>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    <plugin>
+                        <artifactId>maven-install-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>default-install</id>
+                                <phase>none</phase>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    <plugin>
+                        <artifactId>maven-resources-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>default-resources</id>
+                                <phase>none</phase>
+                            </execution>
+                            <execution>
+                                <id>default-testResources</id>
+                                <phase>none</phase>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    <plugin>
+                        <artifactId>maven-site-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>attach-descriptor</id>
+                                <phase>none</phase>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+        <profile>
+            <id>build-for-jdk-8</id>
+            <activation>
+                <jdk>[1.8,)</jdk>
+            </activation>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-compiler-plugin</artifactId>
+                        <configuration>
+                            <source>1.8</source>
+                            <target>1.8</target>
+                        </configuration>
+                    </plugin>
+                </plugins>
+            </build>
+            <dependencies>
+                <dependency>
+                    <groupId>${project.groupId}</groupId>
+                    <artifactId>apache-mailet-base</artifactId>
+                </dependency>
+                <dependency>
+                    <groupId>${project.groupId}</groupId>
+                    <artifactId>apache-mailet-base</artifactId>
+                    <type>test-jar</type>
+                    <scope>test</scope>
+                </dependency>
+                <dependency>
+                    <groupId>${project.groupId}</groupId>
+                    <artifactId>james-server-guice-configuration</artifactId>
+                </dependency>
+                <dependency>
+                    <groupId>${project.groupId}</groupId>
+                    <artifactId>james-server-guice-mailet</artifactId>
+                </dependency>
+                <dependency>
+                    <groupId>${project.groupId}</groupId>
+                    <artifactId>james-server-jmap</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>junit</groupId>
+                    <artifactId>junit</artifactId>
+                    <scope>test</scope>
+                </dependency>
+            </dependencies>
+        </profile>
+        <profile>
+            <id>animal-sniffer-java-8</id>
+            <activation>
+                <jdk>[1.8,)</jdk>
+            </activation>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.codehaus.mojo</groupId>
+                        <artifactId>animal-sniffer-maven-plugin</artifactId>
+                        <configuration>
+                            <signature>
+                                <groupId>org.codehaus.mojo.signature</groupId>
+                                <artifactId>java18</artifactId>
+                                <version>1.0</version>
+                            </signature>
+                        </configuration>
+                        <executions>
+                            <execution>
+                                <id>check_java_8</id>
+                                <phase>test</phase>
+                                <goals>
+                                    <goal>check</goal>
+                                </goals>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
+
+</project>

http://git-wip-us.apache.org/repos/asf/james-project/blob/3d0e2ae7/server/container/guice/protocols/jmap/src/main/java/org/apache/james/JmapServer.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/protocols/jmap/src/main/java/org/apache/james/JmapServer.java
 
b/server/container/guice/protocols/jmap/src/main/java/org/apache/james/JmapServer.java
new file mode 100644
index 0000000..218c879
--- /dev/null
+++ 
b/server/container/guice/protocols/jmap/src/main/java/org/apache/james/JmapServer.java
@@ -0,0 +1,26 @@
+/****************************************************************
+ * 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;
+
+import org.apache.james.utils.JmapGuiceProbe;
+
+public interface JmapServer {
+    JmapGuiceProbe getJmapProbe();
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/3d0e2ae7/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPCommonModule.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPCommonModule.java
 
b/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPCommonModule.java
new file mode 100644
index 0000000..c9d7678
--- /dev/null
+++ 
b/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPCommonModule.java
@@ -0,0 +1,91 @@
+/****************************************************************
+ * 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.jmap;
+
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.james.jmap.api.AccessTokenManager;
+import org.apache.james.jmap.api.SimpleTokenFactory;
+import org.apache.james.jmap.api.SimpleTokenManager;
+import org.apache.james.jmap.api.access.AccessTokenRepository;
+import org.apache.james.jmap.crypto.AccessTokenManagerImpl;
+import org.apache.james.jmap.crypto.JamesSignatureHandler;
+import org.apache.james.jmap.crypto.SignatureHandler;
+import org.apache.james.jmap.crypto.SignedTokenFactory;
+import org.apache.james.jmap.crypto.SignedTokenManager;
+import org.apache.james.jmap.model.MailboxFactory;
+import org.apache.james.jmap.model.MessageContentExtractor;
+import org.apache.james.jmap.model.MessageFactory;
+import org.apache.james.jmap.model.MessagePreviewGenerator;
+import org.apache.james.jmap.send.MailFactory;
+import org.apache.james.jmap.send.MailSpool;
+import org.apache.james.jmap.utils.HeadersAuthenticationExtractor;
+import org.apache.james.util.date.DefaultZonedDateTimeProvider;
+import org.apache.james.util.date.ZonedDateTimeProvider;
+import org.apache.mailet.base.AutomaticallySentMailDetector;
+import org.apache.mailet.base.AutomaticallySentMailDetectorImpl;
+
+import com.google.common.collect.ImmutableList;
+import com.google.inject.AbstractModule;
+import com.google.inject.Provides;
+import com.google.inject.Scopes;
+import com.google.inject.name.Names;
+
+public class JMAPCommonModule extends AbstractModule {
+    
+    private static final long DEFAULT_TOKEN_EXPIRATION_IN_MS = 
TimeUnit.MILLISECONDS.convert(15, TimeUnit.MINUTES);
+
+    @Override
+    protected void configure() {
+        bind(JamesSignatureHandler.class).in(Scopes.SINGLETON);
+        bind(DefaultZonedDateTimeProvider.class).in(Scopes.SINGLETON);
+        bind(SignedTokenManager.class).in(Scopes.SINGLETON);
+        bind(AccessTokenManagerImpl.class).in(Scopes.SINGLETON);
+        bind(MailSpool.class).in(Scopes.SINGLETON);
+        bind(MailFactory.class).in(Scopes.SINGLETON);
+        bind(AutomaticallySentMailDetectorImpl.class).in(Scopes.SINGLETON);
+        bind(MailboxFactory.class).in(Scopes.SINGLETON);
+        bind(MessageFactory.class).in(Scopes.SINGLETON);
+        bind(MessagePreviewGenerator.class).in(Scopes.SINGLETON);
+        bind(MessageContentExtractor.class).in(Scopes.SINGLETON);
+        bind(HeadersAuthenticationExtractor.class).in(Scopes.SINGLETON);
+
+        bind(SignatureHandler.class).to(JamesSignatureHandler.class);
+        
bind(ZonedDateTimeProvider.class).to(DefaultZonedDateTimeProvider.class);
+        bind(SimpleTokenManager.class).to(SignedTokenManager.class);
+        bind(SimpleTokenFactory.class).to(SignedTokenFactory.class);
+        
bind(AutomaticallySentMailDetector.class).to(AutomaticallySentMailDetectorImpl.class);
+
+        
bindConstant().annotatedWith(Names.named(AccessTokenRepository.TOKEN_EXPIRATION_IN_MS)).to(DEFAULT_TOKEN_EXPIRATION_IN_MS);
+        bind(AccessTokenManager.class).to(AccessTokenManagerImpl.class);
+    }
+
+    @Provides
+    public List<AuthenticationStrategy> authStrategies(
+            AccessTokenAuthenticationStrategy 
accessTokenAuthenticationStrategy,
+            JWTAuthenticationStrategy jwtAuthenticationStrategy,
+            QueryParameterAccessTokenAuthenticationStrategy 
queryParameterAuthenticationStrategy) {
+
+        return ImmutableList.of(
+                jwtAuthenticationStrategy,
+                accessTokenAuthenticationStrategy,
+                queryParameterAuthenticationStrategy);
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/3d0e2ae7/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPModule.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPModule.java
 
b/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPModule.java
new file mode 100644
index 0000000..7269cb1
--- /dev/null
+++ 
b/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPModule.java
@@ -0,0 +1,142 @@
+/****************************************************************
+ * 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.jmap;
+
+import java.io.IOException;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.Optional;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.commons.io.FileUtils;
+import org.apache.james.filesystem.api.FileSystem;
+import org.apache.james.jmap.mailet.VacationMailet;
+import org.apache.james.jmap.methods.RequestHandler;
+import org.apache.james.jmap.send.PostDequeueDecoratorFactory;
+import org.apache.james.jmap.utils.HtmlTextExtractor;
+import org.apache.james.jmap.utils.MailboxBasedHtmlTextExtractor;
+import org.apache.james.jmap.utils.SystemMailboxesProvider;
+import org.apache.james.jmap.utils.SystemMailboxesProviderImpl;
+import org.apache.james.lifecycle.api.Configurable;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxManager.SearchCapabilities;
+import org.apache.james.mailetcontainer.impl.MatcherMailetPair;
+import org.apache.james.modules.server.CamelMailetContainerModule;
+import org.apache.james.queue.api.MailQueueItemDecoratorFactory;
+import org.apache.james.transport.matchers.RecipientIsLocal;
+import org.apache.james.utils.ConfigurationPerformer;
+import org.apache.james.utils.PropertiesProvider;
+
+import com.github.fge.lambdas.Throwing;
+import com.google.common.base.Preconditions;
+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.Scopes;
+import com.google.inject.Singleton;
+import com.google.inject.multibindings.Multibinder;
+
+public class JMAPModule extends AbstractModule {
+    private static final int DEFAULT_JMAP_PORT = 80;
+
+    @Override
+    protected void configure() {
+        install(new JMAPCommonModule());
+        install(new MethodsModule());
+        bind(JMAPServer.class).in(Scopes.SINGLETON);
+        bind(RequestHandler.class).in(Scopes.SINGLETON);
+        bind(UploadHandler.class).in(Scopes.SINGLETON);
+        bind(MailboxBasedHtmlTextExtractor.class).in(Scopes.SINGLETON);
+        bind(SystemMailboxesProviderImpl.class).in(Scopes.SINGLETON);
+
+        bind(HtmlTextExtractor.class).to(MailboxBasedHtmlTextExtractor.class);
+        Multibinder.newSetBinder(binder(), 
ConfigurationPerformer.class).addBinding().to(RequiredCapabilitiesPrecondition.class);
+
+        Multibinder<CamelMailetContainerModule.TransportProcessorCheck> 
transportProcessorChecks = Multibinder.newSetBinder(binder(), 
CamelMailetContainerModule.TransportProcessorCheck.class);
+        transportProcessorChecks.addBinding().to(VacationMailetCheck.class);
+        
+        
bind(SystemMailboxesProvider.class).to(SystemMailboxesProviderImpl.class);
+        
bind(MailQueueItemDecoratorFactory.class).to(PostDequeueDecoratorFactory.class).in(Scopes.SINGLETON);
+    }
+
+    @Provides
+    @Singleton
+    JMAPConfiguration provideConfiguration(PropertiesProvider 
propertiesProvider, FileSystem fileSystem) throws ConfigurationException, 
IOException{
+        PropertiesConfiguration configuration = 
propertiesProvider.getConfiguration("jmap");
+        return JMAPConfiguration.builder()
+                .keystore(configuration.getString("tls.keystoreURL"))
+                .secret(configuration.getString("tls.secret"))
+                .jwtPublicKeyPem(loadPublicKey(fileSystem, 
Optional.ofNullable(configuration.getString("jwt.publickeypem.url"))))
+                .port(configuration.getInt("jmap.port", DEFAULT_JMAP_PORT))
+                .build();
+    }
+
+    private Optional<String> loadPublicKey(FileSystem fileSystem, 
Optional<String> jwtPublickeyPemUrl) {
+        return jwtPublickeyPemUrl.map(Throwing.function(url -> 
FileUtils.readFileToString(fileSystem.getFile(url))));
+    }
+
+    @Singleton
+    public static class RequiredCapabilitiesPrecondition implements 
ConfigurationPerformer {
+
+        private final MailboxManager mailboxManager;
+
+        @Inject
+        public RequiredCapabilitiesPrecondition(MailboxManager mailboxManager) 
{
+            this.mailboxManager = mailboxManager;
+        }
+
+        @Override
+        public void initModule() {
+            
Preconditions.checkArgument(mailboxManager.hasCapability(MailboxManager.MailboxCapabilities.Move),
+                    "MOVE support in MailboxManager is required by JMAP 
Module");
+
+            EnumSet<MailboxManager.MessageCapabilities> messageCapabilities = 
mailboxManager.getSupportedMessageCapabilities();
+            
Preconditions.checkArgument(messageCapabilities.contains(MailboxManager.MessageCapabilities.Attachment),
+                    "Attachment support in MailboxManager is required by JMAP 
Module");
+            
Preconditions.checkArgument(messageCapabilities.contains(MailboxManager.MessageCapabilities.UniqueID),
+                    "MessageIdManager is not defined by this Mailbox 
implementation");
+
+            EnumSet<SearchCapabilities> searchCapabilities = 
mailboxManager.getSupportedSearchCapabilities();
+            
Preconditions.checkArgument(searchCapabilities.contains(MailboxManager.SearchCapabilities.MultimailboxSearch),
+                    "Multimailbox search in MailboxManager is required by JMAP 
Module");
+            
Preconditions.checkArgument(searchCapabilities.contains(MailboxManager.SearchCapabilities.Text),
+                    "Text support in MailboxManager is required by JMAP 
Module");
+        }
+
+        @Override
+        public List<Class<? extends Configurable>> forClasses() {
+            return ImmutableList.of();
+        }
+    }
+
+    public static class VacationMailetCheck implements 
CamelMailetContainerModule.TransportProcessorCheck {
+        @Override
+        public void check(List<MatcherMailetPair> pairs) throws 
ConfigurationException {
+            Preconditions.checkNotNull(pairs);
+            pairs.stream()
+                .filter(pair -> 
pair.getMailet().getClass().equals(VacationMailet.class))
+                .filter(pair -> 
pair.getMatcher().getClass().equals(RecipientIsLocal.class))
+                .findAny()
+                .orElseThrow(() -> new ConfigurationException("Missing " + 
VacationMailet.class.getName() + " in mailets configuration (mailetcontainer -> 
processors -> transport)"));
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/3d0e2ae7/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/MethodsModule.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/MethodsModule.java
 
b/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/MethodsModule.java
new file mode 100644
index 0000000..9feb897
--- /dev/null
+++ 
b/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/MethodsModule.java
@@ -0,0 +1,84 @@
+/****************************************************************
+ * 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.jmap;
+
+import org.apache.james.jmap.json.ObjectMapperFactory;
+import org.apache.james.jmap.methods.GetMailboxesMethod;
+import org.apache.james.jmap.methods.GetMessageListMethod;
+import org.apache.james.jmap.methods.GetMessagesMethod;
+import org.apache.james.jmap.methods.GetVacationResponseMethod;
+import org.apache.james.jmap.methods.JmapRequestParser;
+import org.apache.james.jmap.methods.JmapRequestParserImpl;
+import org.apache.james.jmap.methods.JmapResponseWriter;
+import org.apache.james.jmap.methods.JmapResponseWriterImpl;
+import org.apache.james.jmap.methods.Method;
+import org.apache.james.jmap.methods.SetMailboxesCreationProcessor;
+import org.apache.james.jmap.methods.SetMailboxesDestructionProcessor;
+import org.apache.james.jmap.methods.SetMailboxesMethod;
+import org.apache.james.jmap.methods.SetMailboxesProcessor;
+import org.apache.james.jmap.methods.SetMailboxesUpdateProcessor;
+import org.apache.james.jmap.methods.SetMessagesCreationProcessor;
+import org.apache.james.jmap.methods.SetMessagesDestructionProcessor;
+import org.apache.james.jmap.methods.SetMessagesMethod;
+import org.apache.james.jmap.methods.SetMessagesProcessor;
+import org.apache.james.jmap.methods.SetMessagesUpdateProcessor;
+import org.apache.james.jmap.methods.SetVacationResponseMethod;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Scopes;
+import com.google.inject.multibindings.Multibinder;
+import com.google.inject.name.Names;
+
+public class MethodsModule extends AbstractModule {
+
+    @Override
+    protected void configure() {
+        bind(JmapRequestParserImpl.class).in(Scopes.SINGLETON);
+        bind(JmapResponseWriterImpl.class).in(Scopes.SINGLETON);
+        bind(ObjectMapperFactory.class).in(Scopes.SINGLETON);
+
+        bind(JmapRequestParser.class).to(JmapRequestParserImpl.class);
+        bind(JmapResponseWriter.class).to(JmapResponseWriterImpl.class);
+
+        
bindConstant().annotatedWith(Names.named(GetMessageListMethod.MAXIMUM_LIMIT)).to(GetMessageListMethod.DEFAULT_MAXIMUM_LIMIT);
+
+        Multibinder<Method> methods = Multibinder.newSetBinder(binder(), 
Method.class);
+        methods.addBinding().to(GetMailboxesMethod.class);
+        methods.addBinding().to(GetMessageListMethod.class);
+        methods.addBinding().to(GetMessagesMethod.class);
+        methods.addBinding().to(SetMessagesMethod.class);
+        methods.addBinding().to(SetMailboxesMethod.class);
+        methods.addBinding().to(GetVacationResponseMethod.class);
+        methods.addBinding().to(SetVacationResponseMethod.class);
+
+        Multibinder<SetMailboxesProcessor> setMailboxesProcessor =
+            Multibinder.newSetBinder(binder(), SetMailboxesProcessor.class);
+        
setMailboxesProcessor.addBinding().to(SetMailboxesCreationProcessor.class);
+        
setMailboxesProcessor.addBinding().to(SetMailboxesUpdateProcessor.class);
+        
setMailboxesProcessor.addBinding().to(SetMailboxesDestructionProcessor.class);
+
+        Multibinder<SetMessagesProcessor> setMessagesProcessors =
+                Multibinder.newSetBinder(binder(), SetMessagesProcessor.class);
+        
setMessagesProcessors.addBinding().to(SetMessagesUpdateProcessor.class);
+        
setMessagesProcessors.addBinding().to(SetMessagesCreationProcessor.class);
+        
setMessagesProcessors.addBinding().to(SetMessagesDestructionProcessor.class);
+    }
+
+}


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

Reply via email to