You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2018/07/05 02:01:23 UTC

[01/13] james-project git commit: JAMES-2435 Adding SPF how to...

Repository: james-project
Updated Branches:
  refs/heads/master 5c7ac5122 -> 9d023beae


JAMES-2435 Adding SPF how to...


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

Branch: refs/heads/master
Commit: d261aef277235bcf290c03d456c76f0e599c3121
Parents: 644ea0f
Author: benwa <bt...@linagora.com>
Authored: Thu Jun 21 14:41:37 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jul 4 17:26:18 2018 +0700

----------------------------------------------------------------------
 src/homepage/howTo/index.html |  30 +----
 src/homepage/howTo/spf.html   | 233 +++++++++++++++++++++++++++++++++++++
 2 files changed, 237 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/d261aef2/src/homepage/howTo/index.html
----------------------------------------------------------------------
diff --git a/src/homepage/howTo/index.html b/src/homepage/howTo/index.html
index ff64620..127ba6a 100644
--- a/src/homepage/howTo/index.html
+++ b/src/homepage/howTo/index.html
@@ -69,39 +69,17 @@ layout: default
                  class="james-schema" >
                 <span class="fa fa-sitemap"></span>Setting up an IMAP server<span class="fa fa-long-arrow-right"></span>
               </a>
-              <a href="testing.html"
+              <a href="spf.html"
                  data-lightbox="james-schema"
-                 data-title="Testing with James"
-                 alt="Testing with James"
+                 data-title="Configuring SPF"
+                 alt="Configuring SPF"
                  class="james-schema" >
-                <span class="fa fa-sitemap"></span>Testing with James<span class="fa fa-long-arrow-right"></span>
+                <span class="fa fa-sitemap"></span>Configuring SPF<span class="fa fa-long-arrow-right"></span>
               </a>
 
               <br/>
               <br/>
 
-              <a href="spam-assassin.html"
-                 data-lightbox="james-schema"
-                 data-title="Spam Assassin integration"
-                 alt="Spam Assassin integration"
-                 class="james-schema" >
-                <span class="fa fa-sitemap"></span>Spam Assassin integration<span class="fa fa-long-arrow-right"></span>
-              </a>
-              <a href="mail-processing-how-to.html"
-                 data-lightbox="james-schema"
-                 data-title="Using a SMTP gateway"
-                 alt="Using a SMTP gateway"
-                 class="james-schema" >
-                <span class="fa fa-sitemap"></span>Using a SMTP gateway<span class="fa fa-long-arrow-right"></span>
-              </a>
-              <a href="mail-processing-how-to.html"
-                 data-lightbox="james-schema"
-                 data-title="Testing with James"
-                 alt="Testing with James"
-                 class="james-schema" >
-                <span class="fa fa-sitemap"></span>Testing with James<span class="fa fa-long-arrow-right"></span>
-              </a>
-
             </div>
           </div>
         </section>

http://git-wip-us.apache.org/repos/asf/james-project/blob/d261aef2/src/homepage/howTo/spf.html
----------------------------------------------------------------------
diff --git a/src/homepage/howTo/spf.html b/src/homepage/howTo/spf.html
new file mode 100644
index 0000000..a0b69e9
--- /dev/null
+++ b/src/homepage/howTo/spf.html
@@ -0,0 +1,233 @@
+---
+layout: default
+---
+<!--
+    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.
+-->
+<link href="assets/css/lightbox.css" rel="stylesheet">
+<link href="assets/css/lity.min.css" rel="stylesheet" />
+<div id="wrapper">
+    <div class="apache_ref">
+        <a href="https://www.apache.org" alt="apache foundation link"><img src="https://www.apache.org/foundation/press/kit/asf_logo.svg" title="apache foundation logo"/></a>
+    </div>
+    <div class="apache_ref_mobile">
+        <a href="https://www.apache.org" alt="apache foundation link">The Apache Software Foundation</a>
+    </div>
+    <div class="apache_ref_left">
+        <a href="https://www.apache.org/events/current-event.html" alt="apache foundation event"><img src="https://www.apache.org/events/current-event-234x60.png" title="apache foundation event logo"/></a>
+    </div>
+    <div class="apache_ref_left_mobile">
+        <a href="https://www.apache.org/events/current-event.html" alt="apache foundation event"><img src="https://www.apache.org/events/current-event-234x60.png" title="apache foundation event logo"/></a>
+    </div>
+
+    <!-- Header -->
+    <header id="header" class="alt">
+        <div class="logo"><a href="/index.html" alt="Apache James"><img src="/images/james.svg" alt="james logo"/></a></div>
+        <h1 class="hidden">James Enterprise Mail Server</h1>
+        <h2>Emails at the heart of your business logic</h2>
+    </header>
+
+    <!-- Main -->
+    <div id="main">
+
+        <!-- Introduction -->
+        <section id="intro" class="main special">
+            <div class="">
+                <div class="content align-left">
+                    <header class="major">
+                        <h1><b>Setting up SPF</b></h1>
+                    </header>
+
+                    <p>
+                        You just finished installing a <a href="imap-server.html">James IMAP server</a> and wonder how to
+                        gain trust for it?
+                    </p>
+
+                    <p>
+                        The Sender Policy Framework (SPF) is an open standard specifying a technical method to prevent
+                        sender address forgery, might help you to do this.
+                    </p>
+
+                    <p>
+                        More precisely, SPF protects the envelope sender address, which is used for the delivery of messages.
+                        It allows the owner of a domain to specify their mail sending policy, e.g. which mail servers they
+                        use to send emails from their domain.
+                    </p>
+
+                    <p>
+                        To correctly configure SPF for your domain, you need to answer the following questions:
+                    </p>
+
+                    <ul>
+                        <li><b>From what server or servers will email from my domain originate?</b> In our case, we only
+                            want our James Server to be able to send emails from our domain.</li>
+                        <li><b>How do you want illegitimate email to be handled?</b> <code>-all</code> is an SPF fail and
+                            usually means dropping such emails, whereas <code>~all</code> is an SPF softfail and traditionally
+                            means accepting but marking them.</li>
+                    </ul>
+
+                    <p>
+                        Therefore, we add the following DNS records to our DNS zone file:
+                    </p>
+
+                    <pre><code>@ IN TXT “v=spf1 +a:james.test-domain.com -all”
+@ IN SPF “v=spf1 +a:james.test-domain.com -all”</code></pre>
+
+                    <p>That way other mail servers knows only <i>james.test-domain.com</i> can send mails for <i>test-domain.com</i>.</p>
+
+
+                    <header class="major">
+                        <h1><b>Verifying SPF for incoming emails</b></h1>
+                    </header>
+
+                    <p>
+                        Now we will see how to verify SPF records of incoming emails. For this we can customize mail processing,
+                        and specify actions upon SPF record validity. For introducing these components, James relies on the
+                        <a href="https://james.apache.org/jspf/">JSPF</a>library.
+                    </p>
+
+                    <p>We just need to edit the <code>mailetcontainer.xml</code> configuration file as follow:</p>
+
+                    <p>We are going to create a new processor called <b>SPFProcessor</b>. It will handle emails after
+                        the <b>root</b> processor but before the <b>transport</b> processor. Moreover, we do not need to
+                        perform a SPF check or take a decision if the sender is authenticated or is a local user, because
+                        we already trust him.
+
+                        In all other cases, we add a SPF header using the <b>SPF</b> mailet. Then we need to take a decision
+                        about incoming emails. We use the <b>HasMailAttributeWithValue</b> matcher which has seven possible
+                        values to handle in the case of SPF: <b>permerror</b>, <b>temperror</b>, <b>none</b>, <b>pass</b>,
+                        <b>neutral</b>, <b>fail</b> and <b>softfail</b>. What action you choose for each of these values
+                        depends on what you want to do. In our case, we redirect SPF errors and fails to the <b>error</b>
+                        processor, whereas all other cases lead directly to the <b>transport</b> processor for further
+                        normal processing. We are rather tolerant since we authorize <b>softfails</b>.</p>
+
+                    <p>For example:</p>
+
+                    <pre><code>[...]
+
+&lt;processors>
+  &lt;processor state="root" enableJmx="true">
+    &lt;mailet match="All" class="PostmasterAlias"/>
+    &lt;mailet match="RelayLimit=30" class="Null"/>
+    &lt;mailet match="All" class="ToProcessor"&gt;
+      &lt;processor&gt;SPFProcessor&lt;/processor>
+    &lt;/mailet&gt;
+  &lt;/processor>
+
+  &lt;processor state="error" enableJmx="true">
+    [...]
+  &lt;/processor>
+
+  &lt;processor state="SPFProcessor">
+    &lt;mailet match="SenderIsLocal" class="ToProcessor"&gt;
+      &lt;processor&gt;transport&lt;/processor&gt;
+    &lt;/mailet&gt;
+    &lt;mailet match="SMTPAuthSuccessful" class="ToProcessor"&gt;
+      &lt;processor&gt;transport&lt;/processor&gt;
+    &lt;/mailet&gt;
+    &lt;mailet match="All" class="SPF"&gt;
+      &lt;addHeader&gt;true&lt;/addHeader&gt;
+    &lt;/mailet&gt;
+    &lt;mailet match="HasMailAttributeWithValue=org.apache.james.transport.mailets.spf.result, permerror" class="ToProcessor"&gt;
+      &lt;processor&gt;error&lt;/processor&gt;
+    &lt;/mailet&gt;
+    &lt;mailet match="HasMailAttributeWithValue=org.apache.james.transport.mailets.spf.result, temperror" class="ToProcessor"&gt;
+      &lt;processor&gt;error&lt;/processor&gt;
+    &lt;/mailet&gt;
+    &lt;mailet match="HasMailAttributeWithValue=org.apache.james.transport.mailets.spf.result, none" class="ToProcessor"&gt;
+      &lt;processor&gt;transport&lt;/processor&gt;
+    &lt;/mailet&gt;
+    &lt;mailet match="HasMailAttributeWithValue=org.apache.james.transport.mailets.spf.result, pass" class="ToProcessor"&gt;
+      &lt;processor&gt;transport&lt;/processor&gt;
+    &lt;/mailet&gt;
+    &lt;mailet match="HasMailAttributeWithValue=org.apache.james.transport.mailets.spf.result, neutral" class="ToProcessor"&gt;
+      &lt;processor&gt;transport&lt;/processor&gt;
+    &lt;/mailet&gt;
+    &lt;mailet match="HasMailAttributeWithValue=org.apache.james.transport.mailets.spf.result, fail" class="ToProcessor"&gt;
+      &lt;processor&gt;error&lt;/processor&gt;
+    &lt;/mailet&gt;
+    &lt;mailet match="HasMailAttributeWithValue=org.apache.james.transport.mailets.spf.result, softfail" class="ToProcessor"&gt;
+      &lt;processor&gt;transport&lt;/processor&gt;
+    &lt;/mailet&gt;
+    &lt;mailet match="All" class="LogMessage"&gt;
+      &lt;headers&gt;true&lt;/headers&gt;
+      &lt;body&gt;false&lt;/body&gt;
+      &lt;comment&gt;Unknown SPF result&lt;/comment&gt;
+    &lt;/mailet&gt;
+  &lt;/processor&gt;
+
+[...]</code></pre>
+
+                </div>
+                <footer class="major">
+                    <ul class="actions align-center">
+                        <li><a href="index.html" class="button">go back to other how-tos</a></li>
+                    </ul>
+                </footer>
+            </div>
+        </section>
+
+    </div>
+    <footer id="footer" class="major">
+        <section>
+            <h2>James</h2>
+            <ul class="no-padding">
+                <li class="no-padding"><a href="https://james.apache.org/#intro" class="active">About</a></li>
+                <li class="no-padding"><a href="https://james.apache.org/#first">Get Started</a></li>
+                <li class="no-padding"><a href="https://james.apache.org/#posts">Last Posts</a></li>
+                <li class="no-padding"><a href="https://james.apache.org/#second">Community</a></li>
+                <li class="no-padding"><a href="https://james.apache.org/#third">Contribute</a></li>
+                <li class="no-padding"><a href="https://james.apache.org/"><span class="fa fa-external-link"></span> Documentation</a></li>
+            </ul>
+        </section>
+        <section>
+            <h2>Connect</h2>
+            <ul class="icons">
+                <li><a href="https://james.apache.org/mail.html" class="icon fa-envelope-o alt"><span class="label">Mailing-list</span></a></li>
+                <li><a href="https://gitter.im/apache/james-project" class="icon fa-wechat alt"><span class="label">Gitter</span></a></li>
+                <li><a href="https://github.com/apache/james-project" class="icon fa-github alt"><span class="label">GitHub</span></a></li>
+                <li><a href="https://twitter.com/ApacheJames" class="icon fa-twitter alt"><span class="label">Twitter</span></a></li>
+                <li><a href="https://james.apache.org/support.html" class="icon fa-briefcase alt"><span class="label">Support</span></a></li>
+                <li><a href="http://www.apache.org/events/current-event" class="icon fa-calendar alt"><span class="label">Apache Foundation events</span></a></li>
+            </ul>
+        </section>
+        <section class="legal-section">
+            <h2>Copyright</h2>
+            Apache James and related projects are trademarks of the Apache Software Foundation.<br/>
+            <a href="https://www.apache.org/">Copyright 2006-2018 The Apache Software Foundation. All Rights Reserved.</a><br/>
+            <a href="https://www.apache.org/licenses/">License</a><br/>
+            <a href="https://www.apache.org/foundation/sponsorship.html">Donate</a> to support the Apache Foundation<br/>
+            <a href="https://www.apache.org/foundation/thanks.html">Thanks</a><br/>
+            Design: <a href="https://html5up.net">HTML5 UP</a><br/>
+            Thanks to <a href="http://www.neoma-interactive.com/">Neoma by Linagora</a> for the website design
+        </section>
+    </footer>
+</div>
+
+<!-- Scripts -->
+<script src="assets/js/jquery.min.js"></script>
+<script src="assets/js/jquery.scrollex.min.js"></script>
+<script src="assets/js/jquery.scrolly.min.js"></script>
+<script src="assets/js/skel.min.js"></script>
+<script src="assets/js/util.js"></script>
+<script src="assets/js/lightbox.js"></script>
+<script src="assets/js/github-fetch.js"></script>
+<script src="assets/js/lity.min.js"></script>
+<!--[if lte IE 8]><script src="assets/js/ie/respond.min.js"></script><![endif]-->
+<script src="assets/js/main.js"></script>
+


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


[05/13] james-project git commit: JAMES-2448 Limit non-started protocols

Posted by bt...@apache.org.
JAMES-2448 Limit non-started protocols


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

Branch: refs/heads/master
Commit: a8f83ab2aac5d53c9f2ffc8c1890e475330f1571
Parents: 612010d
Author: benwa <bt...@linagora.com>
Authored: Mon Jul 2 08:30:55 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Thu Jul 5 08:58:13 2018 +0700

----------------------------------------------------------------------
 .../src/test/resources/imapserver.xml           | 15 ------
 .../src/test/resources/lmtpserver.xml           | 18 -------
 .../src/test/resources/managesieveserver.xml    | 33 ------------
 .../src/test/resources/pop3server.xml           | 19 -------
 .../src/test/resources/smtpserver.xml           | 54 --------------------
 5 files changed, 139 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/a8f83ab2/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/imapserver.xml
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/imapserver.xml b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/imapserver.xml
index 28ce44c..5db05e9 100644
--- a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/imapserver.xml
+++ b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/imapserver.xml
@@ -36,19 +36,4 @@ under the License.
         <connectionLimit>0</connectionLimit>
         <connectionLimitPerIP>0</connectionLimitPerIP>
     </imapserver>
-    <imapserver enabled="true">
-        <jmxName>imapserver-ssl</jmxName>
-        <bind>0.0.0.0:1993</bind>
-        <connectionBacklog>200</connectionBacklog>
-        <tls socketTLS="false" startTLS="false">
-            <!-- To create a new keystore execute:
-              keytool -genkey -alias james -keyalg RSA -keystore /path/to/james/conf/keystore
-             -->
-            <keystore>file://conf/keystore</keystore>
-            <secret>james72laBalle</secret>
-            <provider>org.bouncycastle.jce.provider.BouncyCastleProvider</provider>
-        </tls>
-        <connectionLimit>0</connectionLimit>
-        <connectionLimitPerIP>0</connectionLimitPerIP>
-    </imapserver>
 </imapservers>

http://git-wip-us.apache.org/repos/asf/james-project/blob/a8f83ab2/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/lmtpserver.xml
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/lmtpserver.xml b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/lmtpserver.xml
index 5c4a9c7..f838adb 100644
--- a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/lmtpserver.xml
+++ b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/lmtpserver.xml
@@ -20,22 +20,4 @@
 
 <lmtpservers>
 
-    <lmtpserver enabled="true">
-        <jmxName>lmtpserver</jmxName>
-        <!-- LMTP should not be reachable from outside your network so bind it to loopback-->
-        <bind>127.0.0.1:1024</bind>
-        <connectionBacklog>200</connectionBacklog>
-        <connectiontimeout>1200</connectiontimeout>
-        <!-- Set the maximum simultaneous incoming connections for this service -->
-        <connectionLimit>0</connectionLimit>
-        <!-- Set the maximum simultaneous incoming connections per IP for this service -->
-        <connectionLimitPerIP>0</connectionLimitPerIP>
-        <!--  This sets the maximum allowed message size (in kilobytes) for this -->
-        <!--  LMTP service. If unspecified, the value defaults to 0, which means no limit. -->
-        <maxmessagesize>0</maxmessagesize>
-        <handlerchain>
-            <handler class="org.apache.james.lmtpserver.CoreCmdHandlerLoader"/>
-        </handlerchain>
-    </lmtpserver>
-
 </lmtpservers>

http://git-wip-us.apache.org/repos/asf/james-project/blob/a8f83ab2/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/managesieveserver.xml
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/managesieveserver.xml b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/managesieveserver.xml
index ec57e09..f136a43 100644
--- a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/managesieveserver.xml
+++ b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/managesieveserver.xml
@@ -27,39 +27,6 @@
 
 <managesieveservers>
 
-   <managesieveserver enabled="true">
-
-     <jmxName>managesieveserver</jmxName>
-
-     <bind>0.0.0.0:4190</bind>
-
-     <connectionBacklog>200</connectionBacklog>
-
-     <tls socketTLS="false" startTLS="false">
-       <!-- To create a new keystore execute:
-        keytool -genkey -alias james -keyalg RSA -keystore /path/to/james/conf/keystore
-         -->
-       <keystore>file://conf/keystore</keystore>
-       <secret>james72laBalle</secret>
-       <provider>org.bouncycastle.jce.provider.BouncyCastleProvider</provider>
-       <!-- The algorithm is optional and only needs to be specified when using something other
-        than the Sun JCE provider - You could use IbmX509 with IBM Java runtime. -->
-       <algorithm>SunX509</algorithm>
-     </tls>
-         
-        <!-- connection timeout in secconds -->
-        <connectiontimeout>360</connectiontimeout>
-
-        <!-- Set the maximum simultaneous incoming connections for this service -->
-        <connectionLimit>0</connectionLimit>
-         
-        <!-- Set the maximum simultaneous incoming connections per IP for this service -->
-        <connectionLimitPerIP>0</connectionLimitPerIP>
-        <maxmessagesize>0</maxmessagesize>
-        <addressBracketsEnforcement>true</addressBracketsEnforcement>
-  
-   </managesieveserver>
-
 </managesieveservers>
 
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/a8f83ab2/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/pop3server.xml
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/pop3server.xml b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/pop3server.xml
index e4187da..bec385a 100644
--- a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/pop3server.xml
+++ b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/pop3server.xml
@@ -20,23 +20,4 @@
 
 
 <pop3servers>
-    <pop3server enabled="true">
-        <jmxName>pop3server</jmxName>
-        <bind>0.0.0.0:1110</bind>
-        <connectionBacklog>200</connectionBacklog>
-        <tls socketTLS="false" startTLS="false">
-            <!-- To create a new keystore execute:
-                  keytool -genkey -alias james -keyalg RSA -keystore /path/to/james/conf/keystore
-             -->
-            <keystore>file://conf/keystore</keystore>
-            <secret>james72laBalle</secret>
-            <provider>org.bouncycastle.jce.provider.BouncyCastleProvider</provider>
-        </tls>
-        <connectiontimeout>1200</connectiontimeout>
-        <connectionLimit>0</connectionLimit>
-        <connectionLimitPerIP>0</connectionLimitPerIP>
-        <handlerchain>
-            <handler class="org.apache.james.pop3server.core.CoreCmdHandlerLoader"/>
-        </handlerchain>
-    </pop3server>
 </pop3servers>

http://git-wip-us.apache.org/repos/asf/james-project/blob/a8f83ab2/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/smtpserver.xml
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/smtpserver.xml b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/smtpserver.xml
index 2f83c8e..eb84850 100644
--- a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/smtpserver.xml
+++ b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/resources/smtpserver.xml
@@ -43,60 +43,6 @@
             <handler class="org.apache.james.smtpserver.CoreCmdHandlerLoader"/>
         </handlerchain>
     </smtpserver>
-    <smtpserver enabled="true">
-        <jmxName>smtpserver-TLS</jmxName>
-        <bind>0.0.0.0:10465</bind>
-        <connectionBacklog>200</connectionBacklog>
-        <tls socketTLS="false" startTLS="false">
-            <keystore>file://conf/keystore</keystore>
-            <secret>james72laBalle</secret>
-            <provider>org.bouncycastle.jce.provider.BouncyCastleProvider</provider>
-            <algorithm>SunX509</algorithm>
-        </tls>
-        <connectiontimeout>360</connectiontimeout>
-        <connectionLimit>0</connectionLimit>
-        <connectionLimitPerIP>0</connectionLimitPerIP>
-        <!--
-           Authorize only local users
-        -->
-        <authRequired>true</authRequired>
-        <!-- Trust authenticated users -->
-        <verifyIdentity>false</verifyIdentity>
-        <maxmessagesize>0</maxmessagesize>
-        <addressBracketsEnforcement>true</addressBracketsEnforcement>
-        <smtpGreeting>JAMES Linagora's SMTP awesome Server</smtpGreeting>
-        <handlerchain>
-            <handler class="org.apache.james.smtpserver.fastfail.ValidRcptHandler"/>
-            <handler class="org.apache.james.smtpserver.CoreCmdHandlerLoader"/>
-        </handlerchain>
-    </smtpserver>
-    <smtpserver enabled="true">
-        <jmxName>smtpserver-authenticated</jmxName>
-        <bind>0.0.0.0:1587</bind>
-        <connectionBacklog>200</connectionBacklog>
-        <tls socketTLS="false" startTLS="false">
-            <keystore>file://conf/keystore</keystore>
-            <secret>james72laBalle</secret>
-            <provider>org.bouncycastle.jce.provider.BouncyCastleProvider</provider>
-            <algorithm>SunX509</algorithm>
-        </tls>
-        <connectiontimeout>360</connectiontimeout>
-        <connectionLimit>0</connectionLimit>
-        <connectionLimitPerIP>0</connectionLimitPerIP>
-        <!--
-           Authorize only local users
-        -->
-        <authRequired>true</authRequired>
-        <!-- Trust authenticated users -->
-        <verifyIdentity>false</verifyIdentity>
-        <maxmessagesize>0</maxmessagesize>
-        <addressBracketsEnforcement>true</addressBracketsEnforcement>
-        <smtpGreeting>JAMES Linagora's SMTP awesome Server</smtpGreeting>
-        <handlerchain>
-            <handler class="org.apache.james.smtpserver.fastfail.ValidRcptHandler"/>
-            <handler class="org.apache.james.smtpserver.CoreCmdHandlerLoader"/>
-        </handlerchain>
-    </smtpserver>
 </smtpservers>
 
 


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


[03/13] james-project git commit: JAMES-2435 Skeleton of "how-to" proposition & custom mailet example.

Posted by bt...@apache.org.
JAMES-2435 Skeleton of "how-to" proposition & custom mailet example.


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

Branch: refs/heads/master
Commit: 863da41941aef69140570b19521dc13cc2a31742
Parents: 5c7ac51
Author: benwa <bt...@linagora.com>
Authored: Wed Jun 20 12:38:52 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jul 4 17:26:18 2018 +0700

----------------------------------------------------------------------
 examples/custom-mailets/pom.xml                 |  26 ++
 .../custom/mailets/IsDelayedForMoreThan.java    |  70 +++++
 .../custom/mailets/SendPromotionCode.java       |  71 +++++
 .../src/main/resources/mailetcontainer.xml      | 168 +++++++++++
 examples/pom.xml                                |  40 +++
 pom.xml                                         |   1 +
 src/homepage/howTo/index.html                   | 157 ++++++++++
 src/homepage/howTo/mail-processing.html         | 287 +++++++++++++++++++
 src/homepage/index.html                         |   3 +
 9 files changed, 823 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/863da419/examples/custom-mailets/pom.xml
----------------------------------------------------------------------
diff --git a/examples/custom-mailets/pom.xml b/examples/custom-mailets/pom.xml
new file mode 100644
index 0000000..ee08d36
--- /dev/null
+++ b/examples/custom-mailets/pom.xml
@@ -0,0 +1,26 @@
+<?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>examples</artifactId>
+        <groupId>org.apache.james</groupId>
+        <version>3.1.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>custom-mailets</artifactId>
+
+    <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>apache-mailet-base</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>james-server-util</artifactId>
+        </dependency>
+    </dependencies>
+
+
+</project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/863da419/examples/custom-mailets/src/main/java/org/apache/james/examples/custom/mailets/IsDelayedForMoreThan.java
----------------------------------------------------------------------
diff --git a/examples/custom-mailets/src/main/java/org/apache/james/examples/custom/mailets/IsDelayedForMoreThan.java b/examples/custom-mailets/src/main/java/org/apache/james/examples/custom/mailets/IsDelayedForMoreThan.java
new file mode 100644
index 0000000..2c40d80
--- /dev/null
+++ b/examples/custom-mailets/src/main/java/org/apache/james/examples/custom/mailets/IsDelayedForMoreThan.java
@@ -0,0 +1,70 @@
+/****************************************************************
+ * 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.examples.custom.mailets;
+
+import java.time.Clock;
+import java.time.Duration;
+import java.util.Collection;
+import java.util.Date;
+
+import javax.mail.MessagingException;
+
+import org.apache.james.core.MailAddress;
+import org.apache.james.util.TimeConverter;
+import org.apache.mailet.Mail;
+import org.apache.mailet.base.GenericMatcher;
+
+import com.google.common.collect.ImmutableList;
+
+public class IsDelayedForMoreThan extends GenericMatcher {
+
+    public static final TimeConverter.Unit DEFAULT_UNIT = TimeConverter.Unit.HOURS;
+    private final Clock clock;
+    private Duration maxDelay;
+
+    public IsDelayedForMoreThan(Clock clock) {
+        this.clock = clock;
+    }
+
+    public IsDelayedForMoreThan() {
+        this(Clock.systemDefaultZone());
+    }
+
+    @Override
+    public Collection<MailAddress> match(Mail mail) throws MessagingException {
+        Date sentDate = mail.getMessage().getSentDate();
+
+        if (clock.instant().isAfter(sentDate.toInstant().plusMillis(maxDelay.toMillis()))) {
+            return ImmutableList.copyOf(mail.getRecipients());
+        }
+        return ImmutableList.of();
+    }
+
+    @Override
+    public void init() {
+        String condition = getCondition();
+        maxDelay = Duration.ofMillis(TimeConverter.getMilliSeconds(condition, DEFAULT_UNIT));
+    }
+
+    @Override
+    public String getMatcherName() {
+        return "IsDelayedForMoreThan";
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/863da419/examples/custom-mailets/src/main/java/org/apache/james/examples/custom/mailets/SendPromotionCode.java
----------------------------------------------------------------------
diff --git a/examples/custom-mailets/src/main/java/org/apache/james/examples/custom/mailets/SendPromotionCode.java b/examples/custom-mailets/src/main/java/org/apache/james/examples/custom/mailets/SendPromotionCode.java
new file mode 100644
index 0000000..898b7cd
--- /dev/null
+++ b/examples/custom-mailets/src/main/java/org/apache/james/examples/custom/mailets/SendPromotionCode.java
@@ -0,0 +1,71 @@
+/****************************************************************
+ * 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.examples.custom.mailets;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+
+import org.apache.james.core.MailAddress;
+import org.apache.mailet.Mail;
+import org.apache.mailet.base.GenericMailet;
+
+import com.google.common.base.Strings;
+import com.google.common.collect.ImmutableList;
+
+public class SendPromotionCode extends GenericMailet {
+
+    public static final boolean REPLY_TO_SENDER_ONLY = false;
+
+    private String reason;
+    private String promotionCode;
+
+    @Override
+    public void service(Mail mail) throws MessagingException {
+        MimeMessage response = (MimeMessage) mail.getMessage()
+            .reply(REPLY_TO_SENDER_ONLY);
+
+        response.setText(reason + "\n\n" +
+            "Here is the following promotion code that you can use on your next order: " + promotionCode);
+
+        MailAddress sender = getMailetContext().getPostmaster();
+        ImmutableList<MailAddress> recipients = ImmutableList.of(mail.getSender());
+
+        getMailetContext()
+            .sendMail(sender, recipients, response);
+    }
+
+    @Override
+    public void init() throws MessagingException {
+        reason = getInitParameter("reason");
+        promotionCode = getInitParameter("promotionCode");
+
+        if (Strings.isNullOrEmpty(reason)) {
+            throw new MessagingException("'reason' is compulsory");
+        }
+        if (Strings.isNullOrEmpty(promotionCode)) {
+            throw new MessagingException("'promotionCode' is compulsory");
+        }
+    }
+
+    @Override
+    public String getMailetName() {
+        return "SendPromotionCode";
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/863da419/examples/custom-mailets/src/main/resources/mailetcontainer.xml
----------------------------------------------------------------------
diff --git a/examples/custom-mailets/src/main/resources/mailetcontainer.xml b/examples/custom-mailets/src/main/resources/mailetcontainer.xml
new file mode 100644
index 0000000..d75ba9e
--- /dev/null
+++ b/examples/custom-mailets/src/main/resources/mailetcontainer.xml
@@ -0,0 +1,168 @@
+<?xml version="1.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.
+ -->
+
+<mailetcontainer enableJmx="true">
+
+    <context>
+        <postmaster>postmaster@james.minet.net</postmaster>
+    </context>
+
+    <spooler>
+        <threads>20</threads>
+    </spooler>
+
+    <processors>
+        <processor state="root" enableJmx="true">
+            <mailet match="All" class="PostmasterAlias"/>
+
+            <mailet match="org.apache.james.examples.custom.mailets.IsDelayedForMoreThan=1 day"
+                    class="org.apache.james.examples.custom.mailets.SendPromotionCode">
+                <reason>Your email had been delayed for a long time. Because we are sorry about it, please find the
+                    following promotion code.</reason>
+                <promotionCode>1542-2563-5469</promotionCode>
+            </mailet>
+
+            <mailet match="RelayLimit=30" class="Null"/>
+            <mailet match="All" class="ToProcessor">
+                <processor>transport</processor>
+            </mailet>
+        </processor>
+
+        <processor state="error" enableJmx="true">
+            <mailet match="All" class="MetricsMailet">
+                <metricName>mailetContainerErrors</metricName>
+            </mailet>
+            <mailet match="All" class="Bounce"/>
+            <mailet match="All" class="ToRepository">
+                <repositoryPath>file://var/mail/error/</repositoryPath>
+            </mailet>
+        </processor>
+
+        <processor state="transport" enableJmx="true">
+            <mailet match="SMTPAuthSuccessful" class="SetMimeHeader">
+                <name>X-UserIsAuth</name>
+                <value>true</value>
+                <onMailetException>ignore</onMailetException>
+            </mailet>
+            <mailet match="HasMailAttribute=org.apache.james.SMIMECheckSignature" class="SetMimeHeader">
+                <name>X-WasSigned</name>
+                <value>true</value>
+                <onMailetException>ignore</onMailetException>
+            </mailet>
+            <mailet match="All" class="RemoveMimeHeader">
+                <name>bcc</name>
+                <onMailetException>ignore</onMailetException>
+            </mailet>
+            <mailet match="All" class="RecipientRewriteTable">
+                <errorProcessor>rrt-error</errorProcessor>
+            </mailet>
+            <mailet match="RecipientIsLocal" class="Sieve"/>
+            <mailet match="RecipientIsLocal" class="AddDeliveredToHeader"/>
+            <mailet match="RecipientIsLocal" class="LocalDelivery"/>
+            <mailet match="HostIsLocal" class="ToProcessor">
+                <processor>local-address-error</processor>
+                <notice>550 - Requested action not taken: no such user here</notice>
+            </mailet>
+
+            <mailet match="SMTPAuthSuccessful" class="ToProcessor">
+                <processor>relay</processor>
+            </mailet>
+            <mailet match="SMTPIsAuthNetwork" class="ToProcessor">
+                <processor>relay</processor>
+            </mailet>
+            <mailet match="SentByMailet" class="ToProcessor">
+                <processor>relay</processor>
+            </mailet>
+
+            <mailet match="All" class="ToProcessor">
+                <processor>relay-denied</processor>
+            </mailet>
+        </processor>
+
+        <processor state="relay" enableJmx="true">
+            <mailet match="All" class="RemoteDelivery">
+                <outgoingQueue>outgoing</outgoingQueue>
+                <delayTime>5000, 100000, 500000</delayTime>
+                <maxRetries>25</maxRetries>
+                <maxDnsProblemRetries>0</maxDnsProblemRetries>
+                <deliveryThreads>10</deliveryThreads>
+                <sendpartial>true</sendpartial>
+                <bounceProcessor>bounces</bounceProcessor>
+            </mailet>
+        </processor>
+
+        <processor state="spam" enableJmx="true">
+            <mailet match="All" class="MetricsMailet">
+                <metricName>mailetContainerSpam</metricName>
+            </mailet>
+            <mailet match="All" class="ToRepository">
+                <repositoryPath>file://var/mail/spam/</repositoryPath>
+            </mailet>
+        </processor>
+
+        <processor state="local-address-error" enableJmx="true">
+            <mailet match="All" class="MetricsMailet">
+                <metricName>mailetContainerLocalAddressError</metricName>
+            </mailet>
+            <mailet match="All" class="Bounce">
+                <attachment>none</attachment>
+            </mailet>
+            <mailet match="All" class="ToRepository">
+                <repositoryPath>file://var/mail/address-error/</repositoryPath>
+            </mailet>
+        </processor>
+
+        <processor state="relay-denied" enableJmx="true">
+            <mailet match="All" class="MetricsMailet">
+                <metricName>mailetContainerRelayDenied</metricName>
+            </mailet>
+            <mailet match="All" class="Bounce">
+                <attachment>none</attachment>
+            </mailet>
+            <mailet match="All" class="ToRepository">
+                <repositoryPath>file://var/mail/relay-denied/</repositoryPath>
+                <notice>Warning: You are sending an e-mail to a remote server. You must be authenticated to perform such an operation</notice>
+            </mailet>
+        </processor>
+
+        <processor state="bounces" enableJmx="true">
+            <mailet match="All" class="MetricsMailet">
+                <metricName>bounces</metricName>
+            </mailet>
+            <mailet match="All" class="DSNBounce">
+                <passThrough>false</passThrough>
+            </mailet>
+        </processor>
+
+        <processor state="rrt-error" enableJmx="false">
+            <mailet match="All" class="ToRepository">
+                <repositoryPath>file://var/mail/rrt-error/</repositoryPath>
+                <passThrough>true</passThrough>
+            </mailet>
+            <mailet match="IsSenderInRRTLoop" class="Null"/>
+            <mailet match="All" class="Bounce"/>
+        </processor>
+
+    </processors>
+
+</mailetcontainer>
+
+

http://git-wip-us.apache.org/repos/asf/james-project/blob/863da419/examples/pom.xml
----------------------------------------------------------------------
diff --git a/examples/pom.xml b/examples/pom.xml
new file mode 100644
index 0000000..a04a912
--- /dev/null
+++ b/examples/pom.xml
@@ -0,0 +1,40 @@
+<?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/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.james</groupId>
+        <artifactId>james-project</artifactId>
+        <version>3.1.0-SNAPSHOT</version>
+    </parent>
+
+    <packaging>pom</packaging>
+    <artifactId>examples</artifactId>
+
+    <name>Apache James :: Examples</name>
+
+    <modules>
+        <module>custom-mailets</module>
+    </modules>
+
+</project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/863da419/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 7b93832..f776df9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -527,6 +527,7 @@
         <module>backends-common</module>
         <module>core</module>
         <module>event-sourcing</module>
+        <module>examples</module>
         <module>javax-mail-extension</module>
         <module>mailbox</module>
         <module>mailet</module>

http://git-wip-us.apache.org/repos/asf/james-project/blob/863da419/src/homepage/howTo/index.html
----------------------------------------------------------------------
diff --git a/src/homepage/howTo/index.html b/src/homepage/howTo/index.html
new file mode 100644
index 0000000..ff64620
--- /dev/null
+++ b/src/homepage/howTo/index.html
@@ -0,0 +1,157 @@
+---
+layout: default
+---
+<!--
+    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.
+-->
+<link href="assets/css/lightbox.css" rel="stylesheet">
+<link href="assets/css/lity.min.css" rel="stylesheet" />
+<div id="wrapper">
+  <div class="apache_ref">
+    <a href="https://www.apache.org" alt="apache foundation link"><img src="https://www.apache.org/foundation/press/kit/asf_logo.svg" title="apache foundation logo"/></a>
+  </div>
+  <div class="apache_ref_mobile">
+    <a href="https://www.apache.org" alt="apache foundation link">The Apache Software Foundation</a>
+  </div>
+  <div class="apache_ref_left">
+    <a href="https://www.apache.org/events/current-event.html" alt="apache foundation event"><img src="https://www.apache.org/events/current-event-234x60.png" title="apache foundation event logo"/></a>
+  </div>
+  <div class="apache_ref_left_mobile">
+    <a href="https://www.apache.org/events/current-event.html" alt="apache foundation event"><img src="https://www.apache.org/events/current-event-234x60.png" title="apache foundation event logo"/></a>
+  </div>
+
+  <!-- Header -->
+    <header id="header" class="alt">
+      <div class="logo"><a href="/index.html" alt="Apache James"><img src="/images/james.svg" alt="james logo"/></a></div>
+      <h1 class="hidden">James Enterprise Mail Server</h1>
+      <h2>Emails at the heart of your business logic</h2>
+    </header>
+
+  <!-- Main -->
+    <div id="main">
+
+      <!-- Introduction -->
+        <section id="intro" class="main special">
+          <div class="">
+            <div class="content">
+              <header class="major">
+                <h2>James how to's...</h2>
+              </header>
+              <p class="align-left">James can be used for a wide variety of cases here is a little list of what you can use it for.<br/>
+                This section explains in detail how to achieve these cool features in a straightforward way...</p>
+
+              <a href="mail-processing.html"
+                 data-lightbox="james-schema"
+                 data-title="Customized mail processing"
+                 alt="Customized mail processing"
+                 class="james-schema" >
+                <span class="fa fa-sitemap"></span>Customized mail processing<span class="fa fa-long-arrow-right"></span>
+              </a>
+              <a href="imap-server.html"
+                 data-lightbox="james-schema"
+                 data-title="Setting up an IMAP server"
+                 alt="Setting up an IMAP server"
+                 class="james-schema" >
+                <span class="fa fa-sitemap"></span>Setting up an IMAP server<span class="fa fa-long-arrow-right"></span>
+              </a>
+              <a href="testing.html"
+                 data-lightbox="james-schema"
+                 data-title="Testing with James"
+                 alt="Testing with James"
+                 class="james-schema" >
+                <span class="fa fa-sitemap"></span>Testing with James<span class="fa fa-long-arrow-right"></span>
+              </a>
+
+              <br/>
+              <br/>
+
+              <a href="spam-assassin.html"
+                 data-lightbox="james-schema"
+                 data-title="Spam Assassin integration"
+                 alt="Spam Assassin integration"
+                 class="james-schema" >
+                <span class="fa fa-sitemap"></span>Spam Assassin integration<span class="fa fa-long-arrow-right"></span>
+              </a>
+              <a href="mail-processing-how-to.html"
+                 data-lightbox="james-schema"
+                 data-title="Using a SMTP gateway"
+                 alt="Using a SMTP gateway"
+                 class="james-schema" >
+                <span class="fa fa-sitemap"></span>Using a SMTP gateway<span class="fa fa-long-arrow-right"></span>
+              </a>
+              <a href="mail-processing-how-to.html"
+                 data-lightbox="james-schema"
+                 data-title="Testing with James"
+                 alt="Testing with James"
+                 class="james-schema" >
+                <span class="fa fa-sitemap"></span>Testing with James<span class="fa fa-long-arrow-right"></span>
+              </a>
+
+            </div>
+          </div>
+        </section>
+
+    </div>
+    <footer id="footer" class="major">
+      <section>
+        <h2>James</h2>
+        <ul class="no-padding">
+          <li class="no-padding"><a href="https://james.apache.org/#intro" class="active">About</a></li>
+          <li class="no-padding"><a href="https://james.apache.org/#first">Get Started</a></li>
+          <li class="no-padding"><a href="https://james.apache.org/#posts">Last Posts</a></li>
+          <li class="no-padding"><a href="https://james.apache.org/#second">Community</a></li>
+          <li class="no-padding"><a href="https://james.apache.org/#third">Contribute</a></li>
+          <li class="no-padding"><a href="https://james.apache.org/"><span class="fa fa-external-link"></span> Documentation</a></li>
+        </ul>
+      </section>
+      <section>
+        <h2>Connect</h2>
+        <ul class="icons">
+          <li><a href="https://james.apache.org/mail.html" class="icon fa-envelope-o alt"><span class="label">Mailing-list</span></a></li>
+          <li><a href="https://gitter.im/apache/james-project" class="icon fa-wechat alt"><span class="label">Gitter</span></a></li>
+          <li><a href="https://github.com/apache/james-project" class="icon fa-github alt"><span class="label">GitHub</span></a></li>
+          <li><a href="https://twitter.com/ApacheJames" class="icon fa-twitter alt"><span class="label">Twitter</span></a></li>
+          <li><a href="https://james.apache.org/support.html" class="icon fa-briefcase alt"><span class="label">Support</span></a></li>
+          <li><a href="http://www.apache.org/events/current-event" class="icon fa-calendar alt"><span class="label">Apache Foundation events</span></a></li>
+          </ul>
+      </section>
+      <section class="legal-section">
+        <h2>Copyright</h2>
+        Apache James and related projects are trademarks of the Apache Software Foundation.<br/>
+        <a href="https://www.apache.org/">Copyright 2006-2018 The Apache Software Foundation. All Rights Reserved.</a><br/>
+        <a href="https://www.apache.org/licenses/">License</a><br/>
+        <a href="https://www.apache.org/foundation/sponsorship.html">Donate</a> to support the Apache Foundation<br/>
+        <a href="https://www.apache.org/foundation/thanks.html">Thanks</a><br/>
+        Design: <a href="https://html5up.net">HTML5 UP</a><br/>
+        Thanks to <a href="http://www.neoma-interactive.com/">Neoma by Linagora</a> for the website design
+      </section>
+  </footer>
+</div>
+
+<!-- Scripts -->
+<script src="assets/js/jquery.min.js"></script>
+<script src="assets/js/jquery.scrollex.min.js"></script>
+<script src="assets/js/jquery.scrolly.min.js"></script>
+<script src="assets/js/skel.min.js"></script>
+<script src="assets/js/util.js"></script>
+<script src="assets/js/lightbox.js"></script>
+<script src="assets/js/github-fetch.js"></script>
+<script src="assets/js/lity.min.js"></script>
+<!--[if lte IE 8]><script src="assets/js/ie/respond.min.js"></script><![endif]-->
+<script src="assets/js/main.js"></script>
+

http://git-wip-us.apache.org/repos/asf/james-project/blob/863da419/src/homepage/howTo/mail-processing.html
----------------------------------------------------------------------
diff --git a/src/homepage/howTo/mail-processing.html b/src/homepage/howTo/mail-processing.html
new file mode 100644
index 0000000..9c07441
--- /dev/null
+++ b/src/homepage/howTo/mail-processing.html
@@ -0,0 +1,287 @@
+---
+layout: default
+---
+<!--
+    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.
+-->
+<link href="assets/css/lightbox.css" rel="stylesheet">
+<link href="assets/css/lity.min.css" rel="stylesheet" />
+<div id="wrapper">
+  <div class="apache_ref">
+    <a href="https://www.apache.org" alt="apache foundation link"><img src="https://www.apache.org/foundation/press/kit/asf_logo.svg" title="apache foundation logo"/></a>
+  </div>
+  <div class="apache_ref_mobile">
+    <a href="https://www.apache.org" alt="apache foundation link">The Apache Software Foundation</a>
+  </div>
+  <div class="apache_ref_left">
+    <a href="https://www.apache.org/events/current-event.html" alt="apache foundation event"><img src="https://www.apache.org/events/current-event-234x60.png" title="apache foundation event logo"/></a>
+  </div>
+  <div class="apache_ref_left_mobile">
+    <a href="https://www.apache.org/events/current-event.html" alt="apache foundation event"><img src="https://www.apache.org/events/current-event-234x60.png" title="apache foundation event logo"/></a>
+  </div>
+
+  <!-- Header -->
+    <header id="header" class="alt">
+      <div class="logo"><a href="/index.html" alt="Apache James"><img src="/images/james.svg" alt="james logo"/></a></div>
+      <h1 class="hidden">James Enterprise Mail Server</h1>
+      <h2>Emails at the heart of your business logic</h2>
+    </header>
+
+  <!-- Main -->
+    <div id="main">
+
+      <!-- Introduction -->
+        <section id="intro" class="main special">
+          <div class="">
+            <div class="content align-left">
+              <header class="major">
+                <h1>How to customize mail processing...</h1>
+              </header>
+                <header class="major">
+                    <h2><b>Mail processing component overview</b></h2>
+                </header>
+              <p class="align-left">At the heart of James lies the Mailet container, which allows mail processing. This is
+              splitted into smaller units, with specific responsibilities:
+
+              </p>
+
+              <ul class="no-padding">
+                <li><b>Mailets:</b> Are operations performed with the mail: modifying it, performing a side-effect, etc...</li>
+                <li><b>Matchers:</b> Are per-recipient conditions for mailet executions</li>
+                <li><b>Processors:</b> Are matcher/mailet pair execution threads</li>
+              </ul>
+
+              <p> Read <a href="/server/feature-mailetcontainer.html">this</a> for more explanations of mailet container concepts.</p>
+
+              <p>Once we define the mailet container content through the <a href="/server/config-mailetcontainer.html">mailetcontailer.xml</a> file.
+              Hence, we can arrange James standard components listed <a href="/server/dev-provided-mailets.html">here</a> to achieve basic logic. But what if our goals are more
+              complex? What if we need our own processing components?</p>
+
+              <p>This page will propose a 'hands on practice' how-to using James 3.0.1. We will implement a custom mailet and a custom matcher,
+              then deploy it in a James server.</p>
+
+              <p>We need to choose our use case. We will, when a mail is delayed over one day, write a mail to the original sender
+              to inform him about the delay, say that we are sorry, and send him a promotion code...<pre></pre></p>
+
+
+              <header class="major">
+                <h2><b>Writing custom mailets and matchers</b></h2>
+              </header>
+
+              <p>None of the matchers and mailets available in James allows us to implement what we want. We will have to
+              write our own mailet and matcher in a separated maven project depending on James Mailet API.</p>
+
+              <p>We will write a <b>IsDelayedForMoreThan</b> matcher with a configurable delay. If the Sent Date of incoming emails is older than specified delay, then the emails
+              should be matched (return all mail recipients). Otherwise, we just return an empty list of recipients.</p>
+
+              <p>To ease our Job, we can rely on the <b>org.apache.james.apache-mailet-base</b> maven project, which provides us a <b>GenericMatcher</b> that we can extend.</p>
+
+              <p>Here is the dependency:</p>
+
+              <pre><code>&lt;dependency&gt;
+    &lt;groupId&gt;org.apache.james&lt;/groupId&gt;
+    &lt;artifactId&gt;apache-mailet-base&lt;/artifactId&gt;
+&lt;/dependency&gt;</code></pre>
+
+              <p>The main method of a matcher is the <b>match</b> method:</p>
+
+              <pre><code>Collection&lt;MailAddress&gt; match(Mail mail) throws MessagingException;</code></pre>
+
+              <p>For us, it becomes, with <b>maxDelay</b> being previously configured:</p>
+
+              <pre><code>    private final Clock clock;
+    private Duration maxDelay;
+
+    @Override
+    public Collection&lt;MailAddress&gt; match(Mail mail) throws MessagingException {
+        Date sentDate = mail.getMessage().getSentDate();
+
+        if (clock.instant().isAfter(sentDate.toInstant().plusMillis(maxDelay.toMillis()))) {
+            return ImmutableList.copyOf(mail.getRecipients());
+        }
+        return ImmutableList.of();
+    }</code></pre>
+
+                <p><b>GenericMatcher</b> exposes us the condition that had been configured. We will use it to compute <b>maxDelay</b>.
+              We can do it in the <b>init()</b> method exposed by the generic matcher:</p>
+
+              <pre><code>
+    public static final TimeConverter.Unit DEFAULT_UNIT = TimeConverter.Unit.HOURS;
+
+    @Override
+    public void init() {
+        String condition = getCondition();
+        maxDelay = Duration.ofMillis(TimeConverter.getMilliSeconds(condition, DEFAULT_UNIT));
+    }</code></pre>
+
+              <p>Now, let's take a look at the <b>SendPromotionCode</b> mailet. Of course, we want to write a generic mailet
+                 with a configurable reason (why are we sending the promotion code). To keep things simple, only one promotion
+                 code will be used, and will be written in the configuration. We can here also simply extend the
+                  <b>GenericMailet</b> helper class.</p>
+
+              <p>The main method of a mailet is the <b>service</b> method:</p>
+
+              <pre><code>void service(Mail mail) throws MessagingException</code></pre>
+
+              <p>For us, it becomes, with <b>reason</b> and <b>promotionCode</b> being previously configured:</p>
+
+                <pre><code>    public static final boolean REPLY_TO_SENDER_ONLY = false;
+
+    private String reason;
+    private String promotionCode;
+
+    @Override
+    public void service(Mail mail) throws MessagingException {
+        MimeMessage response = (MimeMessage) mail.getMessage()
+            .reply(REPLY_TO_SENDER_ONLY);
+
+        response.setText(reason + "\n\n" +
+            "Here is the following promotion code that you can use on your next order: " + promotionCode);
+
+        MailAddress sender = getMailetContext().getPostmaster();
+        ImmutableList&lt;MailAddress&gt; recipients = ImmutableList.of(mail.getSender());
+
+        getMailetContext()
+            .sendMail(sender, recipients, response);
+    }</code></pre>
+
+              <p>Note that we can interact with the mail server through the mailet context for sending mails, knowing postmaster, etc...</p>
+
+                <p><b>GenericMailet</b> exposes us the 'init parameters' that had been configured for this mailet. We will
+                    use it to retireve <b>reason</b> and <b>promotionCode</b>.
+                    We can do it in the <b>init()</b> method exposed by the generic mailet:</p>
+
+                <pre><code>    @Override
+    public void init() throws MessagingException {
+        reason = getInitParameter("reason");
+        promotionCode = getInitParameter("promotionCode");
+
+        if (Strings.isNullOrEmpty(reason)) {
+            throw new MessagingException("'reason' is compulsory");
+        }
+        if (Strings.isNullOrEmpty(promotionCode)) {
+            throw new MessagingException("'promotionCode' is compulsory");
+        }
+    }</code></pre>
+
+            <p>You can retrieve the sources of this mini-project on <a href="https://github.com/apache/james-project/examples/custom-mailets">GitHub</a></p>
+
+            <header class="major">
+               <h2><b>Loading custom mailets with James</b></h2>
+            </header>
+
+            <p>Now is the time we will run James with our awesome matcher and mailet configured.</p>
+
+            <p>First, we will need to compile our project with <code>mvn clean install</code>. A jar will be outputted in the target directory.</p>
+
+            <p>Then, we will write the <code>mailetcontainer.xml</code> file expressing the logic we want:</p>
+
+            <pre><code>
+&lt;mailetcontainer enableJmx="true">
+
+    &lt;context&gt;
+        &lt;postmaster&gt;postmaster@james.minet.net&lt;/postmaster&gt;
+    &lt;/context&gt;
+
+    &lt;spooler&gt;
+        &lt;threads&gt;20&lt;/threads&gt;
+    &lt;/spooler&gt;
+
+    &lt;processors&gt;
+        &lt;processor state="root" enableJmx="true"&gt;
+            &lt;mailet match="All" class="PostmasterAlias"/&gt;
+            &lt;mailet match="org.apache.james.examples.custom.mailets.IsDelayedForMoreThan=1 day"
+                    class="org.apache.james.examples.custom.mailets.SendPromotionCode"&gt;
+                &lt;reason&gt;Your email had been delayed for a long time. Because we are sorry about it, please find the
+                following promotion code.&lt;/reason&gt;
+                &lt;promotionCode&gt;1542-2563-5469&lt;/promotionCode&gt;
+            &lt;/mailet&gt;
+            &lt;!-- Rest of the configuration --&gt;
+        &lt;/processor&gt;
+
+        &lt;!-- Other processors --&gt;
+    &lt;/processors&gt;
+&lt;/mailetcontainer&gt;</code></pre>
+
+            <p>Finally, we will start a James server using that. We will rely on docker default image for simplicity.
+                We need to be using the <b>mailetcontainer.xml</b> configuration that we had been writing and position
+                the jar in the <b>extensions-jars</b> folder (specific to guice). This can be achieved with the following command:</p>
+
+            <pre><code>docker run -p "25:25" -p "143:143" \
+                   -v "$PWD/src/main/resources/mailetcontainer.xml:/root/conf/mailetcontainer.xml" \
+                   -v "$PWD/target/custom-mailets-3.1.0-SNAPSHOT.jar:/root/extensions-jars/custom-mailets.jar" \
+            linagora/james-jpa-sample:latest</code></pre>
+
+            </div>
+              <footer class="major">
+                  <ul class="actions align-center">
+                      <li><a href="index.html" class="button">go back to other how-tos</a></li>
+                  </ul>
+              </footer>
+          </div>
+        </section>
+
+    </div>
+    <footer id="footer" class="major">
+      <section>
+        <h2>James</h2>
+        <ul class="no-padding">
+          <li class="no-padding"><a href="https://james.apache.org/#intro" class="active">About</a></li>
+          <li class="no-padding"><a href="https://james.apache.org/#first">Get Started</a></li>
+          <li class="no-padding"><a href="https://james.apache.org/#posts">Last Posts</a></li>
+          <li class="no-padding"><a href="https://james.apache.org/#second">Community</a></li>
+          <li class="no-padding"><a href="https://james.apache.org/#third">Contribute</a></li>
+          <li class="no-padding"><a href="https://james.apache.org/"><span class="fa fa-external-link"></span> Documentation</a></li>
+        </ul>
+      </section>
+      <section>
+        <h2>Connect</h2>
+        <ul class="icons">
+          <li><a href="https://james.apache.org/mail.html" class="icon fa-envelope-o alt"><span class="label">Mailing-list</span></a></li>
+          <li><a href="https://gitter.im/apache/james-project" class="icon fa-wechat alt"><span class="label">Gitter</span></a></li>
+          <li><a href="https://github.com/apache/james-project" class="icon fa-github alt"><span class="label">GitHub</span></a></li>
+          <li><a href="https://twitter.com/ApacheJames" class="icon fa-twitter alt"><span class="label">Twitter</span></a></li>
+          <li><a href="https://james.apache.org/support.html" class="icon fa-briefcase alt"><span class="label">Support</span></a></li>
+          <li><a href="http://www.apache.org/events/current-event" class="icon fa-calendar alt"><span class="label">Apache Foundation events</span></a></li>
+          </ul>
+      </section>
+      <section class="legal-section">
+        <h2>Copyright</h2>
+        Apache James and related projects are trademarks of the Apache Software Foundation.<br/>
+        <a href="https://www.apache.org/">Copyright 2006-2018 The Apache Software Foundation. All Rights Reserved.</a><br/>
+        <a href="https://www.apache.org/licenses/">License</a><br/>
+        <a href="https://www.apache.org/foundation/sponsorship.html">Donate</a> to support the Apache Foundation<br/>
+        <a href="https://www.apache.org/foundation/thanks.html">Thanks</a><br/>
+        Design: <a href="https://html5up.net">HTML5 UP</a><br/>
+        Thanks to <a href="http://www.neoma-interactive.com/">Neoma by Linagora</a> for the website design
+      </section>
+  </footer>
+</div>
+
+<!-- Scripts -->
+<script src="assets/js/jquery.min.js"></script>
+<script src="assets/js/jquery.scrollex.min.js"></script>
+<script src="assets/js/jquery.scrolly.min.js"></script>
+<script src="assets/js/skel.min.js"></script>
+<script src="assets/js/util.js"></script>
+<script src="assets/js/lightbox.js"></script>
+<script src="assets/js/github-fetch.js"></script>
+<script src="assets/js/lity.min.js"></script>
+<!--[if lte IE 8]><script src="assets/js/ie/respond.min.js"></script><![endif]-->
+<script src="assets/js/main.js"></script>
+

http://git-wip-us.apache.org/repos/asf/james-project/blob/863da419/src/homepage/index.html
----------------------------------------------------------------------
diff --git a/src/homepage/index.html b/src/homepage/index.html
index 844e380..53bf2a3 100644
--- a/src/homepage/index.html
+++ b/src/homepage/index.html
@@ -86,6 +86,9 @@ layout: default
               <a href="images/james-general-architecture.png" data-lightbox="james-schema" data-title="James General architecture" alt="James General architecture" class="james-schema" ><span class="fa fa-sitemap"></span>james general architecture<span class="fa fa-long-arrow-right"></span></a>
               <a href="images/james-smtp-relay.png" data-lightbox="james-schema" data-title="James SMTP relay" alt="James SMTP relay" class="james-schema"><span class="fa fa-sitemap"></span>using james as smtp relay<span class="fa fa-long-arrow-right"></span></a>
               <a href="images/james-imap-server.png" data-lightbox="james-schema" data-title="James IMAP server" alt="James IMAP server" class="james-schema"><span class="fa fa-sitemap"></span>using james as an imap server<span class="fa fa-long-arrow-right"></span></a><br/><br/>
+
+              <p>Available how-tos for James features are detailed <a href="howTo">here</a>.</p>
+
               <h2 class="big-h2"><span class="fa fa-wrench"></span> <span>James is a <b>living Open Source project</b> (all developments and implementations are based on open technical standards), any function which is not already available from <b>can be developed!</b></span></h2>
             </div>
           </div>


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


[13/13] james-project git commit: JAMES-2441 Run parallely (and statically when possible) docker containers and other heavy tasks.

Posted by bt...@apache.org.
JAMES-2441 Run parallely (and statically when possible) docker containers and other heavy tasks.


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

Branch: refs/heads/master
Commit: 9d023beae924f0d2b49ee1919e8160da840d45c2
Parents: 26df561
Author: benwa <bt...@linagora.com>
Authored: Wed Jul 4 14:50:12 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Thu Jul 5 09:00:27 2018 +0700

----------------------------------------------------------------------
 .../backends/es/EmbeddedElasticSearch.java      |  2 +-
 .../java/org/apache/james/util/Runnables.java   | 40 ++++++++++++++++++++
 .../james/user/ldap/LdapGenericContainer.java   | 10 +++++
 .../ldap/ReadOnlyUsersLDAPRepositoryTest.java   | 25 ++++--------
 .../jmap/cassandra/CassandraJmapExtension.java  | 15 ++++++--
 server/queue/queue-rabbitmq/pom.xml             |  7 +++-
 .../DockerClusterRabbitMQExtension.java         | 30 +++++++++------
 7 files changed, 94 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/9d023bea/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/EmbeddedElasticSearch.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/EmbeddedElasticSearch.java b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/EmbeddedElasticSearch.java
index b2146ab..19002b5 100644
--- a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/EmbeddedElasticSearch.java
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/EmbeddedElasticSearch.java
@@ -69,7 +69,7 @@ public class EmbeddedElasticSearch extends ExternalResource {
     }
 
     @Override
-    public void before() throws IOException {
+    public void before() {
         node = nodeBuilder().local(true)
             .settings(Settings.builder()
                 .put("path.home", folder.get().toAbsolutePath())

http://git-wip-us.apache.org/repos/asf/james-project/blob/9d023bea/server/container/util-java8/src/main/java/org/apache/james/util/Runnables.java
----------------------------------------------------------------------
diff --git a/server/container/util-java8/src/main/java/org/apache/james/util/Runnables.java b/server/container/util-java8/src/main/java/org/apache/james/util/Runnables.java
new file mode 100644
index 0000000..c199f31
--- /dev/null
+++ b/server/container/util-java8/src/main/java/org/apache/james/util/Runnables.java
@@ -0,0 +1,40 @@
+/****************************************************************
+ * 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.util;
+
+import java.util.Arrays;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Supplier;
+
+public class Runnables {
+    public static void runParallel(Runnable... runnables) {
+        FluentFutureStream.of(
+            Arrays.stream(runnables)
+                .map(runnable -> CompletableFuture.supplyAsync(toVoidSupplier(runnable))))
+            .join();
+    }
+
+    private static Supplier<Void> toVoidSupplier(Runnable runnable) {
+        return () -> {
+            runnable.run();
+            return null;
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/9d023bea/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/LdapGenericContainer.java
----------------------------------------------------------------------
diff --git a/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/LdapGenericContainer.java b/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/LdapGenericContainer.java
index 992b4bf..74e62d9 100644
--- a/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/LdapGenericContainer.java
+++ b/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/LdapGenericContainer.java
@@ -78,6 +78,16 @@ public class LdapGenericContainer extends ExternalResource {
         this.container = container;
     }
 
+    @Override
+    protected void before() {
+        start();
+    }
+
+    @Override
+    protected void after() {
+        stop();
+    }
+
     public void start() {
         container.start();
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/9d023bea/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java b/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java
index e78f976..2fdbe54 100644
--- a/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java
+++ b/server/data/data-ldap-integration-testing/src/test/java/org/apache/james/user/ldap/ReadOnlyUsersLDAPRepositoryTest.java
@@ -25,8 +25,8 @@ import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.commons.configuration.plist.PropertyListConfiguration;
 import org.apache.james.core.MailAddress;
 import org.apache.james.domainlist.api.DomainList;
-import org.junit.After;
 import org.junit.Before;
+import org.junit.ClassRule;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -42,24 +42,20 @@ public class ReadOnlyUsersLDAPRepositoryTest {
     private static final String PASSWORD = "secret";
     private static final String BAD_PASSWORD = "badpassword";
 
-    private LdapGenericContainer ldapContainer;
+    @ClassRule
+    public static LdapGenericContainer ldapContainer = LdapGenericContainer.builder()
+        .domain(DOMAIN)
+        .password(ADMIN_PASSWORD)
+        .build();
+
     private ReadOnlyUsersLDAPRepository ldapRepository;
     private DomainList domainList;
 
     @Before
     public void setup() {
-        startLdapContainer();
         domainList = mock(DomainList.class);
     }
 
-    private void startLdapContainer() {
-        ldapContainer = LdapGenericContainer.builder()
-                .domain(DOMAIN)
-                .password(ADMIN_PASSWORD)
-                .build();
-        ldapContainer.start();
-    }
-
     private void startUsersRepository(HierarchicalConfiguration ldapRepositoryConfiguration) throws Exception {
         ldapRepository = new ReadOnlyUsersLDAPRepository(domainList);
         ldapRepository.configure(ldapRepositoryConfiguration);
@@ -97,13 +93,6 @@ public class ReadOnlyUsersLDAPRepositoryTest {
         return configuration;
     }
 
-    @After
-    public void tearDown() {
-        if (ldapContainer != null) {
-            ldapContainer.stop();
-        }
-    }
-
     @Test
     public void knownUserShouldBeAbleToLogInWhenPasswordIsCorrect() throws Exception {
         startUsersRepository(ldapRepositoryConfiguration());

http://git-wip-us.apache.org/repos/asf/james-project/blob/9d023bea/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraJmapExtension.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraJmapExtension.java b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraJmapExtension.java
index 5a0dd48..8a0b0cd 100644
--- a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraJmapExtension.java
+++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraJmapExtension.java
@@ -34,6 +34,7 @@ import org.apache.james.modules.TestESMetricReporterModule;
 import org.apache.james.modules.TestElasticSearchModule;
 import org.apache.james.modules.TestJMAPServerModule;
 import org.apache.james.server.core.configuration.Configuration;
+import org.apache.james.util.Runnables;
 import org.apache.james.util.scanner.SpamAssassinExtension;
 import org.junit.jupiter.api.extension.AfterAllCallback;
 import org.junit.jupiter.api.extension.AfterEachCallback;
@@ -45,6 +46,8 @@ import org.junit.jupiter.api.extension.ParameterResolutionException;
 import org.junit.jupiter.api.extension.ParameterResolver;
 import org.junit.rules.TemporaryFolder;
 
+import com.github.fge.lambdas.Throwing;
+
 public class CassandraJmapExtension implements BeforeAllCallback, AfterAllCallback,
     BeforeEachCallback, AfterEachCallback, ParameterResolver {
 
@@ -83,15 +86,19 @@ public class CassandraJmapExtension implements BeforeAllCallback, AfterAllCallba
     @Override
     public void beforeAll(ExtensionContext context) throws Exception {
         temporaryFolder.create();
-        cassandra.start();
-        elasticSearch.before();
+
+        Runnables.runParallel(
+            cassandra::start,
+            elasticSearch::before);
     }
 
     @Override
     public void afterAll(ExtensionContext context) {
         elasticSearch.after();
-        cassandra.stop();
-        temporaryFolder.delete();
+
+        Runnables.runParallel(
+            cassandra::stop,
+            elasticSearch::after);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/9d023bea/server/queue/queue-rabbitmq/pom.xml
----------------------------------------------------------------------
diff --git a/server/queue/queue-rabbitmq/pom.xml b/server/queue/queue-rabbitmq/pom.xml
index c2fff5b..06ba537 100644
--- a/server/queue/queue-rabbitmq/pom.xml
+++ b/server/queue/queue-rabbitmq/pom.xml
@@ -34,7 +34,12 @@
 
     <dependencies>
         <dependency>
-            <groupId>org.apache.james</groupId>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>james-server-util-java8</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
             <artifactId>james-server-util-java8</artifactId>
             <type>test-jar</type>
             <scope>test</scope>

http://git-wip-us.apache.org/repos/asf/james-project/blob/9d023bea/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/DockerClusterRabbitMQExtension.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/DockerClusterRabbitMQExtension.java b/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/DockerClusterRabbitMQExtension.java
index 000fef6..1f8cc0f 100644
--- a/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/DockerClusterRabbitMQExtension.java
+++ b/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/DockerClusterRabbitMQExtension.java
@@ -19,6 +19,7 @@
 package org.apache.james.queue.rabbitmq;
 
 import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.james.util.Runnables;
 import org.junit.jupiter.api.extension.AfterEachCallback;
 import org.junit.jupiter.api.extension.BeforeEachCallback;
 import org.junit.jupiter.api.extension.ExtensionContext;
@@ -27,6 +28,7 @@ import org.junit.jupiter.api.extension.ParameterResolutionException;
 import org.junit.jupiter.api.extension.ParameterResolver;
 import org.testcontainers.containers.Network;
 
+import com.github.fge.lambdas.Throwing;
 import com.google.common.collect.ImmutableList;
 import com.rabbitmq.client.Address;
 
@@ -39,7 +41,7 @@ public class DockerClusterRabbitMQExtension implements BeforeEachCallback, After
     private Network network;
 
     @Override
-    public void beforeEach(ExtensionContext context) throws Exception {
+    public void beforeEach(ExtensionContext context) {
         String cookie = DigestUtils.sha1Hex("secret cookie here");
 
         network = Network.NetworkImpl.builder()
@@ -51,15 +53,20 @@ public class DockerClusterRabbitMQExtension implements BeforeEachCallback, After
         DockerRabbitMQ rabbitMQ2 = DockerRabbitMQ.withCookieAndNodeName(RABBIT_2, cookie, "rabbit@rabbit2", network);
         DockerRabbitMQ rabbitMQ3 = DockerRabbitMQ.withCookieAndNodeName(RABBIT_3, cookie, "rabbit@rabbit3", network);
 
-        rabbitMQ1.start();
-        rabbitMQ2.start();
-        rabbitMQ3.start();
+        Runnables.runParallel(
+            rabbitMQ1::start,
+            rabbitMQ2::start,
+            rabbitMQ3::start);
 
-        rabbitMQ2.join(rabbitMQ1);
-        rabbitMQ3.join(rabbitMQ1);
+        Runnables.runParallel(
+            Throwing.runnable(() -> rabbitMQ2.join(rabbitMQ1)),
+            Throwing.runnable(() -> rabbitMQ3.join(rabbitMQ1)));
 
-        rabbitMQ2.startApp();
-        rabbitMQ3.startApp();
+
+
+        Runnables.runParallel(
+            Throwing.runnable(rabbitMQ2::startApp),
+            Throwing.runnable(rabbitMQ3::startApp));
 
         cluster = new DockerRabbitMQCluster(rabbitMQ1, rabbitMQ2, rabbitMQ3);
     }
@@ -93,9 +100,10 @@ public class DockerClusterRabbitMQExtension implements BeforeEachCallback, After
         }
 
         public void stop() {
-            rabbitMQ1.stop();
-            rabbitMQ2.stop();
-            rabbitMQ3.stop();
+            Runnables.runParallel(
+                rabbitMQ1::stop,
+                rabbitMQ2::stop,
+                rabbitMQ3::stop);
         }
 
         public DockerRabbitMQ getRabbitMQ1() {


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


[06/13] james-project git commit: JAMES-2448 Start camel context before loading processors

Posted by bt...@apache.org.
JAMES-2448 Start camel context before loading processors


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

Branch: refs/heads/master
Commit: b374cf9f5ca1cb3645e7269dc5709e0adc33288e
Parents: a8f83ab
Author: benwa <bt...@linagora.com>
Authored: Mon Jul 2 11:11:33 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Thu Jul 5 08:58:13 2018 +0700

----------------------------------------------------------------------
 .../mailetcontainer/impl/camel/CamelCompositeProcessor.java      | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/b374cf9f/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelCompositeProcessor.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelCompositeProcessor.java b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelCompositeProcessor.java
index 14aeaeb..06e34cd 100644
--- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelCompositeProcessor.java
+++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelCompositeProcessor.java
@@ -72,14 +72,12 @@ public class CamelCompositeProcessor extends AbstractStateCompositeProcessor imp
     @Override
     @PostConstruct
     public void init() throws Exception {
-        super.init();
-
         // Make sure the camel context get started
         // See https://issues.apache.org/jira/browse/JAMES-1069
         if (getCamelContext().getStatus().isStopped()) {
             getCamelContext().start();
         }
-
+        super.init();
     }
 
     @PreDestroy


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


[02/13] james-project git commit: JAMES-2435 Adding a How to 'IMAP server'

Posted by bt...@apache.org.
JAMES-2435 Adding a How to 'IMAP server'


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

Branch: refs/heads/master
Commit: 644ea0f745f7a8f097d9880ba54b07123885a0c4
Parents: 863da41
Author: benwa <bt...@linagora.com>
Authored: Thu Jun 21 11:36:33 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jul 4 17:26:18 2018 +0700

----------------------------------------------------------------------
 src/homepage/howTo/imap-server.html             | 250 +++++++++++++++++++
 .../images/guice-jpa-architecture-overview.png  | Bin 0 -> 41998 bytes
 2 files changed, 250 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/644ea0f7/src/homepage/howTo/imap-server.html
----------------------------------------------------------------------
diff --git a/src/homepage/howTo/imap-server.html b/src/homepage/howTo/imap-server.html
new file mode 100644
index 0000000..aff1bb2
--- /dev/null
+++ b/src/homepage/howTo/imap-server.html
@@ -0,0 +1,250 @@
+---
+layout: default
+---
+<!--
+    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.
+-->
+<link href="assets/css/lightbox.css" rel="stylesheet">
+<link href="assets/css/lity.min.css" rel="stylesheet" />
+<div id="wrapper">
+    <div class="apache_ref">
+        <a href="https://www.apache.org" alt="apache foundation link"><img src="https://www.apache.org/foundation/press/kit/asf_logo.svg" title="apache foundation logo"/></a>
+    </div>
+    <div class="apache_ref_mobile">
+        <a href="https://www.apache.org" alt="apache foundation link">The Apache Software Foundation</a>
+    </div>
+    <div class="apache_ref_left">
+        <a href="https://www.apache.org/events/current-event.html" alt="apache foundation event"><img src="https://www.apache.org/events/current-event-234x60.png" title="apache foundation event logo"/></a>
+    </div>
+    <div class="apache_ref_left_mobile">
+        <a href="https://www.apache.org/events/current-event.html" alt="apache foundation event"><img src="https://www.apache.org/events/current-event-234x60.png" title="apache foundation event logo"/></a>
+    </div>
+
+    <!-- Header -->
+    <header id="header" class="alt">
+        <div class="logo"><a href="/index.html" alt="Apache James"><img src="/images/james.svg" alt="james logo"/></a></div>
+        <h1 class="hidden">James Enterprise Mail Server</h1>
+        <h2>Emails at the heart of your business logic</h2>
+    </header>
+
+    <!-- Main -->
+    <div id="main">
+
+        <!-- Introduction -->
+        <section id="intro" class="main special">
+            <div class="">
+                <div class="content align-left">
+                    <header class="major">
+                        <h1><b>Setting up an IMAP server</b></h1>
+                    </header>
+
+                    <p>
+                        This document will present how to set up a James server in order to serve as a personal IMAP + SMTP
+                        server. We will cover:
+                    </p>
+
+                    <ul>
+                        <li>DNS creation and MX record</li>
+                        <li>Server components description</li>
+                        <li>Generation of a custom keystore</li>
+                        <li>Starting James</li>
+                        <li>Basic James administration</li>
+                        <li>Additional features one might want to enable...</li>
+                    </ul>
+
+                    <p>
+                        This guide rely on the JPA Guice Docker image. To run it, one need to have docker installed.
+                    </p>
+
+                    <header class="major">
+                        <h2><b>DNS resolution</b></h2>
+                    </header>
+
+                    <p>
+                        Someone willing to send you an email will first have to discover which IP your mail server have.
+                        The way this is achieved is through MX (means Mail eXchange) DNS record.
+                    </p>
+
+                    <p>
+                        Imagine bob@domain.org sends a mail to alice@company.com. Bob will:
+                    </p>
+
+                    <ol>
+                        <li>Ask <code>company.com</code> DNS server its MX entries</li>
+                        <li><code>company.com</code> respond that it is <code>mx.company.com</code></li>
+                        <li>Bob resolves <code>mx.company.com</code> ip address...</li>
+                        <li>And can establish a connection to <code>mx.company.com</code> to send an email to Alice</li>
+                    </ol>
+
+                    <p>All is needed is a MX entry in domain name resolution pointing to the future IP of your James server.</p>
+
+                    <header class="major">
+                        <h2><b>JAMES architecture</b></h2>
+                    </header>
+
+                    <p>JPA guice docker image relies on an embedded derby database for storing data. Note that Apache Lucene library
+                        is used for email search. A mail queue is implemented on top of an embedded Apache ActiveMQ. Hence James do not need
+                        any external service for being running.
+                    </p>
+
+                    <img src="/images/guice-jpa-architecture-overview.png">
+
+                    <p>
+                        JPA guice offers the following protocols:
+                    </p>
+
+                    <ul class="no-padding">
+                        <li><b>SMTP</b> For receiving emails</li>
+                        <li><b>IMAP</b> For reading emails</li>
+                        <li><b><a href="http://james.apache.org/server/manage-webadmin.html">WebAdmin</a></b> is a REST API allowing you to manage Apache JAMES</li>
+                    </ul>
+
+                    <p>The following protocols are also available:</p>
+
+                    <ul class="no-padding">
+                        <li><b>LMTP</b> local version of SMTP</li>
+                        <li><b>POP3</b> For reading emails. Lacks tests</li>
+                        <li><b>JMX</b> is used by a <a href="http://james.apache.org/server/manage-cli.html">command line</a> for administrating Apache James</li>
+                        <li>And <a href="http://james.apache.org/server/feature-protocols.html">more</a>...</li>
+                    </ul>
+
+                    <header class="major">
+                        <h2><b>Generation of a custom keystore</b></h2>
+                    </header>
+
+                    <p>In order to maintain a good level of privacy and security, James is relying on TLS cryptography
+                    for securing exchanges. We thus need to generate our own personal keystore. Note that this guide do not
+                    cover generating a keystore from SSL certificates. A security exception might be configured on the Mail
+                    User Agent.</p>
+
+                    <p>In order to create a keystore, please run: <code>keytool -genkey -alias james -keyalg RSA -keystore /path/to/james/conf/keystore</code>.
+                    James is configured with a default password <code>james72laBalle</code> (used to read the keystore). However, we will be overriding the
+                    configuration of the docker image, so you can be defining your own.</p>
+
+                    <header class="major">
+                        <h2><b>Starting james</b></h2>
+                    </header>
+
+                    <p>We want to override the configuration of the docker image with a volume.</p>
+
+                    <p>First let's retrieve a valid configuration:</p>
+
+                    <pre><code>$ git clone https://github.com/apache/james-project
+$ cp -rf james-project/dockerfiles/run/guice/jpa/destination/conf conf
+$ mv keystore conf/keystore</code></pre>
+
+                    <p>Modify all protocol configuration files to match your keystore password (imapserver.xml, lmtpserver.xml, managesieveserver.xml, pop3server.xml, smtpserver.xml).</p>
+
+                    <p>We will create a local folder for holding data out of the container:</p>
+
+                    <pre><code>mkdir var</code></pre>
+
+
+                    <p>Then, let's start James:</p>
+
+                    <pre><code>docker run \
+    --name james_run \
+    --port "25:25" --port "465:465" --port "587:587" \
+    --port "143:143"  --port "993:993" \
+    --volume "$PWD/conf:/root/conf/" \
+    --volume "$PWD/var:/root/var/" \
+linagora/james-jpa-guice:latest</code></pre>
+
+
+                    <header class="major">
+                        <h2><b>Administrating James</b></h2>
+                    </header>
+
+                    <p>We now have a running James server. We just need to tell him which users and domains it should be handling mails for.
+                    We will, in order to do this, use the command line:</p>
+
+                    <pre><code>docker exec james_run java -jar /root/james-cli.jar AddDomain domain.tld
+docker exec james_run java -jar /root/james-cli.jar AddUser user@domain.tld secretPassword</code></pre>
+
+                    <p>The command line client can be used for several other purposes like managing quota, setting addresses redirections, etc..</p>
+
+                    <header class="major">
+                        <h2><b>Additional features</b></h2>
+                    </header>
+
+                    <p>James is a large project with many features. You can go further and complete your installation with
+                    an <a href="http://james.apache.org/server/config-antispam.html">AntiSpam system</a>, or set up
+                        <a href="http://james.apache.org/server/metrics.html">metric display</a>, collect logs in ElasticSearch for a display in Kibana,
+                    and much more!</p>
+
+                    <p>Also, James offers support for <a href="https://medium.com/linagora-engineering/installing-james-3-0-with-spf-verification-421b26b92f11">SPF</a>
+                        and DKIM standard, which increase the trust external people can get in your mail system.</p>
+
+                </div>
+                <footer class="major">
+                    <ul class="actions align-center">
+                        <li><a href="index.html" class="button">go back to other how-tos</a></li>
+                    </ul>
+                </footer>
+            </div>
+        </section>
+
+    </div>
+    <footer id="footer" class="major">
+        <section>
+            <h2>James</h2>
+            <ul class="no-padding">
+                <li class="no-padding"><a href="https://james.apache.org/#intro" class="active">About</a></li>
+                <li class="no-padding"><a href="https://james.apache.org/#first">Get Started</a></li>
+                <li class="no-padding"><a href="https://james.apache.org/#posts">Last Posts</a></li>
+                <li class="no-padding"><a href="https://james.apache.org/#second">Community</a></li>
+                <li class="no-padding"><a href="https://james.apache.org/#third">Contribute</a></li>
+                <li class="no-padding"><a href="https://james.apache.org/"><span class="fa fa-external-link"></span> Documentation</a></li>
+            </ul>
+        </section>
+        <section>
+            <h2>Connect</h2>
+            <ul class="icons">
+                <li><a href="https://james.apache.org/mail.html" class="icon fa-envelope-o alt"><span class="label">Mailing-list</span></a></li>
+                <li><a href="https://gitter.im/apache/james-project" class="icon fa-wechat alt"><span class="label">Gitter</span></a></li>
+                <li><a href="https://github.com/apache/james-project" class="icon fa-github alt"><span class="label">GitHub</span></a></li>
+                <li><a href="https://twitter.com/ApacheJames" class="icon fa-twitter alt"><span class="label">Twitter</span></a></li>
+                <li><a href="https://james.apache.org/support.html" class="icon fa-briefcase alt"><span class="label">Support</span></a></li>
+                <li><a href="http://www.apache.org/events/current-event" class="icon fa-calendar alt"><span class="label">Apache Foundation events</span></a></li>
+            </ul>
+        </section>
+        <section class="legal-section">
+            <h2>Copyright</h2>
+            Apache James and related projects are trademarks of the Apache Software Foundation.<br/>
+            <a href="https://www.apache.org/">Copyright 2006-2018 The Apache Software Foundation. All Rights Reserved.</a><br/>
+            <a href="https://www.apache.org/licenses/">License</a><br/>
+            <a href="https://www.apache.org/foundation/sponsorship.html">Donate</a> to support the Apache Foundation<br/>
+            <a href="https://www.apache.org/foundation/thanks.html">Thanks</a><br/>
+            Design: <a href="https://html5up.net">HTML5 UP</a><br/>
+            Thanks to <a href="http://www.neoma-interactive.com/">Neoma by Linagora</a> for the website design
+        </section>
+    </footer>
+</div>
+
+<!-- Scripts -->
+<script src="assets/js/jquery.min.js"></script>
+<script src="assets/js/jquery.scrollex.min.js"></script>
+<script src="assets/js/jquery.scrolly.min.js"></script>
+<script src="assets/js/skel.min.js"></script>
+<script src="assets/js/util.js"></script>
+<script src="assets/js/lightbox.js"></script>
+<script src="assets/js/github-fetch.js"></script>
+<script src="assets/js/lity.min.js"></script>
+<!--[if lte IE 8]><script src="assets/js/ie/respond.min.js"></script><![endif]-->
+<script src="assets/js/main.js"></script>
+

http://git-wip-us.apache.org/repos/asf/james-project/blob/644ea0f7/src/homepage/images/guice-jpa-architecture-overview.png
----------------------------------------------------------------------
diff --git a/src/homepage/images/guice-jpa-architecture-overview.png b/src/homepage/images/guice-jpa-architecture-overview.png
new file mode 100644
index 0000000..d479ef0
Binary files /dev/null and b/src/homepage/images/guice-jpa-architecture-overview.png differ


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


[11/13] james-project git commit: JAMES-2394 Add a missing JMAP configuration page

Posted by bt...@apache.org.
JAMES-2394 Add a missing JMAP configuration page


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

Branch: refs/heads/master
Commit: 4c27a8a9f066906080c164b10defc2cbfdeecfc2
Parents: b44df19
Author: benwa <bt...@linagora.com>
Authored: Thu May 10 17:25:59 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Thu Jul 5 08:59:57 2018 +0700

----------------------------------------------------------------------
 src/site/site.xml                    |  1 +
 src/site/xdoc/server/config-jmap.xml | 63 +++++++++++++++++++++++++++++++
 src/site/xdoc/server/config.xml      |  7 +++-
 3 files changed, 70 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/4c27a8a9/src/site/site.xml
----------------------------------------------------------------------
diff --git a/src/site/site.xml b/src/site/site.xml
index 1ed9248..89e4eb2 100644
--- a/src/site/site.xml
+++ b/src/site/site.xml
@@ -123,6 +123,7 @@
                         <item name="SMTP LMTP" href="/server/config-smtp-lmtp.html" />
                         <item name="POP3" href="/server/config-pop3.html" />
                         <item name="IMAP4" href="/server/config-imap4.html" />
+                        <item name="JMAP" href="/server/config-jmap.html" />
                         <item name="Mailet Container" href="/server/config-mailetcontainer.html" />
                         <item name="FetchMail" href="/server/config-fetchmail.html" />
                         <item name="SSL/TLS" href="/server/config-ssl-tls.html" />

http://git-wip-us.apache.org/repos/asf/james-project/blob/4c27a8a9/src/site/xdoc/server/config-jmap.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/server/config-jmap.xml b/src/site/xdoc/server/config-jmap.xml
new file mode 100644
index 0000000..88addd9
--- /dev/null
+++ b/src/site/xdoc/server/config-jmap.xml
@@ -0,0 +1,63 @@
+<?xml version="1.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.
+-->
+<document>
+
+    <properties>
+        <title>Apache James Server 3 - JMAP Configuration</title>
+    </properties>
+
+    <body>
+
+        <section name="JMAP configuration">
+
+            <p><a href="https://jmap.io/">JMAP</a>  is intended to be a new standard for email clients to connect to mail
+                stores. It therefore intends to primarily replace IMAP + SMTP submission. It is also designed to be more
+                generic. It does not replace MTA-to-MTA SMTP transmission.</p>
+
+            <p>Cassandra Guice proposes a JMAP implementation.</p>
+
+            <subsection name="jmap.properties">
+
+                <p>Consult <a href="https://github.com/apache/james-project/blob/master/dockerfiles/run/guice/cassandra/destination/conf/jmap.properties">jmap.properties</a> in GIT to get some examples and hints.</p>
+
+                <br/>
+
+                <dl>
+                    <dt><strong>enabled</strong></dt>
+                    <dd>true/false. Governs whether JMAP should be enabled</dd>
+
+                    <dt><strong>tls.keystoreURL</strong></dt>
+                    <dd>Keystore to be used for generating authentication tokens for password authentication mechanism.
+                    This should not be the same keystore than the ones used by TLS based protocols.</dd>
+
+                    <dt><strong>tls.secret</strong></dt>
+                    <dd>Password used to read the keystore</dd>
+
+                    <dt><strong>jwt.publickeypem.url</strong></dt>
+                    <dd>Optional. JWT tokens allows request to bypass authentication</dd>
+                </dl>
+
+            </subsection>
+
+        </section>
+
+    </body>
+
+</document>

http://git-wip-us.apache.org/repos/asf/james-project/blob/4c27a8a9/src/site/xdoc/server/config.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/server/config.xml b/src/site/xdoc/server/config.xml
index 807b22d..073c97e 100644
--- a/src/site/xdoc/server/config.xml
+++ b/src/site/xdoc/server/config.xml
@@ -38,7 +38,7 @@
     <p>Please note that the configuration is dependent of the wiring you have chosen. Some configuration files are specific to
     some back-ends, to some protocols. Please also note that some configuration files are not required for Guice. In this
     case, it will be specified.</p>
-       
+
     <p>In every configuration files, you can use the following notation to use an environment variable: <code>${env:MY_VAR}</code>.
     If <code>MY_VAR</code> exists, it will be replaced by the matching environment variable.
     If it does not, <code>${env:MY_VAR}</code> will be kept as is.</p>
@@ -123,6 +123,11 @@
         <td><a href="config-fetchmail.html">FetchMail Configuration (Spring only)</a></td>
         <td></td>
       </tr>
+      <tr>
+        <td><a href="https://github.com/apache/james-project/blob/master/dockerfiles/run/guice/cassandra/destination/conf/jmap.properties">jmap.properties</a></td>
+        <td><a href="config-jmap.html">JMAP Configuration (Guice only)</a></td>
+        <td></td>
+      </tr>
 
     </table>
     


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


[08/13] james-project git commit: JAMES-2448 Upgrade camel version

Posted by bt...@apache.org.
JAMES-2448 Upgrade camel version


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

Branch: refs/heads/master
Commit: 612010dd222dbd01bb59e2e4be53e527b89cc38e
Parents: 85a4404
Author: benwa <bt...@linagora.com>
Authored: Mon Jul 2 00:27:46 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Thu Jul 5 08:58:13 2018 +0700

----------------------------------------------------------------------
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/612010dd/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index f776df9..35918d8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -583,7 +583,7 @@
 
         <activemq.version>5.15.2</activemq.version>
         <apache-mime4j.version>0.8.2</apache-mime4j.version>
-        <camel.version>2.19.4</camel.version>
+        <camel.version>2.21.1</camel.version>
         <derby.version>10.9.1.0</derby.version>
         <hadoop.version>1.1.1</hadoop.version>
         <hbase.version>0.94.27</hbase.version>


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


[09/13] james-project git commit: JAMES-2448 Avoid pushing logic into Apache Camel

Posted by bt...@apache.org.
JAMES-2448 Avoid pushing logic into Apache Camel

This comes at a huge price in readability, and when starting Apache Camel


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

Branch: refs/heads/master
Commit: 85a440469094330beb7d7c8c152d9e9296ae11cb
Parents: 32d59cc
Author: benwa <bt...@linagora.com>
Authored: Mon Jul 2 00:13:36 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Thu Jul 5 08:58:13 2018 +0700

----------------------------------------------------------------------
 .../mailetcontainer/impl/MatcherMailetPair.java |   5 +
 .../impl/camel/CamelMailetProcessor.java        | 104 +++++++++----------
 .../impl/camel/CamelProcessor.java              |  16 ++-
 .../impl/camel/MatcherSplitter.java             |   7 +-
 .../lib/AbstractStateMailetProcessor.java       |   2 +-
 5 files changed, 66 insertions(+), 68 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/85a44046/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/MatcherMailetPair.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/MatcherMailetPair.java b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/MatcherMailetPair.java
index 0c25977..b2d1540 100644
--- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/MatcherMailetPair.java
+++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/MatcherMailetPair.java
@@ -51,4 +51,9 @@ public class MatcherMailetPair {
         return mailet;
     }
 
+    public String getOnMatchException() {
+        return mailet.getMailetConfig()
+            .getInitParameter("onMatchException");
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/85a44046/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessor.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessor.java b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessor.java
index 2410374..1c9a473 100644
--- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessor.java
+++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessor.java
@@ -28,17 +28,16 @@ import org.apache.camel.CamelContextAware;
 import org.apache.camel.CamelExecutionException;
 import org.apache.camel.Exchange;
 import org.apache.camel.ExchangePattern;
-import org.apache.camel.Processor;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.model.RouteDefinition;
 import org.apache.camel.processor.aggregate.UseLatestAggregationStrategy;
+import org.apache.james.lifecycle.api.LifecycleUtil;
 import org.apache.james.mailetcontainer.impl.MatcherMailetPair;
 import org.apache.james.mailetcontainer.lib.AbstractStateMailetProcessor;
 import org.apache.james.metrics.api.MetricFactory;
 import org.apache.mailet.Mail;
 import org.apache.mailet.Mailet;
-import org.apache.mailet.MailetConfig;
 import org.apache.mailet.Matcher;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -56,7 +55,6 @@ public class CamelMailetProcessor extends AbstractStateMailetProcessor implement
 
     private ProducerTemplate producerTemplate;
 
-    private final UseLatestAggregationStrategy aggr = new UseLatestAggregationStrategy();
     private final MetricFactory metricFactory;
     private List<MatcherMailetPair> pairs;
 
@@ -114,7 +112,7 @@ public class CamelMailetProcessor extends AbstractStateMailetProcessor implement
     protected void setupRouting(List<MatcherMailetPair> pairs) throws MessagingException {
         try {
             this.pairs = pairs;
-            context.addRoutes(new MailetContainerRouteBuilder(pairs));
+            context.addRoutes(new MailetContainerRouteBuilder(this, metricFactory, pairs));
         } catch (Exception e) {
             throw new MessagingException("Unable to setup routing for MailetMatcherPairs", e);
         }
@@ -124,84 +122,82 @@ public class CamelMailetProcessor extends AbstractStateMailetProcessor implement
      * {@link RouteBuilder} which construct the Matcher and Mailet routing use
      * Camel DSL
      */
-    private final class MailetContainerRouteBuilder extends RouteBuilder {
+    private static class MailetContainerRouteBuilder extends RouteBuilder {
+
+        private final CamelMailetProcessor container;
 
         private final List<MatcherMailetPair> pairs;
+        private final MetricFactory metricFactory;
 
-        public MailetContainerRouteBuilder(List<MatcherMailetPair> pairs) {
+        private MailetContainerRouteBuilder(CamelMailetProcessor container, MetricFactory metricFactory, List<MatcherMailetPair> pairs) {
+            this.container = container;
+            this.metricFactory = metricFactory;
             this.pairs = pairs;
         }
 
         @Override
         public void configure() {
-            Processor disposeProcessor = new DisposeProcessor();
-            Processor completeProcessor = new CompleteProcessor();
-            Processor stateChangedProcessor = new StateChangedProcessor();
-
-            String state = getState();
+            String state = container.getState();
+            CamelProcessor terminatingMailetProcessor = new CamelProcessor(metricFactory, container, new TerminatingMailet());
 
-            RouteDefinition processorDef = from(getEndpoint())
+            RouteDefinition processorDef = from(container.getEndpoint())
                 .routeId(state)
                 .setExchangePattern(ExchangePattern.InOnly);
 
             for (MatcherMailetPair pair : pairs) {
-                Matcher matcher = pair.getMatcher();
-                Mailet mailet = pair.getMailet();
-
-                MailetConfig mailetConfig = mailet.getMailetConfig();
-                String onMatchException = mailetConfig.getInitParameter("onMatchException");
-
-                CamelProcessor mailetProccessor = new CamelProcessor(metricFactory, mailet, CamelMailetProcessor.this);
-                // Store the matcher to use for splitter in properties
-                MatcherSplitter matcherSplitter = new MatcherSplitter(metricFactory, CamelMailetProcessor.this, matcher, onMatchException);
+                CamelProcessor mailetProccessor = new CamelProcessor(metricFactory, container, pair.getMailet());
+                MatcherSplitter matcherSplitter = new MatcherSplitter(metricFactory, container, pair);
 
                 processorDef
                         // do splitting of the mail based on the stored matcher
-                        .split().method(matcherSplitter).aggregationStrategy(aggr)
-
-                        .choice().when(new MatcherMatch()).process(mailetProccessor).end()
-
-                        .choice().when(new MailStateEquals(Mail.GHOST)).process(disposeProcessor).stop().end()
-
-                        .choice().when(new MailStateNotEquals(state)).process(stateChangedProcessor).process(completeProcessor).stop().end();
+                        .split().method(matcherSplitter)
+                            .aggregationStrategy(new UseLatestAggregationStrategy())
+                        .process(exchange -> handleMailet(exchange, container, mailetProccessor));
             }
 
-            Processor terminatingMailetProcessor = new CamelProcessor(metricFactory, new TerminatingMailet(), CamelMailetProcessor.this);
-
             processorDef
-                    // start choice
-                    .choice()
-
-                    // when the mail state did not change till yet ( the end of
-                    // the route) we need to call the TerminatingMailet to
-                    // make sure we don't fall into a endless loop
-                    .when(new MailStateEquals(state)).process(terminatingMailetProcessor).stop()
-
-                    // dispose when needed
-                    .when(new MailStateEquals(Mail.GHOST)).process(disposeProcessor).stop()
-
-                    // this container is complete
-                    .otherwise().process(completeProcessor).stop();
+                .process(exchange -> terminateSmoothly(exchange, container, terminatingMailetProcessor));
 
         }
 
-        private final class CompleteProcessor implements Processor {
+        private void terminateSmoothly(Exchange exchange, CamelMailetProcessor container, CamelProcessor terminatingMailetProcessor) throws Exception {
+            Mail mail = exchange.getIn().getBody(Mail.class);
+            if (mail.getState().equals(container.getState())) {
+                terminatingMailetProcessor.process(mail);
+            }
+            if (mail.getState().equals(Mail.GHOST)) {
+                dispose(exchange, mail);
+            }
+            complete(exchange, container);
+        }
 
-            @Override
-            public void process(Exchange ex) {
-                LOGGER.debug("End of mailetprocessor for state {} reached", getState());
-                ex.setProperty(Exchange.ROUTE_STOP, true);
+        private void handleMailet(Exchange exchange, CamelMailetProcessor container, CamelProcessor mailetProccessor) throws Exception {
+            Mail mail = exchange.getIn().getBody(Mail.class);
+            boolean isMatched = mail.removeAttribute(MatcherSplitter.MATCHER_MATCHED_ATTRIBUTE) != null;
+            if (isMatched) {
+                mailetProccessor.process(mail);
+            }
+            if (mail.getState().equals(Mail.GHOST)) {
+                dispose(exchange, mail);
+                return;
+            }
+            if (!mail.getState().equals(container.getState())) {
+                container.toProcessor(mail);
+                complete(exchange, container);
             }
         }
 
-        private final class StateChangedProcessor implements Processor {
+        private void complete(Exchange exchange, CamelMailetProcessor container) {
+            LOGGER.debug("End of mailetprocessor for state {} reached", container.getState());
+            exchange.setProperty(Exchange.ROUTE_STOP, true);
+        }
 
-            @Override
-            public void process(Exchange arg0) throws Exception {
-                Mail mail = arg0.getIn().getBody(Mail.class);
-                toProcessor(mail);
-            }
+        private void dispose(Exchange exchange, Mail mail) throws MessagingException {
+            LifecycleUtil.dispose(mail.getMessage());
+            LifecycleUtil.dispose(mail);
 
+            // stop routing
+            exchange.setProperty(Exchange.ROUTE_STOP, true);
         }
 
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/85a44046/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelProcessor.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelProcessor.java b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelProcessor.java
index 3b3eba8..a1ae59a 100644
--- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelProcessor.java
+++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelProcessor.java
@@ -22,8 +22,6 @@ import java.io.Closeable;
 import java.util.List;
 import java.util.Locale;
 
-import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
 import org.apache.james.mailetcontainer.impl.MailetConfigImpl;
 import org.apache.james.mailetcontainer.impl.ProcessorUtil;
 import org.apache.james.mailetcontainer.lib.AbstractStateMailetProcessor.MailetProcessorListener;
@@ -42,7 +40,7 @@ import com.google.common.collect.ImmutableList;
 /**
  * Mailet wrapper which execute a Mailet in a Processor
  */
-public class CamelProcessor implements Processor {
+public class CamelProcessor {
     private static final Logger LOGGER = LoggerFactory.getLogger(CamelProcessor.class);
 
     private final MetricFactory metricFactory;
@@ -51,22 +49,20 @@ public class CamelProcessor implements Processor {
 
     /**
      * Mailet to call on process
-     *
-     * @param metricFactory
+     *  @param metricFactory
+     * @param processor
      * @param mailet
      */
-    public CamelProcessor(MetricFactory metricFactory, Mailet mailet, CamelMailetProcessor processor) {
+    public CamelProcessor(MetricFactory metricFactory, CamelMailetProcessor processor, Mailet mailet) {
         this.metricFactory = metricFactory;
-        this.mailet = mailet;
         this.processor = processor;
+        this.mailet = mailet;
     }
 
     /**
      * Call the wrapped mailet for the exchange
      */
-    @Override
-    public void process(Exchange exchange) throws Exception {
-        Mail mail = exchange.getIn().getBody(Mail.class);
+    public void process(Mail mail) throws Exception {
         long start = System.currentTimeMillis();
         TimeMetric timeMetric = metricFactory.timer(mailet.getClass().getSimpleName());
         Exception ex = null;

http://git-wip-us.apache.org/repos/asf/james-project/blob/85a44046/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/MatcherSplitter.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/MatcherSplitter.java b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/MatcherSplitter.java
index 016a0c9..21d721a 100644
--- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/MatcherSplitter.java
+++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/MatcherSplitter.java
@@ -32,6 +32,7 @@ import org.apache.camel.Body;
 import org.apache.camel.Handler;
 import org.apache.camel.InOnly;
 import org.apache.james.core.MailAddress;
+import org.apache.james.mailetcontainer.impl.MatcherMailetPair;
 import org.apache.james.mailetcontainer.impl.ProcessorUtil;
 import org.apache.james.mailetcontainer.lib.AbstractStateMailetProcessor.MailetProcessorListener;
 import org.apache.james.metrics.api.MetricFactory;
@@ -61,11 +62,11 @@ public class MatcherSplitter {
     private final Matcher matcher;
     private final String onMatchException;
 
-    public MatcherSplitter(MetricFactory metricFactory, CamelMailetProcessor container, Matcher matcher, String onMatchException) {
+    public MatcherSplitter(MetricFactory metricFactory, CamelMailetProcessor container, MatcherMailetPair pair) {
         this.metricFactory = metricFactory;
         this.container = container;
-        this.matcher = matcher;
-        this.onMatchException = Optional.ofNullable(onMatchException)
+        this.matcher = pair.getMatcher();
+        this.onMatchException = Optional.ofNullable(pair.getOnMatchException())
             .map(s -> s.trim().toLowerCase(Locale.US))
             .orElse(Mail.ERROR);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/85a44046/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessor.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessor.java b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessor.java
index 4666e98..99f3b1b 100644
--- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessor.java
+++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessor.java
@@ -383,7 +383,7 @@ public abstract class AbstractStateMailetProcessor implements MailProcessor, Con
      * Mailet which protect us to not fall into an endless loop caused by an
      * configuration error
      */
-    public final class TerminatingMailet extends GenericMailet {
+    public static class TerminatingMailet extends GenericMailet {
         /**
          * The name of the mailet used to terminate the mailet chain. The end of
          * the matcher/mailet chain must be a matcher that matches all mails and


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


[10/13] james-project git commit: JAMES-2451 JMAP NotImplemented exception do not report the not implemented method

Posted by bt...@apache.org.
JAMES-2451 JMAP NotImplemented exception do not report the not implemented method


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

Branch: refs/heads/master
Commit: b44df191d329ce0fe2dd0d1870a213e6cee9ed93
Parents: 8baa752
Author: Gautier DI FOLCO <gd...@linagora.com>
Authored: Tue Jul 3 17:39:27 2018 +0200
Committer: benwa <bt...@linagora.com>
Committed: Thu Jul 5 08:59:07 2018 +0700

----------------------------------------------------------------------
 .../integration/GetMailboxesMethodTest.java     |  3 +-
 .../integration/GetVacationResponseTest.java    |  3 +-
 .../integration/SetMailboxesMethodTest.java     |  6 ++-
 .../integration/SetMessagesMethodTest.java      |  6 ++-
 .../integration/SetVacationResponseTest.java    |  3 +-
 .../cucumber/GetMessagesMethodStepdefs.java     | 12 +++++-
 .../test/resources/cucumber/GetMessages.feature |  4 +-
 .../jmap/JmapFieldNotSupportedException.java    | 41 ++++++++++++++++++++
 .../james/jmap/methods/GetMessagesMethod.java   | 11 +++---
 .../james/jmap/methods/RequestHandler.java      | 26 +++++++------
 .../james/jmap/model/GetMailboxesRequest.java   |  5 ++-
 .../james/jmap/model/GetVacationRequest.java    |  5 ++-
 .../james/jmap/model/SetMessagesRequest.java    |  7 ++--
 .../james/jmap/model/SetVacationRequest.java    |  5 ++-
 .../model/mailbox/MailboxCreateRequest.java     |  7 ++--
 15 files changed, 105 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/b44df191/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMailboxesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMailboxesMethodTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMailboxesMethodTest.java
index 8348fe2..9cbc885 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMailboxesMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMailboxesMethodTest.java
@@ -140,7 +140,8 @@ public abstract class GetMailboxesMethodTest {
         .then()
             .statusCode(200)
             .body(NAME, equalTo("error"))
-            .body(ARGUMENTS + ".type", equalTo("Not yet implemented"));
+            .body(ARGUMENTS + ".type", equalTo("invalidArguments"))
+            .body(ARGUMENTS + ".description", equalTo("The field 'accountId' of 'GetMailboxesRequest' is not supported"));
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/b44df191/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetVacationResponseTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetVacationResponseTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetVacationResponseTest.java
index 9c941d2..0fe102f 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetVacationResponseTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetVacationResponseTest.java
@@ -261,7 +261,8 @@ public abstract class GetVacationResponseTest {
         .then()
             .statusCode(200)
             .body(NAME, equalTo("error"))
-            .body(ARGUMENTS + ".type", equalTo("Not yet implemented"));
+            .body(ARGUMENTS + ".type", equalTo("invalidArguments"))
+            .body(ARGUMENTS + ".description", equalTo("The field 'accountId' of 'GetVacationRequest' is not supported"));
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b44df191/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java
index 66e61e2..dae7e9e 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java
@@ -485,7 +485,8 @@ public abstract class SetMailboxesMethodTest {
         .then()
             .statusCode(200)
             .body(NAME, equalTo("error"))
-            .body(ARGUMENTS + ".type", equalTo("Not yet implemented"));
+            .body(ARGUMENTS + ".type", equalTo("invalidArguments"))
+            .body(ARGUMENTS + ".description", equalTo("The field 'role' of 'MailboxCreateRequest' is not supported"));
     }
 
     @Test
@@ -513,7 +514,8 @@ public abstract class SetMailboxesMethodTest {
         .then()
             .statusCode(200)
             .body(NAME, equalTo("error"))
-            .body(ARGUMENTS + ".type", equalTo("Not yet implemented"));
+            .body(ARGUMENTS + ".type", equalTo("invalidArguments"))
+            .body(ARGUMENTS + ".description", equalTo("The field 'sortOrder' of 'MailboxCreateRequest' is not supported"));
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/b44df191/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
index 3d5fda6..f3cbaa3 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
@@ -198,7 +198,8 @@ public abstract class SetMessagesMethodTest {
             .log().ifValidationFails()
             .statusCode(200)
             .body(NAME, equalTo("error"))
-            .body(ARGUMENTS + ".type", equalTo("Not yet implemented"));
+            .body(ARGUMENTS + ".type", equalTo("invalidArguments"))
+            .body(ARGUMENTS + ".description", equalTo("The field 'accountId' of 'SetMessagesRequest' is not supported"));
     }
 
     @Test
@@ -212,7 +213,8 @@ public abstract class SetMessagesMethodTest {
             .log().ifValidationFails()
             .statusCode(200)
             .body(NAME, equalTo("error"))
-            .body(ARGUMENTS + ".type", equalTo("Not yet implemented"));
+            .body(ARGUMENTS + ".type", equalTo("invalidArguments"))
+            .body(ARGUMENTS + ".description", equalTo("The field 'ifInState' of 'SetMessagesRequest' is not supported"));
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/b44df191/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetVacationResponseTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetVacationResponseTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetVacationResponseTest.java
index d5f4257..a5c5ad8 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetVacationResponseTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetVacationResponseTest.java
@@ -388,7 +388,8 @@ public abstract class SetVacationResponseTest {
         .then()
             .statusCode(200)
             .body(NAME, equalTo("error"))
-            .body(ARGUMENTS + ".type", equalTo("Not yet implemented"));
+            .body(ARGUMENTS + ".type", equalTo("invalidArguments"))
+            .body(ARGUMENTS + ".description", equalTo("The field 'accountId' of 'SetVacationRequest' is not supported"));
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/b44df191/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java
index f9bd5db..e2bc4ca 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java
@@ -505,8 +505,16 @@ public class GetMessagesMethodStepdefs {
         return Joiner.on(": ").join(pair);
     }
 
-    @Then("^an error \"([^\"]*)\" is returned$")
-    public void error(String type) {
+    @Then("^an error \"([^\"]*)\" with type \"([^\"]*)\" is returned$")
+    public void error(String description, String type) {
+        assertThat(httpClient.response.getStatusLine().getStatusCode()).isEqualTo(200);
+        assertThat(httpClient.jsonPath.<String>read(NAME)).isEqualTo("error");
+        assertThat(httpClient.jsonPath.<String>read(ARGUMENTS + ".type")).isEqualTo(type);
+        assertThat(httpClient.jsonPath.<String>read(ARGUMENTS + ".description")).isEqualTo(description);
+    }
+
+    @Then("^an error of type \"([^\"]*)\" is returned$")
+    public void errorType(String type) {
         assertThat(httpClient.response.getStatusLine().getStatusCode()).isEqualTo(200);
         assertThat(httpClient.jsonPath.<String>read(NAME)).isEqualTo("error");
         assertThat(httpClient.jsonPath.<String>read(ARGUMENTS + ".type")).isEqualTo(type);

http://git-wip-us.apache.org/repos/asf/james-project/blob/b44df191/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
index 7b5f854..8237ade 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
@@ -36,7 +36,7 @@ Feature: GetMessages method
 
   Scenario: Retrieving messages with a non null accountId should return a NotSupported error
     When "alice@domain.tld" ask for messages using its accountId
-    Then an error "Not yet implemented" is returned
+    Then an error "The field 'accountId' of 'GetMessagesMethod' is not supported" with type "invalidArguments" is returned
 
   Scenario: Unknown arguments should be ignored when retrieving messages
     When "alice@domain.tld" ask for messages using unknown arguments
@@ -46,7 +46,7 @@ Feature: GetMessages method
 
   Scenario: Retrieving messages with invalid argument should return an InvalidArguments error
     When "alice@domain.tld" ask for messages using invalid argument
-    Then an error "invalidArguments" is returned
+    Then an error of type "invalidArguments" is returned
     And the description is "N/A (through reference chain: org.apache.james.jmap.model.Builder["ids"])"
 
   Scenario: Retrieving messages should return empty list when no message

http://git-wip-us.apache.org/repos/asf/james-project/blob/b44df191/server/protocols/jmap/src/main/java/org/apache/james/jmap/JmapFieldNotSupportedException.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/JmapFieldNotSupportedException.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/JmapFieldNotSupportedException.java
new file mode 100644
index 0000000..ed35fa8
--- /dev/null
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/JmapFieldNotSupportedException.java
@@ -0,0 +1,41 @@
+/****************************************************************
+ * 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.commons.lang.NotImplementedException;
+
+public class JmapFieldNotSupportedException extends NotImplementedException {
+    private final String issuer;
+    private final String field;
+
+    public JmapFieldNotSupportedException(String issuer, String field) {
+        super();
+        this.issuer = issuer;
+        this.field = field;
+    }
+
+    public String getField() {
+        return field;
+    }
+
+    public String getIssuer() {
+        return issuer;
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/b44df191/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
index 7c7f066..ae4c0e3 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
@@ -27,7 +27,7 @@ import java.util.stream.Stream;
 
 import javax.inject.Inject;
 
-import org.apache.commons.lang.NotImplementedException;
+import org.apache.james.jmap.JmapFieldNotSupportedException;
 import org.apache.james.jmap.json.FieldNamePropertyFilter;
 import org.apache.james.jmap.model.ClientId;
 import org.apache.james.jmap.model.GetMessagesRequest;
@@ -61,6 +61,7 @@ import com.google.common.collect.ImmutableSet;
 public class GetMessagesMethod implements Method {
 
     public static final String HEADERS_FILTER = "headersFilter";
+    private static final String ISSUER = "GetMessagesMethod";
     private static final Logger LOGGER = LoggerFactory.getLogger(GetMessagesMethod.class);
     private static final Method.Request.Name METHOD_NAME = Method.Request.name("getMessages");
     private static final Method.Response.Name RESPONSE_NAME = Method.Response.name("messages");
@@ -128,7 +129,7 @@ public class GetMessagesMethod implements Method {
     }
 
     private GetMessagesResponse getMessagesResponse(MailboxSession mailboxSession, GetMessagesRequest getMessagesRequest) {
-        getMessagesRequest.getAccountId().ifPresent((input) -> notImplemented());
+        getMessagesRequest.getAccountId().ifPresent((input) -> notImplemented("accountId"));
 
         try {
             return GetMessagesResponse.builder()
@@ -187,7 +188,7 @@ public class GetMessagesMethod implements Method {
         };
     }
 
-    private static void notImplemented() {
-        throw new NotImplementedException();
+    private static void notImplemented(String field) {
+        throw new JmapFieldNotSupportedException(ISSUER, field);
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/b44df191/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/RequestHandler.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/RequestHandler.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/RequestHandler.java
index f62273c..a8c42f3 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/RequestHandler.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/RequestHandler.java
@@ -30,7 +30,7 @@ import java.util.stream.Stream;
 
 import javax.inject.Inject;
 
-import org.apache.commons.lang.NotImplementedException;
+import org.apache.james.jmap.JmapFieldNotSupportedException;
 import org.apache.james.jmap.model.AuthenticatedProtocolRequest;
 import org.apache.james.jmap.model.ProtocolResponse;
 import org.apache.james.mailbox.MailboxSession;
@@ -77,24 +77,28 @@ public class RequestHandler {
                         return method.process(jmapRequest, request.getClientId(), mailboxSession);
                     } catch (IOException e) {
                         LOGGER.error("Error occured while parsing the request.", e);
-                        if (e.getCause() instanceof NotImplementedException) {
-                            return errorNotImplemented(request);
+                        if (e.getCause() instanceof JmapFieldNotSupportedException) {
+                            return errorNotImplemented((JmapFieldNotSupportedException) e.getCause(), request);
                         }
-                        return error(request, ErrorResponse.builder()
-                                                        .type("invalidArguments")
-                                                        .description(e.getMessage())
-                                                        .build());
-                    } catch (NotImplementedException e) {
-                        return errorNotImplemented(request);
+                        return error(request, generateInvalidArgumentError(e.getMessage()));
+                    } catch (JmapFieldNotSupportedException e) {
+                        return errorNotImplemented(e, request);
                     }
                 };
     }
 
-    private Stream<JmapResponse> errorNotImplemented(AuthenticatedProtocolRequest request) {
+    public ErrorResponse generateInvalidArgumentError(String description) {
+        return ErrorResponse.builder()
+            .type("invalidArguments")
+            .description(description)
+            .build();
+    }
+
+    private Stream<JmapResponse> errorNotImplemented(JmapFieldNotSupportedException error, AuthenticatedProtocolRequest request) {
         return Stream.of(
                 JmapResponse.builder()
                     .clientId(request.getClientId())
-                    .error("Not yet implemented")
+                    .error(generateInvalidArgumentError("The field '" + error.getField() + "' of '" + error.getIssuer() + "' is not supported"))
                     .build());
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/b44df191/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetMailboxesRequest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetMailboxesRequest.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetMailboxesRequest.java
index 6e435f8..f7ece2f 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetMailboxesRequest.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetMailboxesRequest.java
@@ -21,7 +21,7 @@ package org.apache.james.jmap.model;
 import java.util.List;
 import java.util.Optional;
 
-import org.apache.commons.lang.NotImplementedException;
+import org.apache.james.jmap.JmapFieldNotSupportedException;
 import org.apache.james.jmap.methods.JmapRequest;
 import org.apache.james.mailbox.model.MailboxId;
 
@@ -33,6 +33,7 @@ import com.google.common.collect.ImmutableSet;
 
 @JsonDeserialize(builder = GetMailboxesRequest.Builder.class)
 public class GetMailboxesRequest implements JmapRequest {
+    private static final String ISSUER = "GetMailboxesRequest";
 
     public static Builder builder() {
         return new Builder();
@@ -52,7 +53,7 @@ public class GetMailboxesRequest implements JmapRequest {
 
         public Builder accountId(String accountId) {
             if (accountId != null) {
-                throw new NotImplementedException();
+                throw new JmapFieldNotSupportedException(ISSUER, "accountId");
             }
             return this;
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b44df191/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetVacationRequest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetVacationRequest.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetVacationRequest.java
index 9f77319..2f75e05 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetVacationRequest.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetVacationRequest.java
@@ -19,7 +19,7 @@
 
 package org.apache.james.jmap.model;
 
-import org.apache.commons.lang.NotImplementedException;
+import org.apache.james.jmap.JmapFieldNotSupportedException;
 import org.apache.james.jmap.methods.JmapRequest;
 
 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
@@ -27,6 +27,7 @@ import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
 
 @JsonDeserialize(builder = GetVacationRequest.Builder.class)
 public class GetVacationRequest implements JmapRequest {
+    private static final String ISSUER = "GetVacationRequest";
 
     public static Builder builder() {
         return new Builder();
@@ -36,7 +37,7 @@ public class GetVacationRequest implements JmapRequest {
     public static class Builder {
 
         public Builder accountId(String accountId) {
-            throw new NotImplementedException();
+            throw new JmapFieldNotSupportedException(ISSUER, "accountId");
         }
 
         public GetVacationRequest build() {

http://git-wip-us.apache.org/repos/asf/james-project/blob/b44df191/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetMessagesRequest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetMessagesRequest.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetMessagesRequest.java
index ec6b1a8..325191f 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetMessagesRequest.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetMessagesRequest.java
@@ -25,7 +25,7 @@ import java.util.Map;
 import java.util.Optional;
 import java.util.function.Function;
 
-import org.apache.commons.lang.NotImplementedException;
+import org.apache.james.jmap.JmapFieldNotSupportedException;
 import org.apache.james.jmap.methods.JmapRequest;
 import org.apache.james.jmap.methods.UpdateMessagePatchConverter;
 import org.apache.james.jmap.methods.ValueWithId.CreationMessageEntry;
@@ -43,6 +43,7 @@ import com.google.common.collect.Maps;
 
 @JsonDeserialize(builder = SetMessagesRequest.Builder.class)
 public class SetMessagesRequest implements JmapRequest {
+    private static final String ISSUER = "SetMessagesRequest";
 
     public static Builder builder() {
         return new Builder();
@@ -68,14 +69,14 @@ public class SetMessagesRequest implements JmapRequest {
 
         public Builder accountId(String accountId) {
             if (accountId != null) {
-                throw new NotImplementedException();
+                throw new JmapFieldNotSupportedException(ISSUER, "accountId");
             }
             return this;
         }
 
         public Builder ifInState(String ifInState) {
             if (ifInState != null) {
-                throw new NotImplementedException();
+                throw new JmapFieldNotSupportedException(ISSUER, "ifInState");
             }
             return this;
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b44df191/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetVacationRequest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetVacationRequest.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetVacationRequest.java
index 5bf505d..4a1c7d1 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetVacationRequest.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetVacationRequest.java
@@ -21,7 +21,7 @@ package org.apache.james.jmap.model;
 
 import java.util.Map;
 
-import org.apache.commons.lang.NotImplementedException;
+import org.apache.james.jmap.JmapFieldNotSupportedException;
 import org.apache.james.jmap.api.vacation.Vacation;
 import org.apache.james.jmap.methods.JmapRequest;
 
@@ -33,6 +33,7 @@ import com.google.common.collect.Maps;
 
 @JsonDeserialize(builder = SetVacationRequest.Builder.class)
 public class SetVacationRequest implements JmapRequest {
+    private static final String ISSUER = "SetVacationRequest";
 
     public static Builder builder() {
         return new Builder();
@@ -45,7 +46,7 @@ public class SetVacationRequest implements JmapRequest {
 
         public Builder accountId(String accountId) {
             if (accountId != null) {
-                throw new NotImplementedException();
+                throw new JmapFieldNotSupportedException(ISSUER, "accountId");
             }
             return this;
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b44df191/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/MailboxCreateRequest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/MailboxCreateRequest.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/MailboxCreateRequest.java
index e473726..ee3e7ff 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/MailboxCreateRequest.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/MailboxCreateRequest.java
@@ -22,7 +22,7 @@ package org.apache.james.jmap.model.mailbox;
 import java.util.Objects;
 import java.util.Optional;
 
-import org.apache.commons.lang.NotImplementedException;
+import org.apache.james.jmap.JmapFieldNotSupportedException;
 import org.apache.james.jmap.model.MailboxCreationId;
 import org.apache.james.mailbox.Role;
 
@@ -35,6 +35,7 @@ import com.google.common.base.Strings;
 
 @JsonDeserialize(builder = MailboxCreateRequest.Builder.class)
 public class MailboxCreateRequest {
+    private static final String ISSUER = "MailboxCreateRequest";
 
     public static Builder builder() {
         return new Builder();
@@ -76,12 +77,12 @@ public class MailboxCreateRequest {
 
         public Builder role(Role role) {
             Preconditions.checkNotNull(role);
-            throw new NotImplementedException();
+            throw new JmapFieldNotSupportedException(ISSUER, "role");
         }
 
         public Builder sortOrder(SortOrder sortOrder) {
             Preconditions.checkNotNull(sortOrder);
-            throw new NotImplementedException();
+            throw new JmapFieldNotSupportedException(ISSUER, "sortOrder");
         }
 
 


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


[12/13] james-project git commit: JAMES-2394 Clarify that protocols don't need to share TLS keys.

Posted by bt...@apache.org.
JAMES-2394 Clarify that protocols don't need to share TLS keys.


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

Branch: refs/heads/master
Commit: 26df561f3f41d0d977f8c2a423dd3765f30e32c7
Parents: 4c27a8a
Author: benwa <bt...@linagora.com>
Authored: Wed Jul 4 13:55:57 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Thu Jul 5 08:59:57 2018 +0700

----------------------------------------------------------------------
 src/site/xdoc/server/config-imap4.xml      | 4 +++-
 src/site/xdoc/server/config-pop3.xml       | 4 +++-
 src/site/xdoc/server/config-smtp-lmtp.xml  | 4 +++-
 src/site/xdoc/server/feature-protocols.xml | 2 ++
 4 files changed, 11 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/26df561f/src/site/xdoc/server/config-imap4.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/server/config-imap4.xml b/src/site/xdoc/server/config-imap4.xml
index 0348a7d..1dab962 100644
--- a/src/site/xdoc/server/config-imap4.xml
+++ b/src/site/xdoc/server/config-imap4.xml
@@ -58,7 +58,9 @@
         <dt><strong>tls</strong></dt>
         <dd>Set to true to support STARTTLS or SSL for the Socket.
          To use this you need to copy sunjce_provider.jar to /path/james/lib directory. To create a new keystore execute:
-             keytool -genkey -alias james -keyalg RSA -keystore /path/to/james/conf/keystore</dd>
+             keytool -genkey -alias james -keyalg RSA -keystore /path/to/james/conf/keystore<br/>
+        Please note that each IMAP server exposed on different port can specify its own keystore, independently from any other
+        TLS based protocols.</dd>
         <dt><strong>handler.helloName</strong></dt>
         <dd>This is the name used by the server to identify itself in the IMAP4 
         protocol.  If autodetect is TRUE, the server will discover its 

http://git-wip-us.apache.org/repos/asf/james-project/blob/26df561f/src/site/xdoc/server/config-pop3.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/server/config-pop3.xml b/src/site/xdoc/server/config-pop3.xml
index 7acc82e..137aff6 100644
--- a/src/site/xdoc/server/config-pop3.xml
+++ b/src/site/xdoc/server/config-pop3.xml
@@ -51,7 +51,9 @@
         <dt><strong>tls</strong></dt>
         <dd>Set to true to support STARTTLS or SSL for the Socket.
          To use this you need to copy sunjce_provider.jar to /path/james/lib directory. To create a new keystore execute:
-             keytool -genkey -alias james -keyalg RSA -keystore /path/to/james/conf/keystore</dd>
+             keytool -genkey -alias james -keyalg RSA -keystore /path/to/james/conf/keystore<br/>
+            Please note that each POP3 server exposed on different port can specify its own keystore, independently from any other
+            TLS based protocols.</dd>
         <dt><strong>handler.helloName</strong></dt>
         <dd>This is the name used by the server to identify itself in the POP3 
         protocol.  If autodetect is TRUE, the server will discover its 

http://git-wip-us.apache.org/repos/asf/james-project/blob/26df561f/src/site/xdoc/server/config-smtp-lmtp.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/server/config-smtp-lmtp.xml b/src/site/xdoc/server/config-smtp-lmtp.xml
index 3cf36cc..62037f5 100644
--- a/src/site/xdoc/server/config-smtp-lmtp.xml
+++ b/src/site/xdoc/server/config-smtp-lmtp.xml
@@ -61,7 +61,9 @@
       <dd>Set to true to support STARTTLS or SSL for the Socket.
          To use this you need to copy sunjce_provider.jar to /path/james/lib directory. To create a new keystore execute:
         keytool -genkey -alias james -keyalg RSA -keystore /path/to/james/conf/keystore. The algorithm is optional and only needs to be specified when using something other
-        than the Sun JCE provider - You could use IbmX509 with IBM Java runtime.</dd>
+        than the Sun JCE provider - You could use IbmX509 with IBM Java runtime.<br/>
+          Please note that each SMTP/LMTP server exposed on different port can specify its own keystore, independently from any other
+          TLS based protocols.</dd>
       <dt><strong>handler.helloName</strong></dt>
       <dd>This is a required tag with an optional body that defines the server name 
       used in the initial service greeting.  The tag may have an optional attribute - <strong>autodetect</strong>.  If 

http://git-wip-us.apache.org/repos/asf/james-project/blob/26df561f/src/site/xdoc/server/feature-protocols.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/server/feature-protocols.xml b/src/site/xdoc/server/feature-protocols.xml
index db708d9..5ceb05a 100644
--- a/src/site/xdoc/server/feature-protocols.xml
+++ b/src/site/xdoc/server/feature-protocols.xml
@@ -41,6 +41,8 @@
       
       <p>The Apache James Server is implemented as a complete collection of servers and related components that, taken together,
       provide an email solution.  These components are described below.</p>
+
+      <p>Note that each protocol can specify its TLS settings and keys in an independent way.</p>
   
     </subsection>
     


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


[04/13] james-project git commit: JAMES-2448 Don't use Camel exchanges properties

Posted by bt...@apache.org.
JAMES-2448 Don't use Camel exchanges properties

It comes with a performance penalty and actually makes code reading harder


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

Branch: refs/heads/master
Commit: 32d59cc34afb7408d3f131d532193be571d293e4
Parents: d261aef
Author: benwa <bt...@linagora.com>
Authored: Sun Jul 1 23:47:06 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Thu Jul 5 08:56:22 2018 +0700

----------------------------------------------------------------------
 .../impl/camel/CamelMailetProcessor.java        | 29 ++++---------
 .../impl/camel/MatcherSplitter.java             | 43 ++++++++------------
 2 files changed, 26 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/32d59cc3/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessor.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessor.java b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessor.java
index b4808c8..2410374 100644
--- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessor.java
+++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessor.java
@@ -133,18 +133,16 @@ public class CamelMailetProcessor extends AbstractStateMailetProcessor implement
         }
 
         @Override
-        public void configure() throws Exception {
+        public void configure() {
             Processor disposeProcessor = new DisposeProcessor();
-            Processor removePropsProcessor = new RemovePropertiesProcessor();
             Processor completeProcessor = new CompleteProcessor();
             Processor stateChangedProcessor = new StateChangedProcessor();
 
             String state = getState();
 
-            RouteDefinition processorDef = from(getEndpoint()).routeId(state).setExchangePattern(ExchangePattern.InOnly)
-                    // store the logger in properties
-                    .setProperty(MatcherSplitter.LOGGER_PROPERTY, constant(LOGGER))
-                    .setProperty(MatcherSplitter.METRIC_FACTORY, constant(metricFactory));
+            RouteDefinition processorDef = from(getEndpoint())
+                .routeId(state)
+                .setExchangePattern(ExchangePattern.InOnly);
 
             for (MatcherMailetPair pair : pairs) {
                 Matcher matcher = pair.getMatcher();
@@ -155,14 +153,15 @@ public class CamelMailetProcessor extends AbstractStateMailetProcessor implement
 
                 CamelProcessor mailetProccessor = new CamelProcessor(metricFactory, mailet, CamelMailetProcessor.this);
                 // Store the matcher to use for splitter in properties
-                processorDef.setProperty(MatcherSplitter.MATCHER_PROPERTY, constant(matcher)).setProperty(MatcherSplitter.ON_MATCH_EXCEPTION_PROPERTY, constant(onMatchException)).setProperty(MatcherSplitter.MAILETCONTAINER_PROPERTY, constant(CamelMailetProcessor.this))
+                MatcherSplitter matcherSplitter = new MatcherSplitter(metricFactory, CamelMailetProcessor.this, matcher, onMatchException);
 
+                processorDef
                         // do splitting of the mail based on the stored matcher
-                        .split().method(MatcherSplitter.class).aggregationStrategy(aggr)
+                        .split().method(matcherSplitter).aggregationStrategy(aggr)
 
                         .choice().when(new MatcherMatch()).process(mailetProccessor).end()
 
-                        .choice().when(new MailStateEquals(Mail.GHOST)).process(disposeProcessor).stop().otherwise().process(removePropsProcessor).end()
+                        .choice().when(new MailStateEquals(Mail.GHOST)).process(disposeProcessor).stop().end()
 
                         .choice().when(new MailStateNotEquals(state)).process(stateChangedProcessor).process(completeProcessor).stop().end();
             }
@@ -186,19 +185,10 @@ public class CamelMailetProcessor extends AbstractStateMailetProcessor implement
 
         }
 
-        private final class RemovePropertiesProcessor implements Processor {
-
-            @Override
-            public void process(Exchange exchange) throws Exception {
-                exchange.removeProperty(MatcherSplitter.ON_MATCH_EXCEPTION_PROPERTY);
-                exchange.removeProperty(MatcherSplitter.MATCHER_PROPERTY);
-            }
-        }
-
         private final class CompleteProcessor implements Processor {
 
             @Override
-            public void process(Exchange ex) throws Exception {
+            public void process(Exchange ex) {
                 LOGGER.debug("End of mailetprocessor for state {} reached", getState());
                 ex.setProperty(Exchange.ROUTE_STOP, true);
             }
@@ -210,7 +200,6 @@ public class CamelMailetProcessor extends AbstractStateMailetProcessor implement
             public void process(Exchange arg0) throws Exception {
                 Mail mail = arg0.getIn().getBody(Mail.class);
                 toProcessor(mail);
-
             }
 
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/32d59cc3/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/MatcherSplitter.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/MatcherSplitter.java b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/MatcherSplitter.java
index 876ce6a..016a0c9 100644
--- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/MatcherSplitter.java
+++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/MatcherSplitter.java
@@ -24,11 +24,11 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import java.util.Locale;
+import java.util.Optional;
 
 import javax.mail.MessagingException;
 
 import org.apache.camel.Body;
-import org.apache.camel.ExchangeProperty;
 import org.apache.camel.Handler;
 import org.apache.camel.InOnly;
 import org.apache.james.core.MailAddress;
@@ -56,36 +56,32 @@ public class MatcherSplitter {
     /** Headername which is used to indicate that the matcher matched */
     public static final String MATCHER_MATCHED_ATTRIBUTE = "matched";
 
-    /** Headername under which the matcher is stored */
-    public static final String MATCHER_PROPERTY = "matcher";
-
-    public static final String ON_MATCH_EXCEPTION_PROPERTY = "onMatchException";
-
-    public static final String LOGGER_PROPERTY = "logger";
-
-    public static final String MAILETCONTAINER_PROPERTY = "container";
-
-    public static final String METRIC_FACTORY = "metricFactory";
+    private final MetricFactory metricFactory;
+    private final CamelMailetProcessor container;
+    private final Matcher matcher;
+    private final String onMatchException;
+
+    public MatcherSplitter(MetricFactory metricFactory, CamelMailetProcessor container, Matcher matcher, String onMatchException) {
+        this.metricFactory = metricFactory;
+        this.container = container;
+        this.matcher = matcher;
+        this.onMatchException = Optional.ofNullable(onMatchException)
+            .map(s -> s.trim().toLowerCase(Locale.US))
+            .orElse(Mail.ERROR);
+    }
 
     /**
      * Generate a List of MailMessage instances for the give @Body. This is done
      * by using the given Matcher to see if we need more then one instance of
      * the MailMessage
-     * 
-     * @param matcher
-     *            Matcher to use for splitting
+     *
      * @param mail
      *            Mail which is stored in the @Body of the MailMessage
      * @return mailMessageList
      * @throws MessagingException
      */
     @Handler
-    public List<Mail> split(@ExchangeProperty(MATCHER_PROPERTY) Matcher matcher,
-                            @ExchangeProperty(ON_MATCH_EXCEPTION_PROPERTY) String onMatchException,
-                            @ExchangeProperty(LOGGER_PROPERTY) Logger logger,
-                            @ExchangeProperty(MAILETCONTAINER_PROPERTY) CamelMailetProcessor container,
-                            @ExchangeProperty(METRIC_FACTORY) MetricFactory metricFactory,
-                            @Body Mail mail) throws MessagingException {
+    public List<Mail> split(@Body Mail mail) throws MessagingException {
         Collection<MailAddress> matchedRcpts = null;
         Collection<MailAddress> origRcpts = new ArrayList<>(mail.getRecipients());
         long start = System.currentTimeMillis();
@@ -122,11 +118,6 @@ public class MatcherSplitter {
 
             } catch (Exception me) {
                 ex = me;
-                if (onMatchException == null) {
-                    onMatchException = Mail.ERROR;
-                } else {
-                    onMatchException = onMatchException.trim().toLowerCase(Locale.US);
-                }
                 if (onMatchException.equalsIgnoreCase("nomatch")) {
                     // In case the matcher returned null, create an empty
                     // Collection
@@ -137,7 +128,7 @@ public class MatcherSplitter {
                     matchedRcpts = mail.getRecipients();
                     // no need to verify addresses
                 } else {
-                    ProcessorUtil.handleException(me, mail, matcher.getMatcherConfig().getMatcherName(), onMatchException, logger);
+                    ProcessorUtil.handleException(me, mail, matcher.getMatcherConfig().getMatcherName(), onMatchException, LOGGER);
                 }
             }
 


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


[07/13] james-project git commit: JAMES-2447 Reduce calmly await poll delay

Posted by bt...@apache.org.
JAMES-2447 Reduce calmly await poll delay

The poll delay is the time to wait before first trial...

The problem is that many things get retried but could have worked directly (eg JMAP authentication)
thus minimizing delay highly speed things up.


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

Branch: refs/heads/master
Commit: 8baa7526d3fb82c7ad17bd3b7db1a9eabe294b88
Parents: b374cf9
Author: benwa <bt...@linagora.com>
Authored: Mon Jul 2 01:06:47 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Thu Jul 5 08:58:13 2018 +0700

----------------------------------------------------------------------
 .../james/CassandraMailRepositoryIntegrationTest.java |  6 +++++-
 ...DirectResolutionRemoteDeliveryIntegrationTest.java |  9 +++++++--
 .../mailets/GatewayRemoteDeliveryIntegrationTest.java | 14 +++++++++++---
 .../apache/james/mailets/configuration/Constants.java | 10 +++++++---
 .../james/smtp/SmtpAuthorizedAddressesTest.java       | 12 ++++++++----
 .../java/org/apache/james/jmap/TestingConstants.java  |  6 ++++--
 6 files changed, 42 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/8baa7526/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraMailRepositoryIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraMailRepositoryIntegrationTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraMailRepositoryIntegrationTest.java
index cf2cbdb..f935d38 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraMailRepositoryIntegrationTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraMailRepositoryIntegrationTest.java
@@ -21,6 +21,8 @@ package org.apache.james;
 
 import static com.jayway.awaitility.Duration.FIVE_HUNDRED_MILLISECONDS;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.james.mailrepository.api.MailRepositoryUrl;
 import org.apache.james.utils.DataProbeImpl;
 import org.apache.james.utils.MailRepositoryProbeImpl;
@@ -32,11 +34,13 @@ import org.junit.Rule;
 import org.junit.Test;
 
 import com.jayway.awaitility.Awaitility;
+import com.jayway.awaitility.Duration;
 import com.jayway.awaitility.core.ConditionFactory;
 
 public class CassandraMailRepositoryIntegrationTest {
 
     private static final MailRepositoryUrl SENDER_DENIED_URL = MailRepositoryUrl.from("cassandra://var/mail/sender-denied/");
+    private static final Duration ONE_MILLISECOND = new Duration(1, TimeUnit.MILLISECONDS);
 
     @ClassRule
     public static DockerCassandraRule cassandra = new DockerCassandraRule();
@@ -57,7 +61,7 @@ public class CassandraMailRepositoryIntegrationTest {
             .pollInterval(FIVE_HUNDRED_MILLISECONDS)
             .and()
             .with()
-            .pollDelay(FIVE_HUNDRED_MILLISECONDS)
+            .pollDelay(ONE_MILLISECOND)
             .await();
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/8baa7526/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/DirectResolutionRemoteDeliveryIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/DirectResolutionRemoteDeliveryIntegrationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/DirectResolutionRemoteDeliveryIntegrationTest.java
index fc8c7c4..984e3b8 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/DirectResolutionRemoteDeliveryIntegrationTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/DirectResolutionRemoteDeliveryIntegrationTest.java
@@ -48,6 +48,7 @@ import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 
 import com.google.common.collect.ImmutableList;
+import com.jayway.awaitility.Duration;
 
 public class DirectResolutionRemoteDeliveryIntegrationTest {
     private static final String JAMES_ANOTHER_DOMAIN = "james.com";
@@ -110,7 +111,9 @@ public class DirectResolutionRemoteDeliveryIntegrationTest {
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
             .sendMessage(FROM, RECIPIENT);
 
-        awaitAtMostOneMinute.until(this::messageIsReceivedByTheSmtpServer);
+        awaitAtMostOneMinute
+            .pollDelay(Duration.FIVE_HUNDRED_MILLISECONDS)
+            .until(this::messageIsReceivedByTheSmtpServer);
     }
 
     @Test
@@ -137,7 +140,9 @@ public class DirectResolutionRemoteDeliveryIntegrationTest {
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
             .sendMessage(FROM, RECIPIENT);
 
-        awaitAtMostOneMinute.until(this::messageIsReceivedByTheSmtpServer);
+        awaitAtMostOneMinute
+            .pollDelay(Duration.FIVE_HUNDRED_MILLISECONDS)
+            .until(this::messageIsReceivedByTheSmtpServer);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/8baa7526/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/GatewayRemoteDeliveryIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/GatewayRemoteDeliveryIntegrationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/GatewayRemoteDeliveryIntegrationTest.java
index 0158104..d9e6bab 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/GatewayRemoteDeliveryIntegrationTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/GatewayRemoteDeliveryIntegrationTest.java
@@ -49,6 +49,8 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 
+import com.jayway.awaitility.Duration;
+
 public class GatewayRemoteDeliveryIntegrationTest {
     private static final String JAMES_ANOTHER_DOMAIN = "james.com";
 
@@ -99,7 +101,9 @@ public class GatewayRemoteDeliveryIntegrationTest {
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
             .sendMessage(FROM, RECIPIENT);
 
-        awaitAtMostOneMinute.until(this::messageIsReceivedByTheSmtpServer);
+        awaitAtMostOneMinute
+            .pollDelay(Duration.FIVE_HUNDRED_MILLISECONDS)
+            .until(this::messageIsReceivedByTheSmtpServer);
     }
 
     @Test
@@ -137,7 +141,9 @@ public class GatewayRemoteDeliveryIntegrationTest {
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
             .sendMessage(FROM, RECIPIENT);
 
-        awaitAtMostOneMinute.until(this::messageIsReceivedByTheSmtpServer);
+        awaitAtMostOneMinute
+            .pollDelay(Duration.FIVE_HUNDRED_MILLISECONDS)
+            .until(this::messageIsReceivedByTheSmtpServer);
     }
 
     @Test
@@ -156,7 +162,9 @@ public class GatewayRemoteDeliveryIntegrationTest {
         messageSender.connect(LOCALHOST_IP, SMTP_PORT)
             .sendMessage(FROM, RECIPIENT);
 
-        awaitAtMostOneMinute.until(this::messageIsReceivedByTheSmtpServer);
+        awaitAtMostOneMinute
+            .pollDelay(Duration.FIVE_HUNDRED_MILLISECONDS)
+            .until(this::messageIsReceivedByTheSmtpServer);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/8baa7526/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/Constants.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/Constants.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/Constants.java
index 5eae0e7..813b3ca 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/Constants.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/configuration/Constants.java
@@ -19,20 +19,24 @@
 
 package org.apache.james.mailets.configuration;
 
-import static com.jayway.awaitility.Duration.FIVE_HUNDRED_MILLISECONDS;
+import static com.jayway.awaitility.Duration.ONE_HUNDRED_MILLISECONDS;
 import static com.jayway.awaitility.Duration.ONE_MINUTE;
 
+import java.util.concurrent.TimeUnit;
+
 import com.jayway.awaitility.Awaitility;
 import com.jayway.awaitility.Duration;
 import com.jayway.awaitility.core.ConditionFactory;
 
 public class Constants {
-    public static Duration slowPacedPollInterval = FIVE_HUNDRED_MILLISECONDS;
+    public static Duration slowPacedPollInterval = ONE_HUNDRED_MILLISECONDS;
+    public static Duration ONE_MILLISECOND = new Duration(1, TimeUnit.MILLISECONDS);
+
     public static ConditionFactory calmlyAwait = Awaitility.with()
         .pollInterval(slowPacedPollInterval)
         .and()
         .with()
-        .pollDelay(slowPacedPollInterval)
+        .pollDelay(ONE_MILLISECOND)
         .await();
     public static ConditionFactory awaitAtMostOneMinute = calmlyAwait.atMost(ONE_MINUTE);
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/8baa7526/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpAuthorizedAddressesTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpAuthorizedAddressesTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpAuthorizedAddressesTest.java
index 859325d..8d7d661 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpAuthorizedAddressesTest.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpAuthorizedAddressesTest.java
@@ -50,6 +50,8 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 
+import com.jayway.awaitility.Duration;
+
 public class SmtpAuthorizedAddressesTest {
     private static final String FROM = "fromuser@" + DEFAULT_DOMAIN;
     private static final String TO = "to@any.com";
@@ -134,10 +136,12 @@ public class SmtpAuthorizedAddressesTest {
             .authenticate(FROM, PASSWORD)
             .sendMessage(FROM, TO);
 
-        awaitAtMostOneMinute.until(() -> fakeSmtp.isReceived(response -> response
-            .body("", hasSize(1))
-            .body("[0].from", equalTo(FROM))
-            .body("[0].subject", equalTo("test"))));
+        awaitAtMostOneMinute
+            .pollDelay(Duration.FIVE_HUNDRED_MILLISECONDS)
+            .until(() -> fakeSmtp.isReceived(response -> response
+                .body("", hasSize(1))
+                .body("[0].from", equalTo(FROM))
+                .body("[0].subject", equalTo("test"))));
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/8baa7526/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/TestingConstants.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/TestingConstants.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/TestingConstants.java
index 7dba329..9949c61 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/TestingConstants.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/TestingConstants.java
@@ -23,6 +23,7 @@ import static com.jayway.restassured.config.EncoderConfig.encoderConfig;
 import static com.jayway.restassured.config.RestAssuredConfig.newConfig;
 
 import java.nio.charset.StandardCharsets;
+import java.util.concurrent.TimeUnit;
 
 import com.jayway.awaitility.Awaitility;
 import com.jayway.awaitility.Duration;
@@ -31,12 +32,13 @@ import com.jayway.restassured.builder.RequestSpecBuilder;
 import com.jayway.restassured.http.ContentType;
 
 public interface TestingConstants {
-    Duration slowPacedPollInterval = Duration.FIVE_HUNDRED_MILLISECONDS;
+    Duration slowPacedPollInterval = Duration.ONE_HUNDRED_MILLISECONDS;
+    Duration ONE_MILLISECOND = new Duration(1, TimeUnit.MILLISECONDS);
 
     ConditionFactory calmlyAwait = Awaitility.with()
         .pollInterval(slowPacedPollInterval)
         .and().with()
-        .pollDelay(slowPacedPollInterval)
+        .pollDelay(ONE_MILLISECOND)
         .await();
 
     RequestSpecBuilder jmapRequestSpecBuilder = new RequestSpecBuilder()


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