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 2016/08/18 10:19:24 UTC

[01/10] james-project git commit: JAMES-1773 HasHeader should not parse conditions on each received e-mail

Repository: james-project
Updated Branches:
  refs/heads/master b738594d1 -> 4ac57ec9e


JAMES-1773 HasHeader should not parse conditions on each received e-mail

I did not use Guava for refactoring as it is not present in this project.

The idea is to introduce specific objects for conditions, that will be parsed once and for all.


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

Branch: refs/heads/master
Commit: 4ac57ec9e13b11901dc94b0f190e438953447cbc
Parents: 80a2ca8
Author: Benoit Tellier <bt...@linagora.com>
Authored: Tue Aug 9 14:42:31 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Aug 18 17:18:15 2016 +0700

----------------------------------------------------------------------
 .../james/transport/matchers/HasHeader.java     | 117 ++++++++++---------
 1 file changed, 63 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/4ac57ec9/mailet/standard/src/main/java/org/apache/james/transport/matchers/HasHeader.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/main/java/org/apache/james/transport/matchers/HasHeader.java b/mailet/standard/src/main/java/org/apache/james/transport/matchers/HasHeader.java
index 00b336d..c8484d9 100644
--- a/mailet/standard/src/main/java/org/apache/james/transport/matchers/HasHeader.java
+++ b/mailet/standard/src/main/java/org/apache/james/transport/matchers/HasHeader.java
@@ -26,8 +26,10 @@ import org.apache.mailet.base.GenericMatcher;
 
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeMessage;
+
+import java.util.ArrayList;
 import java.util.Collection;
-import java.util.LinkedList;
+import java.util.List;
 import java.util.StringTokenizer;
 
 /**
@@ -38,73 +40,80 @@ import java.util.StringTokenizer;
  */
 public class HasHeader extends GenericMatcher {
 
-    private LinkedList<String> conditionline_ = new LinkedList<String>();
+    private static final String CONDITION_SEPARATOR = "+";
+    private static final String HEADER_VALUE_SEPARATOR = "=";
 
-    // set headernames and values
-    public void init() throws MessagingException {
-        StringTokenizer st = new StringTokenizer(getCondition(), "+");
-        conditionline_ = new LinkedList<String>();
+    private interface HeaderCondition {
+        boolean isMatching(MimeMessage mimeMessage) throws MessagingException;
+    }
+
+    private static class HeaderNameCondition implements HeaderCondition {
+        private final String headerName;
+
+        public HeaderNameCondition(String headerName) {
+            this.headerName = headerName;
+        }
 
-        // separates the headernames from the matchline
-        while (st.hasMoreTokens()) {
-            String condition = st.nextToken().trim();
-            conditionline_.add(condition);
+        @Override
+        public boolean isMatching(MimeMessage mimeMessage) throws MessagingException {
+            String[] headerArray = mimeMessage.getHeader(headerName);
+            return headerArray != null && headerArray.length > 0;
         }
     }
 
-    public Collection<MailAddress> match(Mail mail) throws javax.mail.MessagingException {
-        boolean match = false;
-        MimeMessage message = mail.getMessage();
-
-        for (String element : conditionline_) {
-            StringTokenizer st = new StringTokenizer(element, "=", false);
-            String header;
-
-            // read the headername
-            if (st.hasMoreTokens()) {
-                header = st.nextToken().trim();
-            } else {
-                throw new MessagingException("Missing headerName");
-            }
+    private static class HeaderValueCondition implements HeaderCondition {
+        private final String headerName;
+        private final String headerValue;
 
-            // try to read headervalue
-            String headerValue;
-            if (st.hasMoreTokens()) {
-                headerValue = st.nextToken().trim();
-            } else {
-                headerValue = null;
-            }
+        public HeaderValueCondition(String headerName, String headerValue) {
+            this.headerName = headerName;
+            this.headerValue = headerValue;
+        }
 
-            // find headername in Mailheaders
-            String[] headerArray = message.getHeader(header);
+        @Override
+        public boolean isMatching(MimeMessage mimeMessage) throws MessagingException {
+            String[] headerArray = mimeMessage.getHeader(headerName);
             if (headerArray != null && headerArray.length > 0) {
-                // if there is the headername specified without the headervalue
-                // only the existence of the headername ist performed
-                if (headerValue != null) {
-                    //
-                    if (headerArray[0].trim().equalsIgnoreCase(headerValue)) {
-                        // headername and value found and match to the condition
-                        match = true;
-                    } else {
-                        // headername and value found but the value does not match the condition
-                        match = false;
-                        // if one condition fails the matcher returns false
-                        break;
+                for (String value : headerArray) {
+                    if (headerValue.equals(value)) {
+                        return true;
                     }
-                } else {
-                    // just the headername is specified
-                    match = true;
                 }
-            } else {
-                // no headername is found
-                match = false;
-                // if one condition fails the matcher returns false
-                break;
             }
+            return false;
+        }
+    }
+
+    private List<HeaderCondition> headerConditions;
+
+    public void init() throws MessagingException {
+        headerConditions = new ArrayList<HeaderCondition>();
+        StringTokenizer conditionTokenizer = new StringTokenizer(getCondition(), CONDITION_SEPARATOR);
+        while (conditionTokenizer.hasMoreTokens()) {
+            headerConditions.add(parseHeaderCondition(conditionTokenizer.nextToken().trim()));
         }
+    }
 
-        return (match) ? mail.getRecipients() : null;
+    private HeaderCondition parseHeaderCondition(String element) throws MessagingException {
+        StringTokenizer valueSeparatorTokenizer = new StringTokenizer(element, HEADER_VALUE_SEPARATOR, false);
+        if (!valueSeparatorTokenizer.hasMoreElements()) {
+            throw new MessagingException("Missing headerName");
+        }
+        String headerName = valueSeparatorTokenizer.nextToken().trim();
+        if (valueSeparatorTokenizer.hasMoreTokens()) {
+           return new HeaderValueCondition(headerName, valueSeparatorTokenizer.nextToken().trim());
+        } else {
+            return new HeaderNameCondition(headerName);
+        }
+    }
 
+    public Collection<MailAddress> match(Mail mail) throws javax.mail.MessagingException {
+        for (HeaderCondition headerCondition : headerConditions) {
+            if (!headerCondition.isMatching(mail.getMessage())) {
+                return null;
+            }
+        }
+        return mail.getRecipients();
     }
 } 
 


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


[09/10] james-project git commit: JAMES-1773 Document possibility to match header value

Posted by bt...@apache.org.
JAMES-1773 Document possibility to match header value


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

Branch: refs/heads/master
Commit: 80a2ca89d7c453ed7810d44f3eff96dade5c2b8b
Parents: 1b9a107
Author: Benoit Tellier <bt...@linagora.com>
Authored: Tue Aug 9 11:52:37 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Aug 18 17:18:15 2016 +0700

----------------------------------------------------------------------
 server/src/site/xdoc/dev-provided-matchers.xml | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/80a2ca89/server/src/site/xdoc/dev-provided-matchers.xml
----------------------------------------------------------------------
diff --git a/server/src/site/xdoc/dev-provided-matchers.xml b/server/src/site/xdoc/dev-provided-matchers.xml
index 0752002..cd18a91 100644
--- a/server/src/site/xdoc/dev-provided-matchers.xml
+++ b/server/src/site/xdoc/dev-provided-matchers.xml
@@ -119,7 +119,22 @@
                         &lt;mailet match="HasHeader=headerName" class=&quot;&lt;any-class&gt;&quot;&gt;
                     </code></pre>
                 </p>
-
+                <p>
+                    One can additionally specify a header value associated with the header name. You can do something like :
+                    <pre><code>
+                        &lt;mailet match="HasHeader=headerName=headerValue" class=&quot;&lt;any-class&gt;&quot;&gt;
+                    </code></pre>
+                </p>
+                <p>
+                    You can verify several headers at once. They should all be matching. To do so, separate your conditions using "+" :
+                    <pre><code>
+                        &lt;mailet match="HasHeader=headerName1+headerName2=value" class=&quot;&lt;any-class&gt;&quot;&gt;
+                    </code></pre>
+                </p>
+                <p>
+                    Note: If the header you are matching against is present several time in the received mail, then it is
+                    considered as matching if the specified value is present on one line.
+                </p>
             </subsection>
 
             <subsection name="HasMailAttribute">


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


[07/10] james-project git commit: JAMES-1773 Re-indent matcher documentation

Posted by bt...@apache.org.
JAMES-1773 Re-indent matcher documentation


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

Branch: refs/heads/master
Commit: d0114b57dc05a365f16f8dcf57213024e6117401
Parents: be1be8b
Author: Benoit Tellier <bt...@linagora.com>
Authored: Tue Aug 9 11:51:42 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Aug 18 17:18:15 2016 +0700

----------------------------------------------------------------------
 server/src/site/xdoc/dev-provided-matchers.xml | 714 ++++++++++----------
 1 file changed, 358 insertions(+), 356 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/d0114b57/server/src/site/xdoc/dev-provided-matchers.xml
----------------------------------------------------------------------
diff --git a/server/src/site/xdoc/dev-provided-matchers.xml b/server/src/site/xdoc/dev-provided-matchers.xml
index 9095abf..7b0d749 100644
--- a/server/src/site/xdoc/dev-provided-matchers.xml
+++ b/server/src/site/xdoc/dev-provided-matchers.xml
@@ -19,360 +19,362 @@
 -->
 <document>
 
- <properties>
-  <title>Apache James Server 3 - Provided Matchers</title>
- </properties>
-
-<body>
-
-<section name="Matchers">
-
-<p>James provides a number of implemented Matchers for use by James administrators in their 
-configurations.  These are primarily matchers that members of the James developer or user 
-communities have found useful in their own configurations.  A description of how to configure 
-Matchers and use them in the James SpoolManager can be found <a href="config-mailetcontainer.html">here</a>.</p>
-
-<subsection name="All">
-<p>Description: This matcher is the trivial one - it matches all mails being processed. All recipients are returned.</p>
-<p>Configuration string: None.</p>
-</subsection>
-
-<subsection name="AttachmentFileNameIs">
-<p>Description: It can be used to refuse emails with SCR, PIF, EXE etc. attachments.
-It matches mails that has a file attachment with a file name meeting one of the supplied filters.
-All recipients are returned.</p>
-<p>Configuration string: A comma or space delimited list of file names. 
-File names may start with a wildcard '*'. Example: *.scr,*.bat,*.pif,*.pi,*.com,*.exe
-<pre><code>
-&lt;mailet match="AttachmentFileNameIs=value, value, .." class=&quot;&lt;any-class&gt;&quot;&gt;
-</code></pre>
-</p>
-</subsection>
-
-<subsection name="CommandForListserv">
-<p>Description: The CommandForListserv matcher is used as a simple filter to recognize emails that are list server 
-commands.  It will match any email addressed to the list server host, as well as any email that is addressed
-to a user named &lt;prefix&gt;-on or &lt;prefix&gt;-off on any host.  Only those matching recipients will be returned.</p>
-<p>Configuration string: An email address of the form &lt;prefix&gt;@&lt;host&gt;, where host is the hostname used for the listserver and prefix is the command prefix.
-<pre><code>
-&lt;mailet match="CommandForListserv=james-on@list.working-dogs.com" class=&quot;&lt;any-class&gt;&quot;&gt;
-</code></pre>
-</p>
-</subsection>
-
-<subsection name="CommandForListservManager">
-<p>Description: CommandListservMatcher is the matcher that pairs with the CommandListservManager mailet. It checks to see if the request is 
-intended for the ListservManager, but doesn't guarantee that it is a valid command.  Only those matching recipients will be returned.</p>
-<p>Configuration string: An email address.
-<pre><code>
-&lt;mailet match="CommandForListservManager=announce@localhost" class=&quot;&lt;any-class&gt;&quot;&gt;
-</code></pre>
-</p>
-</subsection>
-
-<subsection name="CompareNumericHeaderValue">
-<p>Description: Matches mails containing a header with a numeric value whose comparison with the specified value is true.
-If the header is missing in the message, there will be <i>no match</i>. All recipients are returned.</p>
-<p>Configuration string: The headerName, a comparison operator and the numeric headerValue
-to compare with, <i>space or tab delimited</i>.
-<pre><code>
-&lt;mailet match="CompareNumericHeaderValue= X-MessageIsSpamProbability &gt; 0.9" class=&quot;&lt;any-class&gt;&quot;&gt;
-</code></pre>
-</p>
-</subsection>
-
-<subsection name="FetchedFrom">
-<p>Description: A matcher intended for use with the FetchMail server.  It matches a custom header (X-fetched-from) that is 
-set by the FetchMail server.  FetchMail sets this header to the name of the FetchPOP task which originally fetched
-the message.  All recipients are returned.</p>
-<p>Configuration string: The name of the FetchMail task which originally fetched the message.
-<pre><code>
-&lt;mailet match="FetchedFrom=value" class=&quot;&lt;any-class&gt;&quot;&gt;
-</code></pre>
-</p>
-</subsection>
-
-<subsection name="FileRegexMatcher">
-<p>Description: A matcher which can be used to match on a attachment when the given regex match. All recipients are returned.</p>
-<p>Configuration string: A regex for match attachmentname.
-<pre><code>
-&lt;mailet match="FileRegexMatcher=value" class=&quot;&lt;any-class&gt;&quot;&gt;
-</code></pre>
-</p>
-</subsection>
-
-<subsection name="HasAttachment">
-<p>Description: Matches those messages with a MIME type of "multipart/mixed".  All recipients are returned.</p>
-<p>Configuration string: None.</p>
-</subsection>
-
-<subsection name="HasHabeasWarrantMark">
-<p>Description: Matches mails that have the Habeas Warrant (see http://www.habeas.com for details).  All recipients are returned.</p>
-<p>Configuration string: None.</p>
-</subsection>
-
-<subsection name="HasHeader">
-<p>Description: Matches mails that have the specified header.  All recipients are returned.</p>
-<p>Configuration string: The name of the header whose presence determines the match.
-<pre><code>
-&lt;mailet match="HasHeader=value" class=&quot;&lt;any-class&gt;&quot;&gt;
-</code></pre>
-</p>
-</subsection>
-
-<subsection name="HasMailAttribute">
-<p>Description: Matches mails that have the specified Mail Attribute.  All 
-recipients are returned.</p>
-<p>Configuration string: The name of the Mail Attribute to match. For example:<br/>
-<pre><code>
-&lt;mailet match="HasMailAttribute=name" class=&quot;&lt;any-class&gt;&quot;&gt;
-</code></pre>
-</p>
-</subsection>
-
-<subsection name="HasMailAttributeWithValue">
-<p>Description: Matches mails that have the specified Mail Attribute and the
-specified MailAttribute value. All recipients are returned.</p>
-<p>MailAttributes are types of Object whereas the value specified in the Matcher
-condition is of type String. The toString() method is used to obtain a String
-representation of the Mail Attribute value for matching. The 
-String.equals(String) method tests for a match.</p>
-<p>Configuration string: The name of the Mail Attribute to be matched,  a comma
-and then the String value to be matched. For example:<br/>
-<pre><code>
-&lt;mailet match="HasMailAttributeWithValue=name, value" class=&quot;&lt;any-class&gt;&quot;&gt;
-</code></pre>
-</p>
-</subsection>
-
-<subsection name="HasMailAttributeWithValueRegex">
-<p>Description: Matches mails that have the specified Mail Attribute and 
-a MailAttribute value that matches the specified regular expression.
-All recipients are returned.</p>
-<p>MailAttributes are types of Object whereas the value specified in the Matcher
-condition is of type String. The toString() method is used to obtain a String
-representation of the Mail Attribute value for matching. The regular
-expression must follow Perl5 syntax.</p>
-<p>Configuration string: The name of the Mail Attribute to be matched,  a comma
-and then the regular expression used to match the value against. For example:<br/>
-<pre><code>
-&lt;mailet match="HasMailAttributeWithValueRegex=name, regex" class=&quot;&lt;any-class&gt;&quot;&gt;
-</code></pre>
-</p>
-</subsection>
-
-<subsection name="HostIs">
-<p>Description: Matches mails that are sent to email addresses on hosts that are in the configuration list.  Only 
-recipients that are on one of the hosts are returned.</p>
-<p>Configuration string: A list of host names, comma or space delimited.
-<pre><code>
-&lt;mailet match="HostIs=value, value, .." class=&quot;&lt;any-class&gt;&quot;&gt;
-</code></pre>
-</p>
-</subsection>
-
-<subsection name="HostIsLocal">
-<p>Description: Matches mails that are sent to email addresses on local hosts.  Only 
-recipients that are on one of the local hosts are returned.</p>
-<p>Configuration string: None.</p>
-</subsection>
-
-<subsection name="InSpammerBlacklist">
-<p>Description: Checks the mail against one of a number of mail-abuse.org IP lists. All recipients are returned</p>
-<p>Configuration string: One of three strings - "blackholes.mail-abuse.org", "relays.mail-abuse.org", or "dialups.mail-abuse.org".</p>
-</subsection>
-
-<subsection name="IsInWhiteList">
-<p>Description: Matches recipients having the mail sender in the recipient's private whitelist.
-The recipient name is always converted to its primary name (handling aliases).</p>
-<p>Configuration string: The database name containing the white list table.</p>
-<pre><code>
-&lt;mailet match="IsInWhiteList=db://maildb" class="ToProcessor"&gt;
-  &lt;processor&gt; transport &lt;/processor&gt;
-&lt;/mailet&gt;
-</code></pre>
-</subsection>
-
-<subsection name="IsSingleRecipient">
-<p>Description: Matches those messages sent to only a single recipient.  The single recipient is returned.</p>
-<p>Configuration string: None.</p>
-</subsection>
-
-<subsection name="NESSpamCheck">
-<p>Description: A matcher derived from a Netscape Mail Server spam filter.  If the matcher detects headers that 
-indicate spam, the message is matched.  All recipients are returned.</p>
-<p>Configuration string: None.</p>
-</subsection>
-
-<subsection name="RecipientIs">
-<p>Description: Matches mails that are sent to one of the recipients on a specified list.  Only 
-matching recipients are returned.</p>
-<p>Configuration string: A list of recipient addresses, comma, tab, or space delimited.
-<pre><code>
-&lt;mailet match="RecipientIs=value, value, .." class=&quot;&lt;any-class&gt;&quot;&gt;
-</code></pre>
-</p>
-</subsection>
-
-<subsection name="RecipientIsLocal">
-<p>Description: Matches mails that are sent to email addresses on local hosts with users that have local acccunts.  Only 
-matching recipients are returned.</p>
-<p>Configuration string: None.</p>
-</subsection>
-
-<subsection name="RecipientIsOverFixedQuota">
-<p>Description: Matches mails that are send to email addresses which are over the given quota. Only 
-matching recipients are returned.</p>
-<p>Configuration string: The quota
-<pre><code>
-&lt;mailet match="RecipientIsOverFixedQuota=10m" class=&quot;&lt;any-class&gt;&quot;&gt;
-</code></pre>
-</p>
-</subsection>
-
-<subsection name="RecipientIsRegex">
-<p>Description: Matches mails that are send to email addresses which are matched given regex. Only 
-matching recipients are returned.</p>
-<p>Configuration string: The quota
-<pre><code>
-&lt;mailet match="RecipientIsRegex=value" class=&quot;&lt;any-class&gt;&quot;&gt;
-</code></pre>
-</p>
-</subsection>
-
-
-<subsection name="RelayLimit">
-<p>Description: Counts the number of Received headers in the mail (each of which represents a server 
-in the relay chain).  If the number equals or exceeds the specified limit, the mail is 
-matched.  All recipients are returned.</p>
-<p>Configuration string: a positive integer that is the limit on the number of relays.
-<pre><code>
-&lt;mailet match="RelayLimit=value" class=&quot;&lt;any-class&gt;&quot;&gt;
-</code></pre>
-</p>
-</subsection>
-
-<subsection name="RemoteAddrInNetwork">
-<p>Description: Checks the remote address from which the mail was received against the configured list.  If the address matches one on the list, the matcher considers it a match.  
-All recipients are returned.</p>
-<p>Configuration string: A list of domain names, IP addresses, or wildcarded IP subnets of any class.  The 
-list may be comma or space delimited.
-<pre><code>
-&lt;mailet match="RemoteAddrInNetwork=value, value, .." class=&quot;&lt;any-class&gt;&quot;&gt;
-</code></pre>
-</p>
-</subsection>
-
-<subsection name="RemoteAddrNotInNetwork">
-<p>Description: Checks the remote address from which the mail was received against the configured list.  If the address doesn't match one on the list, the matcher considers it a match. 
-All recipients are returned.</p>
-<p>Configuration string: A list of domain names, IP addresses, or wildcarded IP subnets of any class.  The 
-list may be comma or space delimited.
-<pre><code>
-&lt;mailet match="RemoteAddrNotInNetwork=value, value, .." class=&quot;&lt;any-class&gt;&quot;&gt;
-</code></pre>
-</p>
-</subsection>
-
-<subsection name="SenderHostIs">
-<p>Description: Matches mails where the host name in the address of the sender cannot be resolved.  All 
-recipients are returned.</p>
-<p>Configuration string: None.</p>
-</subsection>
-
-<subsection name="SenderInFakeDomain">
-<p>Description: Matches mails where the host name in the address of the sender cannot be resolved.  All 
-recipients are returned.</p>
-<p>Configuration string: None.</p>
-</subsection>
-
-<subsection name="SenderIs">
-<p>Description: Matches mails that are sent by one of the senders on a specified list.  All 
-recipients are returned.</p>
-<p>Configuration string: A list of sender addresses, comma, tab, or space delimited.
-<pre><code>
-&lt;mailet match="SenderIs=value, value, .." class=&quot;&lt;any-class&gt;&quot;&gt;
-</code></pre>
-</p>
-</subsection>
-
-<subsection name="SenderIsNull">
-<p>Description: Matches mails that are sent by a null sender.</p>
-<p>Configuration string: none.
-<pre><code>
-&lt;mailet match="SenderIsNull" class=&quot;&lt;any-class&gt;&quot;&gt;
-</code></pre>
-</p>
-</subsection>
-
-<subsection name="SenderIsRegex">
-<p>Description: Matches mails that are sent by one of the senders matched the given regex.
-All recipients are returned.</p>
-<p>Configuration string: A regex.
-<pre><code>
-&lt;mailet match="SenderIsRegex=value" class=&quot;&lt;any-class&gt;&quot;&gt;
-</code></pre>
-</p>
-</subsection>
-
-<subsection name="SizeGreaterThan">
-<p>Description: Matches emails with a total message size (headers and body) greater than the specified limit.  
-All recipients are returned.</p>
-<p>Configuration string: a positive integer followed by an 'm' or a 'k'.  This is the maximum message size permitted 
-specified in megabytes or kilobytes respectively.
-<pre><code>
-&lt;mailet match="SizeGreaterThan=1m" class=&quot;&lt;any-class&gt;&quot;&gt;
-</code></pre>
-</p>
-</subsection>
-
-<subsection name="SMTPAuthSuccessful">
-<p>Description: Matches mails that are send from an authorized sender. All recipients are returned.</p>
-<p>Configuration string: none.
-<pre><code>
-&lt;mailet match="SMTPAuthSuccessful" class=&quot;&lt;any-class&gt;&quot;&gt;
-</code></pre>
-</p>
-</subsection>
-
-<subsection name="SMTPAuthUserIs">
-<p>Description: Matches mails that are send from one of the given authorized senders. All recipients are returned.</p>
-<p>Configuration string: none.
-<pre><code>
-&lt;mailet match="SMTPAuthUserIs=value, value, .." class=&quot;&lt;any-class&gt;&quot;&gt;
-</code></pre>
-</p>
-</subsection>
-
-
-<subsection name="SubjectIs">
-<p>Description: Matches emails with the specified subject.  All recipients are returned.</p>
-<p>Configuration string: The string against which mail subject headers are matched.
-<pre><code>
-&lt;mailet match="SubjectIs=value" class=&quot;&lt;any-class&gt;&quot;&gt;
-</code></pre>
-</p>
-</subsection>
-
-<subsection name="SubjectStartsWith">
-<p>Description: Matches emails whose subject header starts with the specified string.  All recipients are returned.</p>
-<p>Configuration string: The string against which mail subject headers are matched.
-<pre><code>
-&lt;mailet match="SubjectStartsWith=value" class=&quot;&lt;any-class&gt;&quot;&gt;
-</code></pre>
-</p>
-</subsection>
-
-<subsection name="UserIs">
-<p>Description: Matches mails that are sent to email addresses that have userids that are in the configuration list.  Only 
-matching recipients are returned.</p>
-<p>Configuration string: A list of user names, comma or space delimited.
-<pre><code>
-&lt;mailet match="UserIs=value, value, .." class=&quot;&lt;any-class&gt;&quot;&gt;
-</code></pre>
-</p>
-</subsection>
-
-</section>
-</body>
+    <properties>
+        <title>Apache James Server 3 - Provided Matchers</title>
+    </properties>
+
+    <body>
+
+        <section name="Matchers">
+
+            <p>James provides a number of implemented Matchers for use by James administrators in their
+                configurations.  These are primarily matchers that members of the James developer or user
+                communities have found useful in their own configurations.  A description of how to configure
+                Matchers and use them in the James SpoolManager can be found <a href="config-mailetcontainer.html">here</a>.</p>
+
+            <subsection name="All">
+                <p>Description: This matcher is the trivial one - it matches all mails being processed. All recipients are returned.</p>
+                <p>Configuration string: None.</p>
+            </subsection>
+
+            <subsection name="AttachmentFileNameIs">
+                <p>Description: It can be used to refuse emails with SCR, PIF, EXE etc. attachments.
+                    It matches mails that has a file attachment with a file name meeting one of the supplied filters.
+                    All recipients are returned.</p>
+                <p>Configuration string: A comma or space delimited list of file names.
+                    File names may start with a wildcard '*'. Example: *.scr,*.bat,*.pif,*.pi,*.com,*.exe
+                    <pre><code>
+                        &lt;mailet match="AttachmentFileNameIs=value, value, .." class=&quot;&lt;any-class&gt;&quot;&gt;
+                    </code></pre>
+                </p>
+            </subsection>
+
+            <subsection name="CommandForListserv">
+                <p>Description: The CommandForListserv matcher is used as a simple filter to recognize emails that are list server
+                    commands.  It will match any email addressed to the list server host, as well as any email that is addressed
+                    to a user named &lt;prefix&gt;-on or &lt;prefix&gt;-off on any host.  Only those matching recipients will be returned.</p>
+                <p>Configuration string: An email address of the form &lt;prefix&gt;@&lt;host&gt;, where host is the hostname used for the listserver and prefix is the command prefix.
+                    <pre><code>
+                        &lt;mailet match="CommandForListserv=james-on@list.working-dogs.com" class=&quot;&lt;any-class&gt;&quot;&gt;
+                    </code></pre>
+                </p>
+            </subsection>
+
+            <subsection name="CommandForListservManager">
+                <p>Description: CommandListservMatcher is the matcher that pairs with the CommandListservManager mailet. It checks to see if the request is
+                    intended for the ListservManager, but doesn't guarantee that it is a valid command.  Only those matching recipients will be returned.</p>
+                <p>Configuration string: An email address.
+                    <pre><code>
+                        &lt;mailet match="CommandForListservManager=announce@localhost" class=&quot;&lt;any-class&gt;&quot;&gt;
+                    </code></pre>
+                </p>
+            </subsection>
+
+            <subsection name="CompareNumericHeaderValue">
+                <p>Description: Matches mails containing a header with a numeric value whose comparison with the specified value is true.
+                    If the header is missing in the message, there will be <i>no match</i>. All recipients are returned.</p>
+                <p>Configuration string: The headerName, a comparison operator and the numeric headerValue
+                    to compare with, <i>space or tab delimited</i>.
+                    <pre><code>
+                        &lt;mailet match="CompareNumericHeaderValue= X-MessageIsSpamProbability &gt; 0.9" class=&quot;&lt;any-class&gt;&quot;&gt;
+                    </code></pre>
+                </p>
+            </subsection>
+
+            <subsection name="FetchedFrom">
+                <p>Description: A matcher intended for use with the FetchMail server.  It matches a custom header (X-fetched-from) that is
+                    set by the FetchMail server.  FetchMail sets this header to the name of the FetchPOP task which originally fetched
+                    the message.  All recipients are returned.</p>
+                <p>Configuration string: The name of the FetchMail task which originally fetched the message.
+                    <pre><code>
+                        &lt;mailet match="FetchedFrom=value" class=&quot;&lt;any-class&gt;&quot;&gt;
+                    </code></pre>
+                </p>
+            </subsection>
+
+            <subsection name="FileRegexMatcher">
+                <p>Description: A matcher which can be used to match on a attachment when the given regex match. All recipients are returned.</p>
+                <p>Configuration string: A regex for match attachmentname.
+                    <pre><code>
+                        &lt;mailet match="FileRegexMatcher=value" class=&quot;&lt;any-class&gt;&quot;&gt;
+                    </code></pre>
+                </p>
+            </subsection>
+
+            <subsection name="HasAttachment">
+                <p>Description: Matches those messages with a MIME type of "multipart/mixed".  All recipients are returned.</p>
+                <p>Configuration string: None.</p>
+            </subsection>
+
+            <subsection name="HasHabeasWarrantMark">
+                <p>Description: Matches mails that have the Habeas Warrant (see http://www.habeas.com for details).  All recipients are returned.</p>
+                <p>Configuration string: None.</p>
+            </subsection>
+
+            <subsection name="HasHeader">
+                <p>Description: Matches mails that have the specified header.  All recipients are returned.</p>
+                <p>
+                    Configuration string: The name of the header whose presence determines the match.
+                    <pre><code>
+                        &lt;mailet match="HasHeader=headerName" class=&quot;&lt;any-class&gt;&quot;&gt;
+                    </code></pre>
+                </p>
+
+            </subsection>
+
+            <subsection name="HasMailAttribute">
+                <p>Description: Matches mails that have the specified Mail Attribute.  All
+                    recipients are returned.</p>
+                <p>Configuration string: The name of the Mail Attribute to match. For example:<br/>
+                    <pre><code>
+                        &lt;mailet match="HasMailAttribute=name" class=&quot;&lt;any-class&gt;&quot;&gt;
+                    </code></pre>
+                </p>
+            </subsection>
+
+            <subsection name="HasMailAttributeWithValue">
+                <p>Description: Matches mails that have the specified Mail Attribute and the
+                    specified MailAttribute value. All recipients are returned.</p>
+                <p>MailAttributes are types of Object whereas the value specified in the Matcher
+                    condition is of type String. The toString() method is used to obtain a String
+                    representation of the Mail Attribute value for matching. The
+                    String.equals(String) method tests for a match.</p>
+                <p>Configuration string: The name of the Mail Attribute to be matched,  a comma
+                    and then the String value to be matched. For example:<br/>
+                    <pre><code>
+                        &lt;mailet match="HasMailAttributeWithValue=name, value" class=&quot;&lt;any-class&gt;&quot;&gt;
+                    </code></pre>
+                </p>
+            </subsection>
+
+            <subsection name="HasMailAttributeWithValueRegex">
+                <p>Description: Matches mails that have the specified Mail Attribute and
+                    a MailAttribute value that matches the specified regular expression.
+                    All recipients are returned.</p>
+                <p>MailAttributes are types of Object whereas the value specified in the Matcher
+                    condition is of type String. The toString() method is used to obtain a String
+                    representation of the Mail Attribute value for matching. The regular
+                    expression must follow Perl5 syntax.</p>
+                <p>Configuration string: The name of the Mail Attribute to be matched,  a comma
+                    and then the regular expression used to match the value against. For example:<br/>
+                    <pre><code>
+                        &lt;mailet match="HasMailAttributeWithValueRegex=name, regex" class=&quot;&lt;any-class&gt;&quot;&gt;
+                    </code></pre>
+                </p>
+            </subsection>
+
+            <subsection name="HostIs">
+                <p>Description: Matches mails that are sent to email addresses on hosts that are in the configuration list.  Only
+                    recipients that are on one of the hosts are returned.</p>
+                <p>Configuration string: A list of host names, comma or space delimited.
+                    <pre><code>
+                        &lt;mailet match="HostIs=value, value, .." class=&quot;&lt;any-class&gt;&quot;&gt;
+                    </code></pre>
+                </p>
+            </subsection>
+
+            <subsection name="HostIsLocal">
+                <p>Description: Matches mails that are sent to email addresses on local hosts.  Only
+                    recipients that are on one of the local hosts are returned.</p>
+                <p>Configuration string: None.</p>
+            </subsection>
+
+            <subsection name="InSpammerBlacklist">
+                <p>Description: Checks the mail against one of a number of mail-abuse.org IP lists. All recipients are returned</p>
+                <p>Configuration string: One of three strings - "blackholes.mail-abuse.org", "relays.mail-abuse.org", or "dialups.mail-abuse.org".</p>
+            </subsection>
+
+            <subsection name="IsInWhiteList">
+                <p>Description: Matches recipients having the mail sender in the recipient's private whitelist.
+                    The recipient name is always converted to its primary name (handling aliases).</p>
+                <p>Configuration string: The database name containing the white list table.</p>
+                <pre><code>
+                    &lt;mailet match="IsInWhiteList=db://maildb" class="ToProcessor"&gt;
+                    &lt;processor&gt; transport &lt;/processor&gt;
+                    &lt;/mailet&gt;
+                </code></pre>
+            </subsection>
+
+            <subsection name="IsSingleRecipient">
+                <p>Description: Matches those messages sent to only a single recipient.  The single recipient is returned.</p>
+                <p>Configuration string: None.</p>
+            </subsection>
+
+            <subsection name="NESSpamCheck">
+                <p>Description: A matcher derived from a Netscape Mail Server spam filter.  If the matcher detects headers that
+                    indicate spam, the message is matched.  All recipients are returned.</p>
+                <p>Configuration string: None.</p>
+            </subsection>
+
+            <subsection name="RecipientIs">
+                <p>Description: Matches mails that are sent to one of the recipients on a specified list.  Only
+                    matching recipients are returned.</p>
+                <p>Configuration string: A list of recipient addresses, comma, tab, or space delimited.
+                    <pre><code>
+                        &lt;mailet match="RecipientIs=value, value, .." class=&quot;&lt;any-class&gt;&quot;&gt;
+                    </code></pre>
+                </p>
+            </subsection>
+
+            <subsection name="RecipientIsLocal">
+                <p>Description: Matches mails that are sent to email addresses on local hosts with users that have local acccunts.  Only
+                    matching recipients are returned.</p>
+                <p>Configuration string: None.</p>
+            </subsection>
+
+            <subsection name="RecipientIsOverFixedQuota">
+                <p>Description: Matches mails that are send to email addresses which are over the given quota. Only
+                    matching recipients are returned.</p>
+                <p>Configuration string: The quota
+                    <pre><code>
+                        &lt;mailet match="RecipientIsOverFixedQuota=10m" class=&quot;&lt;any-class&gt;&quot;&gt;
+                    </code></pre>
+                </p>
+            </subsection>
+
+            <subsection name="RecipientIsRegex">
+                <p>Description: Matches mails that are send to email addresses which are matched given regex. Only
+                    matching recipients are returned.</p>
+                <p>Configuration string: The quota
+                    <pre><code>
+                        &lt;mailet match="RecipientIsRegex=value" class=&quot;&lt;any-class&gt;&quot;&gt;
+                    </code></pre>
+                </p>
+            </subsection>
+
+
+            <subsection name="RelayLimit">
+                <p>Description: Counts the number of Received headers in the mail (each of which represents a server
+                    in the relay chain).  If the number equals or exceeds the specified limit, the mail is
+                    matched.  All recipients are returned.</p>
+                <p>Configuration string: a positive integer that is the limit on the number of relays.
+                    <pre><code>
+                        &lt;mailet match="RelayLimit=value" class=&quot;&lt;any-class&gt;&quot;&gt;
+                    </code></pre>
+                </p>
+            </subsection>
+
+            <subsection name="RemoteAddrInNetwork">
+                <p>Description: Checks the remote address from which the mail was received against the configured list.  If the address matches one on the list, the matcher considers it a match.
+                    All recipients are returned.</p>
+                <p>Configuration string: A list of domain names, IP addresses, or wildcarded IP subnets of any class.  The
+                    list may be comma or space delimited.
+                    <pre><code>
+                        &lt;mailet match="RemoteAddrInNetwork=value, value, .." class=&quot;&lt;any-class&gt;&quot;&gt;
+                    </code></pre>
+                </p>
+            </subsection>
+
+            <subsection name="RemoteAddrNotInNetwork">
+                <p>Description: Checks the remote address from which the mail was received against the configured list.  If the address doesn't match one on the list, the matcher considers it a match.
+                    All recipients are returned.</p>
+                <p>Configuration string: A list of domain names, IP addresses, or wildcarded IP subnets of any class.  The
+                    list may be comma or space delimited.
+                    <pre><code>
+                        &lt;mailet match="RemoteAddrNotInNetwork=value, value, .." class=&quot;&lt;any-class&gt;&quot;&gt;
+                    </code></pre>
+                </p>
+            </subsection>
+
+            <subsection name="SenderHostIs">
+                <p>Description: Matches mails where the host name in the address of the sender cannot be resolved.  All
+                    recipients are returned.</p>
+                <p>Configuration string: None.</p>
+            </subsection>
+
+            <subsection name="SenderInFakeDomain">
+                <p>Description: Matches mails where the host name in the address of the sender cannot be resolved.  All
+                    recipients are returned.</p>
+                <p>Configuration string: None.</p>
+            </subsection>
+
+            <subsection name="SenderIs">
+                <p>Description: Matches mails that are sent by one of the senders on a specified list.  All
+                    recipients are returned.</p>
+                <p>Configuration string: A list of sender addresses, comma, tab, or space delimited.
+                    <pre><code>
+                        &lt;mailet match="SenderIs=value, value, .." class=&quot;&lt;any-class&gt;&quot;&gt;
+                    </code></pre>
+                </p>
+            </subsection>
+
+            <subsection name="SenderIsNull">
+                <p>Description: Matches mails that are sent by a null sender.</p>
+                <p>Configuration string: none.
+                    <pre><code>
+                        &lt;mailet match="SenderIsNull" class=&quot;&lt;any-class&gt;&quot;&gt;
+                    </code></pre>
+                </p>
+            </subsection>
+
+            <subsection name="SenderIsRegex">
+                <p>Description: Matches mails that are sent by one of the senders matched the given regex.
+                    All recipients are returned.</p>
+                <p>Configuration string: A regex.
+                    <pre><code>
+                        &lt;mailet match="SenderIsRegex=value" class=&quot;&lt;any-class&gt;&quot;&gt;
+                    </code></pre>
+                </p>
+            </subsection>
+
+            <subsection name="SizeGreaterThan">
+                <p>Description: Matches emails with a total message size (headers and body) greater than the specified limit.
+                    All recipients are returned.</p>
+                <p>Configuration string: a positive integer followed by an 'm' or a 'k'.  This is the maximum message size permitted
+                    specified in megabytes or kilobytes respectively.
+                    <pre><code>
+                        &lt;mailet match="SizeGreaterThan=1m" class=&quot;&lt;any-class&gt;&quot;&gt;
+                    </code></pre>
+                </p>
+            </subsection>
+
+            <subsection name="SMTPAuthSuccessful">
+                <p>Description: Matches mails that are send from an authorized sender. All recipients are returned.</p>
+                <p>Configuration string: none.
+                    <pre><code>
+                        &lt;mailet match="SMTPAuthSuccessful" class=&quot;&lt;any-class&gt;&quot;&gt;
+                    </code></pre>
+                </p>
+            </subsection>
+
+            <subsection name="SMTPAuthUserIs">
+                <p>Description: Matches mails that are send from one of the given authorized senders. All recipients are returned.</p>
+                <p>Configuration string: none.
+                    <pre><code>
+                        &lt;mailet match="SMTPAuthUserIs=value, value, .." class=&quot;&lt;any-class&gt;&quot;&gt;
+                    </code></pre>
+                </p>
+            </subsection>
+
+
+            <subsection name="SubjectIs">
+                <p>Description: Matches emails with the specified subject.  All recipients are returned.</p>
+                <p>Configuration string: The string against which mail subject headers are matched.
+                    <pre><code>
+                        &lt;mailet match="SubjectIs=value" class=&quot;&lt;any-class&gt;&quot;&gt;
+                    </code></pre>
+                </p>
+            </subsection>
+
+            <subsection name="SubjectStartsWith">
+                <p>Description: Matches emails whose subject header starts with the specified string.  All recipients are returned.</p>
+                <p>Configuration string: The string against which mail subject headers are matched.
+                    <pre><code>
+                        &lt;mailet match="SubjectStartsWith=value" class=&quot;&lt;any-class&gt;&quot;&gt;
+                    </code></pre>
+                </p>
+            </subsection>
+
+            <subsection name="UserIs">
+                <p>Description: Matches mails that are sent to email addresses that have userids that are in the configuration list.  Only
+                    matching recipients are returned.</p>
+                <p>Configuration string: A list of user names, comma or space delimited.
+                    <pre><code>
+                        &lt;mailet match="UserIs=value, value, .." class=&quot;&lt;any-class&gt;&quot;&gt;
+                    </code></pre>
+                </p>
+            </subsection>
+
+        </section>
+    </body>
 </document>


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


[03/10] james-project git commit: JAMES-1773 Add tests for JamesMailetContext. Required to test RecipientIsLocal.

Posted by bt...@apache.org.
JAMES-1773 Add tests for JamesMailetContext. Required to test RecipientIsLocal.

Are tested : isLocalServer, isLocalUser, isLocalEmail


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

Branch: refs/heads/master
Commit: 992ab012b2b969fa3445dc33de28590c28621f55
Parents: d0114b5
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Aug 10 10:06:08 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Aug 18 17:18:15 2016 +0700

----------------------------------------------------------------------
 server/mailet/mailetcontainer-camel/pom.xml     |  11 ++
 .../impl/JamesMailetContextTest.java            | 142 +++++++++++++++++++
 2 files changed, 153 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/992ab012/server/mailet/mailetcontainer-camel/pom.xml
----------------------------------------------------------------------
diff --git a/server/mailet/mailetcontainer-camel/pom.xml b/server/mailet/mailetcontainer-camel/pom.xml
index 6de3849..c3a591c 100644
--- a/server/mailet/mailetcontainer-camel/pom.xml
+++ b/server/mailet/mailetcontainer-camel/pom.xml
@@ -113,6 +113,11 @@
         </dependency>
         <dependency>
             <groupId>org.apache.james</groupId>
+            <artifactId>james-server-data-memory</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.james</groupId>
             <artifactId>apache-mailet-base</artifactId>
             <classifier>tests</classifier>
             <scope>test</scope>
@@ -129,6 +134,12 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+            <version>${assertj-1.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.mockito</groupId>
             <artifactId>mockito-core</artifactId>
             <scope>test</scope>

http://git-wip-us.apache.org/repos/asf/james-project/blob/992ab012/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/JamesMailetContextTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/JamesMailetContextTest.java b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/JamesMailetContextTest.java
new file mode 100644
index 0000000..a70d8a9
--- /dev/null
+++ b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/JamesMailetContextTest.java
@@ -0,0 +1,142 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mailetcontainer.impl;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.james.domainlist.memory.MemoryDomainList;
+import org.apache.james.user.memory.MemoryUsersRepository;
+import org.apache.mailet.MailAddress;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class JamesMailetContextTest {
+    private static final Logger LOGGER = LoggerFactory.getLogger(JamesMailetContextTest.class);
+
+    public static final String DOMAIN_COM = "domain.com";
+    public static final String USERNAME = "user";
+    public static final String USERMAIL = USERNAME + "@" + DOMAIN_COM;
+    public static final String PASSWORD = "password";
+
+    private MemoryDomainList domainList;
+    private MemoryUsersRepository usersRepository;
+    private JamesMailetContext testee;
+    private MailAddress mailAddress;
+
+    @Before
+    public void setUp() throws Exception {
+        domainList = new MemoryDomainList();
+        domainList.setLog(LOGGER);
+        usersRepository = MemoryUsersRepository.withVirtualHosting();
+        usersRepository.setDomainList(domainList);
+        testee = new JamesMailetContext();
+        testee.setDomainList(domainList);
+        testee.setUsersRepository(usersRepository);
+        mailAddress = new MailAddress(USERMAIL);
+    }
+
+    @Test
+    public void isLocalUserShouldBeFalseOnNullUser() {
+        assertThat(testee.isLocalUser(null)).isFalse();
+    }
+
+    @Test
+    public void isLocalServerShouldBeFalseWhenDomainDoNotExist() {
+        assertThat(testee.isLocalServer(DOMAIN_COM)).isFalse();
+    }
+
+    @Test
+    public void isLocalServerShouldBeTrueWhenDomainExist() throws Exception {
+        domainList.addDomain(DOMAIN_COM);
+
+        assertThat(testee.isLocalServer(DOMAIN_COM)).isTrue();
+    }
+
+    @Test
+    public void isLocalUserShouldBeTrueWhenUsernameExist() throws Exception {
+        domainList.addDomain(DOMAIN_COM);
+        usersRepository.addUser(USERMAIL, PASSWORD);
+
+        assertThat(testee.isLocalUser(USERMAIL)).isTrue();
+    }
+
+    @Test
+    public void isLocalUserShouldReturnTrueWhenUsedWithLocalPartAndUserExistOnDefaultDomain() throws Exception {
+        HierarchicalConfiguration configuration = mock(HierarchicalConfiguration.class);
+        when(configuration.getString(eq("defaultDomain"), any(String.class)))
+            .thenReturn(DOMAIN_COM);
+
+        domainList.configure(configuration);
+        domainList.addDomain(DOMAIN_COM);
+        usersRepository.addUser(USERMAIL, PASSWORD);
+
+        assertThat(testee.isLocalUser(USERNAME)).isTrue();
+    }
+
+    @Test
+    public void isLocalUserShouldReturnFalseWhenUsedWithLocalPartAndUserDoNotExistOnDefaultDomain() throws Exception {
+        HierarchicalConfiguration configuration = mock(HierarchicalConfiguration.class);
+        when(configuration.getString(eq("defaultDomain"), any(String.class)))
+            .thenReturn("any");
+
+        domainList.configure(configuration);
+        domainList.addDomain(DOMAIN_COM);
+        usersRepository.addUser(USERMAIL, PASSWORD);
+
+        assertThat(testee.isLocalUser(USERNAME)).isFalse();
+    }
+
+    @Test
+    public void isLocalUserShouldBeFalseWhenUsernameDoNotExist() throws Exception {
+        assertThat(testee.isLocalUser(USERMAIL)).isFalse();
+    }
+
+    @Test
+    public void isLocalEmailShouldBeFalseWhenUsernameDoNotExist() throws Exception {
+        assertThat(testee.isLocalEmail(mailAddress)).isFalse();
+    }
+
+    @Test
+    public void isLocalEmailShouldBeFalseWhenUsernameDoNotExistButDomainExists() throws Exception {
+        domainList.addDomain(DOMAIN_COM);
+
+        assertThat(testee.isLocalEmail(mailAddress)).isFalse();
+    }
+
+    @Test
+    public void isLocalEmailShouldBeTrueWhenUsernameExists() throws Exception {
+        domainList.addDomain(DOMAIN_COM);
+        usersRepository.addUser(USERMAIL, PASSWORD);
+
+        assertThat(testee.isLocalEmail(mailAddress)).isTrue();
+    }
+
+    @Test
+    public void isLocalEmailShouldBeFalseWhenMailIsNull() throws Exception {
+        assertThat(testee.isLocalEmail(null)).isFalse();
+    }
+}


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


[04/10] james-project git commit: JAMES-1773 Relay limit can not be negative or null

Posted by bt...@apache.org.
JAMES-1773 Relay limit can not be negative or null


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

Branch: refs/heads/master
Commit: 3ef4a113e0ec3e317e00835455292619fdb154b9
Parents: b738594
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Aug 10 15:50:49 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Aug 18 17:18:15 2016 +0700

----------------------------------------------------------------------
 .../main/java/org/apache/james/transport/matchers/RelayLimit.java | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/3ef4a113/mailet/standard/src/main/java/org/apache/james/transport/matchers/RelayLimit.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/main/java/org/apache/james/transport/matchers/RelayLimit.java b/mailet/standard/src/main/java/org/apache/james/transport/matchers/RelayLimit.java
index 7a464be..2b5d52c 100644
--- a/mailet/standard/src/main/java/org/apache/james/transport/matchers/RelayLimit.java
+++ b/mailet/standard/src/main/java/org/apache/james/transport/matchers/RelayLimit.java
@@ -47,6 +47,9 @@ public class RelayLimit extends GenericMatcher {
         } catch (NumberFormatException e) {
             throw new MessagingException("No valid integer: " + getCondition());
         }
+        if (limit <= 0) {
+            throw new MessagingException("Relay limit should be superior to 0");
+        }
     }
 
     public Collection<MailAddress> match(Mail mail) throws javax.mail.MessagingException {


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


[10/10] james-project git commit: JAMES-1773 HasHeaderTest should match our coding standards

Posted by bt...@apache.org.
JAMES-1773 HasHeaderTest should match our coding standards


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

Branch: refs/heads/master
Commit: c94a99f5492a167cf9657263fa3648b1474fb3d1
Parents: 932acf5
Author: Benoit Tellier <bt...@linagora.com>
Authored: Tue Aug 9 11:33:25 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Aug 18 17:18:15 2016 +0700

----------------------------------------------------------------------
 .../james/transport/matchers/HasHeaderTest.java | 73 +++++---------------
 1 file changed, 19 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/c94a99f5/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderTest.java
index d656296..6b40cec 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderTest.java
@@ -20,81 +20,46 @@
 
 package org.apache.james.transport.matchers;
 
-import org.apache.james.transport.matchers.HasHeader;
-import org.apache.mailet.MailAddress;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+
 import org.apache.mailet.Matcher;
 import org.apache.mailet.base.test.FakeMail;
 import org.apache.mailet.base.test.FakeMailContext;
 import org.apache.mailet.base.test.FakeMatcherConfig;
 import org.apache.mailet.base.test.MailUtil;
-import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
 
-import javax.mail.MessagingException;
-import javax.mail.internet.MimeMessage;
-import java.util.Collection;
-
 public class HasHeaderTest {
 
-    private MimeMessage mockedMimeMessage;
+    private static final String HEADER_NAME_1 = "JUNIT";
+    private static final String HEADER_NAME_2 = "defaultHeaderName";
+    private static final String HEADER_VALUE_1 = "defaultHeaderValue";
 
     private FakeMail mockedMail;
-
     private Matcher matcher;
 
-    private final String HEADER_NAME = "JUNIT";
-
-    private String headerName = "defaultHeaderName";
-
-    private String headerValue = "defaultHeaderValue";
-
-    private void setHeaderName(String headerName) {
-        this.headerName = headerName;
-    }
-
-    private void setHeaderValue(String headerValue) {
-        this.headerValue = headerValue;
-    }
-
-    private void setupMockedMimeMessage() throws MessagingException {
-        mockedMimeMessage = MailUtil.createMimeMessage(headerName, headerValue);
-    }
-
-    private void setupMatcher() throws MessagingException {
-        setupMockedMimeMessage();
+    @Before
+    public void setUp() throws Exception {
+        MimeMessage mimeMessage = MailUtil.createMimeMessage(HEADER_NAME_1, HEADER_VALUE_1);
+        mockedMail = MailUtil.createMockMail2Recipients(mimeMessage);
         matcher = new HasHeader();
-        FakeMatcherConfig mci = new FakeMatcherConfig("HasHeader="
-                + HEADER_NAME, new FakeMailContext());
-        matcher.init(mci);
     }
 
-    // test if the Header was matched
     @Test
-    public void testHeaderIsMatched() throws MessagingException {
-        setHeaderName(HEADER_NAME);
-        String HEADER_VALUE = "test-value";
-        setHeaderValue(HEADER_VALUE);
-
-        setupMockedMimeMessage();
-        mockedMail = MailUtil.createMockMail2Recipients(mockedMimeMessage);
-        setupMatcher();
+    public void matchShouldReturnAddressesWhenRightHeaderNameWithoutValue() throws MessagingException {
+        matcher.init(new FakeMatcherConfig("HasHeader=" + HEADER_NAME_1, new FakeMailContext()));
 
-        Collection<MailAddress> matchedRecipients = matcher.match(mockedMail);
-
-        Assert.assertNotNull(matchedRecipients);
-        Assert.assertEquals(matchedRecipients.size(), mockedMail.getRecipients()
-                .size());
+        assertThat(matcher.match(mockedMail)).containsAll(mockedMail.getRecipients());
     }
 
-    // test if the Header was not matched
     @Test
-    public void testHeaderIsNotMatched() throws MessagingException {
-        setupMockedMimeMessage();
-        mockedMail = MailUtil.createMockMail2Recipients(mockedMimeMessage);
-        setupMatcher();
-
-        Collection<MailAddress> matchedRecipients = matcher.match(mockedMail);
+    public void matchShouldReturnNullWhenWrongHeaderNameWithoutValue() throws MessagingException {
+        matcher.init(new FakeMatcherConfig("HasHeader=" + HEADER_NAME_2, new FakeMailContext()));
 
-        Assert.assertNull(matchedRecipients);
+        assertThat(matcher.match(mockedMail)).isNull();
     }
 }


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


[05/10] james-project git commit: JAMES-1773 Provide tests for RelayLimit

Posted by bt...@apache.org.
JAMES-1773 Provide tests for RelayLimit


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

Branch: refs/heads/master
Commit: be1be8b91139de41e9130fa127af3acd8d9d5f4e
Parents: 3ef4a11
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Aug 10 15:51:26 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Aug 18 17:18:15 2016 +0700

----------------------------------------------------------------------
 mailet/standard/pom.xml                         |  10 ++
 .../transport/matchers/RelayLimitTest.java      | 115 +++++++++++++++++++
 2 files changed, 125 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/be1be8b9/mailet/standard/pom.xml
----------------------------------------------------------------------
diff --git a/mailet/standard/pom.xml b/mailet/standard/pom.xml
index fba213d..3b6adf8 100644
--- a/mailet/standard/pom.xml
+++ b/mailet/standard/pom.xml
@@ -67,6 +67,16 @@
             <groupId>commons-io</groupId>
             <artifactId>commons-io</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>

http://git-wip-us.apache.org/repos/asf/james-project/blob/be1be8b9/mailet/standard/src/test/java/org/apache/james/transport/matchers/RelayLimitTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/RelayLimitTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/RelayLimitTest.java
new file mode 100644
index 0000000..58e2701
--- /dev/null
+++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/RelayLimitTest.java
@@ -0,0 +1,115 @@
+/****************************************************************
+ * 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.transport.matchers;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Properties;
+
+import javax.mail.MessagingException;
+import javax.mail.Session;
+import javax.mail.internet.MimeMessage;
+
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+import org.apache.mailet.base.RFC2822Headers;
+import org.apache.mailet.base.test.FakeMail;
+import org.apache.mailet.base.test.FakeMailContext;
+import org.apache.mailet.base.test.FakeMatcherConfig;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+
+public class RelayLimitTest {
+
+    private RelayLimit testee;
+    private MailAddress mailAddress;
+    private Mail mail;
+    private MimeMessage mimeMessage;
+
+    @Before
+    public void setUp() throws Exception {
+        testee = new RelayLimit();
+        mailAddress = new MailAddress("mail@domain.com");
+        mail = new FakeMail();
+        mail.setRecipients(ImmutableList.of(mailAddress));
+        mimeMessage = new MimeMessage(Session.getDefaultInstance(new Properties()));
+        mail.setMessage(mimeMessage);
+    }
+
+    @Test(expected = MessagingException.class)
+    public void relayLimitShouldBeANumber() throws Exception {
+        testee.init(new FakeMatcherConfig("RelayLimit=Abc", new FakeMailContext()));
+    }
+
+    @Test(expected = MessagingException.class)
+    public void relayLimitShouldBeSpecified() throws Exception {
+        testee.init(new FakeMatcherConfig("RelayLimit=", new FakeMailContext()));
+    }
+
+    @Test(expected = MessagingException.class)
+    public void relayLimitShouldNotBeNull() throws Exception {
+        testee.init(new FakeMatcherConfig("RelayLimit=0", new FakeMailContext()));
+    }
+
+    @Test(expected = MessagingException.class)
+    public void relayLimitShouldNotBeEqualToZero() throws Exception {
+        testee.init(new FakeMatcherConfig("RelayLimit=-1", new FakeMailContext()));
+    }
+
+    @Test
+    public void matchShouldReturnNullWhenNoReceivedHeader() throws Exception {
+        testee.init(new FakeMatcherConfig("RelayLimit=2", new FakeMailContext()));
+
+        assertThat(testee.match(mail)).isNull();
+    }
+
+    @Test
+    public void matchShouldReturnNullWhenNotEnoughReceivedHeader() throws Exception {
+        testee.init(new FakeMatcherConfig("RelayLimit=2", new FakeMailContext()));
+
+        mimeMessage.addHeader(RFC2822Headers.RECEIVED, "any");
+
+        assertThat(testee.match(mail)).isNull();
+    }
+
+    @Test
+    public void matchShouldReturnAddressWhenEqualToLimit() throws Exception {
+        testee.init(new FakeMatcherConfig("RelayLimit=2", new FakeMailContext()));
+
+        mimeMessage.addHeader(RFC2822Headers.RECEIVED, "any");
+        mimeMessage.addHeader(RFC2822Headers.RECEIVED, "any");
+
+        assertThat(testee.match(mail)).containsExactly(mailAddress);
+    }
+
+    @Test
+    public void matchShouldReturnAddressWhenOverLimit() throws Exception {
+        testee.init(new FakeMatcherConfig("RelayLimit=2", new FakeMailContext()));
+
+        mimeMessage.addHeader(RFC2822Headers.RECEIVED, "any");
+        mimeMessage.addHeader(RFC2822Headers.RECEIVED, "any");
+        mimeMessage.addHeader(RFC2822Headers.RECEIVED, "any");
+
+        assertThat(testee.match(mail)).containsExactly(mailAddress);
+    }
+
+}


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


[06/10] james-project git commit: JAMES-1773 Add tests for RecipientIsLocal

Posted by bt...@apache.org.
JAMES-1773 Add tests for RecipientIsLocal


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

Branch: refs/heads/master
Commit: adee0b59d593410390205b429aad6fcf90a7dbda
Parents: 992ab01
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Aug 10 10:20:54 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Aug 18 17:18:15 2016 +0700

----------------------------------------------------------------------
 mailet/standard/pom.xml                         |  6 ++
 .../matchers/RecipientIsLocalTest.java          | 85 ++++++++++++++++++++
 2 files changed, 91 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/adee0b59/mailet/standard/pom.xml
----------------------------------------------------------------------
diff --git a/mailet/standard/pom.xml b/mailet/standard/pom.xml
index 3b6adf8..37f6ddc 100644
--- a/mailet/standard/pom.xml
+++ b/mailet/standard/pom.xml
@@ -77,6 +77,12 @@
             <artifactId>guava</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <scope>test</scope>
+            <version>1.9.5</version>
+        </dependency>
     </dependencies>
 
     <build>

http://git-wip-us.apache.org/repos/asf/james-project/blob/adee0b59/mailet/standard/src/test/java/org/apache/james/transport/matchers/RecipientIsLocalTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/RecipientIsLocalTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/RecipientIsLocalTest.java
new file mode 100644
index 0000000..1506e2e
--- /dev/null
+++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/RecipientIsLocalTest.java
@@ -0,0 +1,85 @@
+/****************************************************************
+ * 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.transport.matchers;
+
+import static  org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+import org.apache.mailet.MailetContext;
+import org.apache.mailet.base.test.FakeMail;
+import org.apache.mailet.base.test.FakeMatcherConfig;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+
+public class RecipientIsLocalTest {
+
+    public static final String MATCHER_NAME = "matcherName";
+    private RecipientIsLocal testee;
+    private MailetContext mailetContext;
+    private MailAddress mailAddress1;
+    private MailAddress mailAddress2;
+    private Mail mail;
+
+    @Before
+    public void setUp() throws Exception {
+        mailetContext = mock(MailetContext.class);
+        testee = new RecipientIsLocal();
+        testee.init(new FakeMatcherConfig(MATCHER_NAME, mailetContext));
+
+        mailAddress1 = new MailAddress("mail1@domain.com");
+        mailAddress2 = new MailAddress("mail2@domain.com");
+        mail = new FakeMail();
+        mail.setRecipients(ImmutableList.of(mailAddress1, mailAddress2));
+    }
+
+    @Test
+    public void matchShouldNotReturnNonExistingAddress() throws Exception {
+        when(mailetContext.isLocalEmail(mailAddress1)).thenReturn(false);
+        when(mailetContext.isLocalEmail(mailAddress2)).thenReturn(false);
+
+        assertThat(testee.match(mail)).isEmpty();
+    }
+
+    @Test
+    public void matchShouldNotReturnNonExistingAddressIfSomeRecipientsExists() throws Exception {
+        when(mailetContext.isLocalEmail(mailAddress1)).thenReturn(true);
+        when(mailetContext.isLocalEmail(mailAddress2)).thenReturn(false);
+
+        assertThat(testee.match(mail)).containsOnly(mailAddress1);
+    }
+
+    @Test
+    public void matchShouldHandleTwoValidAddress() throws Exception {
+        when(mailetContext.isLocalEmail(mailAddress1)).thenReturn(true);
+        when(mailetContext.isLocalEmail(mailAddress2)).thenReturn(true);
+
+        assertThat(testee.match(mail)).containsOnly(mailAddress1, mailAddress2);
+    }
+
+    @Test
+    public void matchShouldNotMatchMailWithNoRecipient() throws Exception {
+        assertThat(testee.match(new FakeMail())).isEmpty();
+    }
+}


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


[08/10] james-project git commit: JAMES-1773 Fix typo in RecipientIsLocal configuration

Posted by bt...@apache.org.
JAMES-1773 Fix typo in RecipientIsLocal configuration


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

Branch: refs/heads/master
Commit: 932acf53a76a2144b1c85b15dd21ea413c2f2094
Parents: adee0b5
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Aug 10 10:26:03 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Aug 18 17:18:15 2016 +0700

----------------------------------------------------------------------
 server/src/site/xdoc/dev-provided-matchers.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/932acf53/server/src/site/xdoc/dev-provided-matchers.xml
----------------------------------------------------------------------
diff --git a/server/src/site/xdoc/dev-provided-matchers.xml b/server/src/site/xdoc/dev-provided-matchers.xml
index 7b0d749..0752002 100644
--- a/server/src/site/xdoc/dev-provided-matchers.xml
+++ b/server/src/site/xdoc/dev-provided-matchers.xml
@@ -217,7 +217,7 @@
             </subsection>
 
             <subsection name="RecipientIsLocal">
-                <p>Description: Matches mails that are sent to email addresses on local hosts with users that have local acccunts.  Only
+                <p>Description: Matches mails that are sent to email addresses on local hosts with users that have local accounts.  Only
                     matching recipients are returned.</p>
                 <p>Configuration string: None.</p>
             </subsection>


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


[02/10] james-project git commit: JAMES-1773 Complete HasHeaderTest

Posted by bt...@apache.org.
JAMES-1773 Complete HasHeaderTest

What was not tested ?

 - multi-conditions
 - header present multiples times (buggy)
 - header with value specified


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

Branch: refs/heads/master
Commit: 1b9a1075d9baf5aea358eb40858c27118e571c3a
Parents: c94a99f
Author: Benoit Tellier <bt...@linagora.com>
Authored: Tue Aug 9 11:46:14 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Aug 18 17:18:15 2016 +0700

----------------------------------------------------------------------
 .../james/transport/matchers/HasHeaderTest.java | 80 ++++++++++++++++++++
 1 file changed, 80 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/1b9a1075/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderTest.java
index 6b40cec..ca7ed5d 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasHeaderTest.java
@@ -22,9 +22,13 @@ package org.apache.james.transport.matchers;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
+import java.util.Properties;
+
 import javax.mail.MessagingException;
+import javax.mail.Session;
 import javax.mail.internet.MimeMessage;
 
+import org.apache.mailet.Mail;
 import org.apache.mailet.Matcher;
 import org.apache.mailet.base.test.FakeMail;
 import org.apache.mailet.base.test.FakeMailContext;
@@ -38,6 +42,7 @@ public class HasHeaderTest {
     private static final String HEADER_NAME_1 = "JUNIT";
     private static final String HEADER_NAME_2 = "defaultHeaderName";
     private static final String HEADER_VALUE_1 = "defaultHeaderValue";
+    private static final String HEADER_VALUE_2 = "defaultHeaderValue2";
 
     private FakeMail mockedMail;
     private Matcher matcher;
@@ -62,4 +67,79 @@ public class HasHeaderTest {
 
         assertThat(matcher.match(mockedMail)).isNull();
     }
+
+    @Test
+    public void matchShouldReturnAddressesWhenGoodHeaderNameAndValue() throws MessagingException {
+        matcher.init(new FakeMatcherConfig("HasHeader=" + HEADER_NAME_1 + "=" + HEADER_VALUE_1, new FakeMailContext()));
+
+        assertThat(matcher.match(mockedMail)).containsAll(mockedMail.getRecipients());
+    }
+
+    @Test
+    public void matchShouldReturnNullWhenWrongValue() throws MessagingException {
+        matcher.init(new FakeMatcherConfig("HasHeader=" + HEADER_NAME_1 + "=" + HEADER_VALUE_2, new FakeMailContext()));
+
+        assertThat(matcher.match(mockedMail)).isNull();
+    }
+
+    @Test
+    public void matchShouldReturnNullWhenWrongHeaderNameWithValueSpecified() throws MessagingException {
+        matcher.init(new FakeMatcherConfig("HasHeader=" + HEADER_NAME_2 + "=" + HEADER_VALUE_2, new FakeMailContext()));
+
+        assertThat(matcher.match(mockedMail)).isNull();
+    }
+
+    @Test
+    public void matchShouldIgnoreExtraEquals() throws MessagingException {
+        matcher.init(new FakeMatcherConfig("HasHeader=" + HEADER_NAME_1 + "=" + HEADER_VALUE_1 + "=any", new FakeMailContext()));
+
+        assertThat(matcher.match(mockedMail)).containsAll(mockedMail.getRecipients());
+    }
+
+    @Test
+    public void matchShouldNotMatchMailsWithNoHeaderWhenValueSpecified() throws MessagingException {
+        matcher.init(new FakeMatcherConfig("HasHeader=" + HEADER_NAME_1 + "=" + HEADER_VALUE_1, new FakeMailContext()));
+        Mail mail = MailUtil.createMockMail2Recipients(MailUtil.createMimeMessage());
+
+        assertThat(matcher.match(mail)).isNull();
+    }
+
+    @Test
+    public void matchShouldNotMatchMailsWithNoHeaderWhenValueNotSpecified() throws MessagingException {
+        matcher.init(new FakeMatcherConfig("HasHeader=" + HEADER_NAME_1, new FakeMailContext()));
+        Mail mail = MailUtil.createMockMail2Recipients(MailUtil.createMimeMessage());
+
+        assertThat(matcher.match(mail)).isNull();
+    }
+
+    @Test
+    public void matchShouldReturnNullWhenOneConditionIsNotTrue() throws MessagingException {
+        matcher.init(new FakeMatcherConfig("HasHeader=" + HEADER_NAME_1 + "+" + HEADER_NAME_2, new FakeMailContext()));
+
+        assertThat(matcher.match(mockedMail)).isNull();
+    }
+
+    @Test
+    public void matchShouldReturnAddressesWhenAllConditionsMatch() throws MessagingException {
+        matcher.init(new FakeMatcherConfig("HasHeader=" + HEADER_NAME_1 + "+" + HEADER_NAME_2, new FakeMailContext()));
+        MimeMessage mimeMessage = new MimeMessage(Session.getDefaultInstance(new Properties()));
+        mimeMessage.addHeader(HEADER_NAME_1, HEADER_VALUE_1);
+        mimeMessage.addHeader(HEADER_NAME_2, HEADER_VALUE_2);
+        mimeMessage.saveChanges();
+        Mail mail = MailUtil.createMockMail2Recipients(mimeMessage);
+
+        assertThat(matcher.match(mail)).containsAll(mockedMail.getRecipients());
+    }
+
+    @Test
+    public void matchShouldFindTheRightHeaderLineWhenUsedWithValue() throws MessagingException {
+        matcher.init(new FakeMatcherConfig("HasHeader=" + HEADER_NAME_1 + "=" + HEADER_VALUE_2, new FakeMailContext()));
+        MimeMessage mimeMessage = new MimeMessage(Session.getDefaultInstance(new Properties()));
+        mimeMessage.addHeader(HEADER_NAME_1, HEADER_VALUE_1);
+        mimeMessage.addHeader(HEADER_NAME_1, HEADER_VALUE_2);
+        mimeMessage.saveChanges();
+        Mail mail = MailUtil.createMockMail2Recipients(mimeMessage);
+
+        assertThat(matcher.match(mail)).containsAll(mockedMail.getRecipients());
+    }
 }


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