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:25 UTC
[03/13] james-project git commit: JAMES-2435 Skeleton of "how-to"
proposition & custom mailet example.
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><dependency>
+ <groupId>org.apache.james</groupId>
+ <artifactId>apache-mailet-base</artifactId>
+</dependency></code></pre>
+
+ <p>The main method of a matcher is the <b>match</b> method:</p>
+
+ <pre><code>Collection<MailAddress> 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<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();
+ }</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<MailAddress> 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>
+<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>
+ <!-- Rest of the configuration -->
+ </processor>
+
+ <!-- Other processors -->
+ </processors>
+</mailetcontainer></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