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/12/11 07:01:20 UTC

[1/7] james-project git commit: JAMES-2557 DataCmdHandler line breaks

Repository: james-project
Updated Branches:
  refs/heads/master d700a9718 -> 5b46ce3c1


JAMES-2557 DataCmdHandler line breaks


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

Branch: refs/heads/master
Commit: 5b673a097c30e98dd3db85fb687dd64b01177c8d
Parents: d700a97
Author: Benoit Tellier <bt...@linagora.com>
Authored: Thu Dec 6 11:29:28 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Dec 11 13:58:41 2018 +0700

----------------------------------------------------------------------
 .../protocols/smtp/core/DataCmdHandler.java     | 468 +++++++++----------
 1 file changed, 234 insertions(+), 234 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/5b673a09/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/DataCmdHandler.java
----------------------------------------------------------------------
diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/DataCmdHandler.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/DataCmdHandler.java
index 906da01..00f1128 100644
--- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/DataCmdHandler.java
+++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/DataCmdHandler.java
@@ -1,234 +1,234 @@
-/****************************************************************
- * 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.protocols.smtp.core;
-
-import java.io.Closeable;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.List;
-
-import javax.inject.Inject;
-
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.james.core.MailAddress;
-import org.apache.james.core.MaybeSender;
-import org.apache.james.metrics.api.MetricFactory;
-import org.apache.james.metrics.api.TimeMetric;
-import org.apache.james.protocols.api.ProtocolSession;
-import org.apache.james.protocols.api.Request;
-import org.apache.james.protocols.api.Response;
-import org.apache.james.protocols.api.handler.CommandHandler;
-import org.apache.james.protocols.api.handler.ExtensibleHandler;
-import org.apache.james.protocols.api.handler.LineHandler;
-import org.apache.james.protocols.api.handler.WiringException;
-import org.apache.james.protocols.smtp.MailEnvelope;
-import org.apache.james.protocols.smtp.MailEnvelopeImpl;
-import org.apache.james.protocols.smtp.SMTPResponse;
-import org.apache.james.protocols.smtp.SMTPRetCode;
-import org.apache.james.protocols.smtp.SMTPSession;
-import org.apache.james.protocols.smtp.dsn.DSNStatus;
-import org.apache.james.util.MDCBuilder;
-
-import com.google.common.collect.ImmutableSet;
-
-
-/**
-  * handles DATA command
- */
-public class DataCmdHandler implements CommandHandler<SMTPSession>, ExtensibleHandler {
-
-    private static final Response NO_RECIPIENT = new SMTPResponse(SMTPRetCode.BAD_SEQUENCE, DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_OTHER) + " No recipients specified").immutable();
-    private static final Response NO_SENDER = new SMTPResponse(SMTPRetCode.BAD_SEQUENCE, DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_OTHER) + " No sender specified").immutable();
-    private static final Response UNEXPECTED_ARG = new SMTPResponse(SMTPRetCode.SYNTAX_ERROR_COMMAND_UNRECOGNIZED, DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_INVALID_ARG) + " Unexpected argument provided with DATA command").immutable();
-    private static final Response DATA_READY = new SMTPResponse(SMTPRetCode.DATA_READY, "Ok Send data ending with <CRLF>.<CRLF>").immutable();
-    private static final Collection<String> COMMANDS = ImmutableSet.of("DATA");
-
-    public static final class DataConsumerLineHandler implements LineHandler<SMTPSession> {
-
-        @Override
-        public SMTPResponse onLine(SMTPSession session, ByteBuffer line) {
-            // Discard everything until the end of DATA session
-            if (line.remaining() == 3 && line.get() == 46) {
-                session.popLineHandler();
-            }
-            return null;
-        }
-
-        @Override
-        public void init(Configuration config) throws ConfigurationException {
-
-        }
-
-        @Override
-        public void destroy() {
-
-        }
-    }
-
-    public static final class DataLineFilterWrapper implements LineHandler<SMTPSession> {
-
-        private final DataLineFilter filter;
-        private final LineHandler<SMTPSession> next;
-        
-        public DataLineFilterWrapper(DataLineFilter filter, LineHandler<SMTPSession> next) {
-            this.filter = filter;
-            this.next = next;
-        }
-
-        @Override
-        public Response onLine(SMTPSession session, ByteBuffer line) {
-            line.rewind();
-            return filter.onLine(session, line, next);
-        }
-
-        @Override
-        public void init(Configuration config) throws ConfigurationException {
-
-        }
-
-        @Override
-        public void destroy() {
-
-        }
-    }
-   
-    public static final String MAILENV = "MAILENV";
-
-    private final MetricFactory metricFactory;
-
-    @Inject
-    public DataCmdHandler(MetricFactory metricFactory) {
-        this.metricFactory = metricFactory;
-    }
-
-    private LineHandler<SMTPSession> lineHandler;
-
-    @Override
-    public void init(Configuration config) throws ConfigurationException {
-
-    }
-
-    @Override
-    public void destroy() {
-
-    }
-
-    /**
-     * process DATA command
-     *
-     */
-    @Override
-    public Response onCommand(SMTPSession session, Request request) {
-        TimeMetric timeMetric = metricFactory.timer("SMTP-" + request.getCommand());
-        session.stopDetectingCommandInjection();
-        try (Closeable closeable =
-                 MDCBuilder.create()
-                     .addContext(MDCBuilder.ACTION, request.getCommand())
-                     .build()) {
-            String parameters = request.getArgument();
-            Response response = doDATAFilter(session, parameters);
-
-            if (response == null) {
-                return doDATA(session, parameters);
-            } else {
-                return response;
-            }
-        } catch (IOException e) {
-            throw new RuntimeException(e);
-        } finally {
-            timeMetric.stopAndPublish();
-            session.needsCommandInjectionDetection();
-        }
-    }
-
-
-    /**
-     * Handler method called upon receipt of a DATA command.
-     * Reads in message data, creates header, and delivers to
-     * mail server service for delivery.
-     *
-     * @param session SMTP session object
-     * @param argument the argument passed in with the command by the SMTP client
-     */
-    @SuppressWarnings("unchecked")
-    protected Response doDATA(SMTPSession session, String argument) {
-        MailAddress sender = (MailAddress) session.getAttachment(SMTPSession.SENDER, ProtocolSession.State.Transaction);
-        MailEnvelope env = createEnvelope(session, MaybeSender.of(sender), new ArrayList<>((Collection<MailAddress>) session.getAttachment(SMTPSession.RCPT_LIST, ProtocolSession.State.Transaction)));
-        session.setAttachment(MAILENV, env,ProtocolSession.State.Transaction);
-        session.pushLineHandler(lineHandler);
-        
-        return DATA_READY;
-    }
-    
-    protected MailEnvelope createEnvelope(SMTPSession session, MaybeSender sender, List<MailAddress> recipients) {
-        MailEnvelopeImpl env = new MailEnvelopeImpl();
-        env.setRecipients(recipients);
-        env.setSender(sender);
-        return env;
-    }
-    
-    @Override
-    public Collection<String> getImplCommands() {
-        return COMMANDS;
-    }
-
-    @Override
-    @SuppressWarnings({ "unchecked", "rawtypes" })
-    public List getMarkerInterfaces() {
-        List classes = new LinkedList();
-        classes.add(DataLineFilter.class);
-        return classes;
-    }
-
-
-    @Override
-    @SuppressWarnings("rawtypes")
-    public void wireExtensions(Class interfaceName, List extension) throws WiringException {
-        if (DataLineFilter.class.equals(interfaceName)) {
-
-            LineHandler<SMTPSession> lineHandler = new DataConsumerLineHandler();
-            for (int i = extension.size() - 1; i >= 0; i--) {
-                lineHandler = new DataLineFilterWrapper((DataLineFilter) extension.get(i), lineHandler);
-            }
-
-            this.lineHandler = lineHandler;
-        }
-    }
-
-    protected Response doDATAFilter(SMTPSession session, String argument) {
-        if ((argument != null) && (argument.length() > 0)) {
-            return UNEXPECTED_ARG;
-        }
-        if (session.getAttachment(SMTPSession.SENDER, ProtocolSession.State.Transaction) == null) {
-            return NO_SENDER;
-        } else if (session.getAttachment(SMTPSession.RCPT_LIST, ProtocolSession.State.Transaction) == null) {
-            return NO_RECIPIENT;
-        }
-        return null;
-    }
-
-    protected LineHandler<SMTPSession> getLineHandler() {
-        return lineHandler;
-    }
-
-}
+/****************************************************************
+ * 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.protocols.smtp.core;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.james.core.MailAddress;
+import org.apache.james.core.MaybeSender;
+import org.apache.james.metrics.api.MetricFactory;
+import org.apache.james.metrics.api.TimeMetric;
+import org.apache.james.protocols.api.ProtocolSession;
+import org.apache.james.protocols.api.Request;
+import org.apache.james.protocols.api.Response;
+import org.apache.james.protocols.api.handler.CommandHandler;
+import org.apache.james.protocols.api.handler.ExtensibleHandler;
+import org.apache.james.protocols.api.handler.LineHandler;
+import org.apache.james.protocols.api.handler.WiringException;
+import org.apache.james.protocols.smtp.MailEnvelope;
+import org.apache.james.protocols.smtp.MailEnvelopeImpl;
+import org.apache.james.protocols.smtp.SMTPResponse;
+import org.apache.james.protocols.smtp.SMTPRetCode;
+import org.apache.james.protocols.smtp.SMTPSession;
+import org.apache.james.protocols.smtp.dsn.DSNStatus;
+import org.apache.james.util.MDCBuilder;
+
+import com.google.common.collect.ImmutableSet;
+
+
+/**
+ * handles DATA command
+ */
+public class DataCmdHandler implements CommandHandler<SMTPSession>, ExtensibleHandler {
+
+    private static final Response NO_RECIPIENT = new SMTPResponse(SMTPRetCode.BAD_SEQUENCE, DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_OTHER) + " No recipients specified").immutable();
+    private static final Response NO_SENDER = new SMTPResponse(SMTPRetCode.BAD_SEQUENCE, DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_OTHER) + " No sender specified").immutable();
+    private static final Response UNEXPECTED_ARG = new SMTPResponse(SMTPRetCode.SYNTAX_ERROR_COMMAND_UNRECOGNIZED, DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_INVALID_ARG) + " Unexpected argument provided with DATA command").immutable();
+    private static final Response DATA_READY = new SMTPResponse(SMTPRetCode.DATA_READY, "Ok Send data ending with <CRLF>.<CRLF>").immutable();
+    private static final Collection<String> COMMANDS = ImmutableSet.of("DATA");
+
+    public static final class DataConsumerLineHandler implements LineHandler<SMTPSession> {
+
+        @Override
+        public SMTPResponse onLine(SMTPSession session, ByteBuffer line) {
+            // Discard everything until the end of DATA session
+            if (line.remaining() == 3 && line.get() == 46) {
+                session.popLineHandler();
+            }
+            return null;
+        }
+
+        @Override
+        public void init(Configuration config) throws ConfigurationException {
+
+        }
+
+        @Override
+        public void destroy() {
+
+        }
+    }
+
+    public static final class DataLineFilterWrapper implements LineHandler<SMTPSession> {
+
+        private final DataLineFilter filter;
+        private final LineHandler<SMTPSession> next;
+        
+        public DataLineFilterWrapper(DataLineFilter filter, LineHandler<SMTPSession> next) {
+            this.filter = filter;
+            this.next = next;
+        }
+
+        @Override
+        public Response onLine(SMTPSession session, ByteBuffer line) {
+            line.rewind();
+            return filter.onLine(session, line, next);
+        }
+
+        @Override
+        public void init(Configuration config) throws ConfigurationException {
+
+        }
+
+        @Override
+        public void destroy() {
+
+        }
+    }
+   
+    public static final String MAILENV = "MAILENV";
+
+    private final MetricFactory metricFactory;
+
+    @Inject
+    public DataCmdHandler(MetricFactory metricFactory) {
+        this.metricFactory = metricFactory;
+    }
+
+    private LineHandler<SMTPSession> lineHandler;
+
+    @Override
+    public void init(Configuration config) throws ConfigurationException {
+
+    }
+
+    @Override
+    public void destroy() {
+
+    }
+
+    /**
+     * process DATA command
+     *
+     */
+    @Override
+    public Response onCommand(SMTPSession session, Request request) {
+        TimeMetric timeMetric = metricFactory.timer("SMTP-" + request.getCommand());
+        session.stopDetectingCommandInjection();
+        try (Closeable closeable =
+                 MDCBuilder.create()
+                     .addContext(MDCBuilder.ACTION, request.getCommand())
+                     .build()) {
+            String parameters = request.getArgument();
+            Response response = doDATAFilter(session, parameters);
+
+            if (response == null) {
+                return doDATA(session, parameters);
+            } else {
+                return response;
+            }
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        } finally {
+            timeMetric.stopAndPublish();
+            session.needsCommandInjectionDetection();
+        }
+    }
+
+
+    /**
+     * Handler method called upon receipt of a DATA command.
+     * Reads in message data, creates header, and delivers to
+     * mail server service for delivery.
+     *
+     * @param session SMTP session object
+     * @param argument the argument passed in with the command by the SMTP client
+     */
+    @SuppressWarnings("unchecked")
+    protected Response doDATA(SMTPSession session, String argument) {
+        MailAddress sender = (MailAddress) session.getAttachment(SMTPSession.SENDER, ProtocolSession.State.Transaction);
+        MailEnvelope env = createEnvelope(session, MaybeSender.of(sender), new ArrayList<>((Collection<MailAddress>) session.getAttachment(SMTPSession.RCPT_LIST, ProtocolSession.State.Transaction)));
+        session.setAttachment(MAILENV, env,ProtocolSession.State.Transaction);
+        session.pushLineHandler(lineHandler);
+        
+        return DATA_READY;
+    }
+    
+    protected MailEnvelope createEnvelope(SMTPSession session, MaybeSender sender, List<MailAddress> recipients) {
+        MailEnvelopeImpl env = new MailEnvelopeImpl();
+        env.setRecipients(recipients);
+        env.setSender(sender);
+        return env;
+    }
+    
+    @Override
+    public Collection<String> getImplCommands() {
+        return COMMANDS;
+    }
+
+    @Override
+    @SuppressWarnings({ "unchecked", "rawtypes" })
+    public List getMarkerInterfaces() {
+        List classes = new LinkedList();
+        classes.add(DataLineFilter.class);
+        return classes;
+    }
+
+
+    @Override
+    @SuppressWarnings("rawtypes")
+    public void wireExtensions(Class interfaceName, List extension) throws WiringException {
+        if (DataLineFilter.class.equals(interfaceName)) {
+
+            LineHandler<SMTPSession> lineHandler = new DataConsumerLineHandler();
+            for (int i = extension.size() - 1; i >= 0; i--) {
+                lineHandler = new DataLineFilterWrapper((DataLineFilter) extension.get(i), lineHandler);
+            }
+
+            this.lineHandler = lineHandler;
+        }
+    }
+
+    protected Response doDATAFilter(SMTPSession session, String argument) {
+        if ((argument != null) && (argument.length() > 0)) {
+            return UNEXPECTED_ARG;
+        }
+        if (session.getAttachment(SMTPSession.SENDER, ProtocolSession.State.Transaction) == null) {
+            return NO_SENDER;
+        } else if (session.getAttachment(SMTPSession.RCPT_LIST, ProtocolSession.State.Transaction) == null) {
+            return NO_RECIPIENT;
+        }
+        return null;
+    }
+
+    protected LineHandler<SMTPSession> getLineHandler() {
+        return lineHandler;
+    }
+
+}


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


[4/7] james-project git commit: JAMES-2557 Improve MailCmdHandle MaybeSender computation

Posted by bt...@apache.org.
JAMES-2557 Improve MailCmdHandle MaybeSender computation

Avoid variable re-affectation and further use method extraction.


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

Branch: refs/heads/master
Commit: 7a6d572ea69223c6dae43cc625c76006c7c868fc
Parents: 0bdffec
Author: Benoit Tellier <bt...@linagora.com>
Authored: Fri Dec 7 09:29:06 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Dec 11 13:59:20 2018 +0700

----------------------------------------------------------------------
 .../protocols/smtp/core/MailCmdHandler.java     | 66 ++++++++++----------
 1 file changed, 32 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/7a6d572e/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/MailCmdHandler.java
----------------------------------------------------------------------
diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/MailCmdHandler.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/MailCmdHandler.java
index 4ba8374..9bce885 100644
--- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/MailCmdHandler.java
+++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/MailCmdHandler.java
@@ -27,6 +27,7 @@ import java.util.Map;
 import java.util.StringTokenizer;
 
 import javax.inject.Inject;
+import javax.mail.internet.AddressException;
 
 import org.apache.commons.configuration.Configuration;
 import org.apache.commons.configuration.ConfigurationException;
@@ -213,47 +214,44 @@ public class MailCmdHandler extends AbstractHookableCmdHandler<MailHook> {
                 LOGGER.info("Error parsing sender address: {}: did not start and end with < >", sender);
                 return SYNTAX_ERROR;
             }
-            MaybeSender senderAddress = MaybeSender.nullSender();
-
-            if (session.getConfiguration().useAddressBracketsEnforcement()
-                    || (sender.startsWith("<") && sender.endsWith(">"))) {
-                // Remove < and >
-                sender = sender.substring(1, sender.length() - 1);
+            try {
+                MaybeSender senderAddress = toMaybeSender(removeBrackets(session, sender));
+                // Store the senderAddress in session map
+                session.setAttachment(SMTPSession.SENDER, senderAddress, State.Transaction);
+            } catch (Exception pe) {
+                LOGGER.info("Error parsing sender address: {}", sender, pe);
+                return SYNTAX_ERROR_ADDRESS;
             }
+        }
+        return null;
+    }
 
-            if (sender.length() == 0) {
-                // This is the <> case. Let senderAddress == MaybeSender.nullSender()
-            } else {
-
-                if (!sender.contains("@")) {
-                    sender = sender
-                            + "@"
-                            + getDefaultDomain();
-                }
+    private MaybeSender toMaybeSender(String senderAsString) throws AddressException {
+        if (senderAsString.length() == 0) {
+            // This is the <> case.
+            return MaybeSender.nullSender();
+        }
+        if (senderAsString.equals("@")) {
+            return MaybeSender.nullSender();
+        }
+        return MaybeSender.of(new MailAddress(
+            appendDefaultDomainIfNeeded(senderAsString)));
+    }
 
-                try {
-                    senderAddress = MaybeSender.of(new MailAddress(sender));
-                } catch (Exception pe) {
-                    LOGGER.info("Error parsing sender address: {}", sender, pe);
-                    return SYNTAX_ERROR_ADDRESS;
-                }
-            }
-            if (isNullSender(senderAddress)) {
-                senderAddress = MaybeSender.nullSender();
-            }
-            // Store the senderAddress in session map
-            session.setAttachment(SMTPSession.SENDER, senderAddress, State.Transaction);
+    private String removeBrackets(SMTPSession session, String input) {
+        if (session.getConfiguration().useAddressBracketsEnforcement()
+            || (input.startsWith("<") && input.endsWith(">"))) {
+            // Remove < and >
+            return input.substring(1, input.length() - 1);
         }
-        return null;
+        return input;
     }
 
-    private boolean isNullSender(MaybeSender senderAddress) {
-        if (senderAddress.isNullSender()) {
-            return true;
+    private String appendDefaultDomainIfNeeded(String address) {
+        if (!address.contains("@")) {
+            return address + "@" + getDefaultDomain();
         }
-        boolean hasEmptyLocalPart = senderAddress.get().getLocalPart().length() == 0;
-        boolean hasEmptyDomainPart = senderAddress.get().getDomain().name().length() == 0;
-        return hasEmptyLocalPart && hasEmptyDomainPart;
+        return address;
     }
 
     @Override


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


[6/7] james-project git commit: JAMES-2456 Deprecate MailAddress::isNullSender

Posted by bt...@apache.org.
JAMES-2456 Deprecate MailAddress::isNullSender


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

Branch: refs/heads/master
Commit: 2fe4760da2fd48f5c406170401879ec0582ae533
Parents: 3ae94d0
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Oct 24 11:08:42 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Dec 11 14:00:08 2018 +0700

----------------------------------------------------------------------
 core/src/main/java/org/apache/james/core/MailAddress.java | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/2fe4760d/core/src/main/java/org/apache/james/core/MailAddress.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/james/core/MailAddress.java b/core/src/main/java/org/apache/james/core/MailAddress.java
index 78db46c..d31a26d 100644
--- a/core/src/main/java/org/apache/james/core/MailAddress.java
+++ b/core/src/main/java/org/apache/james/core/MailAddress.java
@@ -374,6 +374,7 @@ public class MailAddress implements java.io.Serializable {
      * @returns true if the given object is equal to this one, false otherwise
      */
     @Override
+    @SuppressWarnings("deprecated")
     public final boolean equals(Object obj) {
         if (obj == null) {
             return false;
@@ -666,8 +667,9 @@ public class MailAddress implements java.io.Serializable {
     /**
      * Return <code>true</code> if the {@link MailAddress} should represent a null sender (<>)
      *
-     * @return nullsender
+     * @Deprecated You should use an Optional&lt;MailAddress&gt; representation of a MailAddress rather than relying on a NULL object
      */
+    @Deprecated
     public boolean isNullSender() {
         return false;
     }


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


[2/7] james-project git commit: JAMES-2557 Improve MailCmdHandler: Simplify removeBrackets condition

Posted by bt...@apache.org.
JAMES-2557 Improve MailCmdHandler: Simplify removeBrackets condition

If useAddressBracketsEnforcement is enforced, the brackets are checks to be present.

We can remove this redundant condition for simplicity.


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

Branch: refs/heads/master
Commit: cc795348eebf39fbcd81531cef25f34306ce0368
Parents: 7a6d572
Author: Benoit Tellier <bt...@linagora.com>
Authored: Fri Dec 7 09:30:54 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Dec 11 13:59:20 2018 +0700

----------------------------------------------------------------------
 .../org/apache/james/protocols/smtp/core/MailCmdHandler.java  | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/cc795348/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/MailCmdHandler.java
----------------------------------------------------------------------
diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/MailCmdHandler.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/MailCmdHandler.java
index 9bce885..6aab40c 100644
--- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/MailCmdHandler.java
+++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/MailCmdHandler.java
@@ -215,7 +215,7 @@ public class MailCmdHandler extends AbstractHookableCmdHandler<MailHook> {
                 return SYNTAX_ERROR;
             }
             try {
-                MaybeSender senderAddress = toMaybeSender(removeBrackets(session, sender));
+                MaybeSender senderAddress = toMaybeSender(removeBrackets(sender));
                 // Store the senderAddress in session map
                 session.setAttachment(SMTPSession.SENDER, senderAddress, State.Transaction);
             } catch (Exception pe) {
@@ -238,9 +238,8 @@ public class MailCmdHandler extends AbstractHookableCmdHandler<MailHook> {
             appendDefaultDomainIfNeeded(senderAsString)));
     }
 
-    private String removeBrackets(SMTPSession session, String input) {
-        if (session.getConfiguration().useAddressBracketsEnforcement()
-            || (input.startsWith("<") && input.endsWith(">"))) {
+    private String removeBrackets(String input) {
+        if (input.startsWith("<") && input.endsWith(">")) {
             // Remove < and >
             return input.substring(1, input.length() - 1);
         }


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


[7/7] james-project git commit: JAMES-2557 Deprecate MailAddress::getSender

Posted by bt...@apache.org.
JAMES-2557 Deprecate MailAddress::getSender

This should rather be handled in MaybeSender


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

Branch: refs/heads/master
Commit: 5b46ce3c12235e6c0948779ca66cd3cb552dad99
Parents: 2fe4760
Author: Benoit Tellier <bt...@linagora.com>
Authored: Thu Dec 6 11:46:57 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Dec 11 14:00:08 2018 +0700

----------------------------------------------------------------------
 .../java/org/apache/james/core/MailAddress.java |  4 ++
 .../java/org/apache/james/core/MaybeSender.java | 23 ++++++++++
 .../org/apache/james/core/MaybeSenderTest.java  | 48 ++++++++++++++++++++
 .../CassandraMailRepositoryMailDAO.java         |  7 +--
 .../apache/james/queue/jms/JMSMailQueue.java    |  4 +-
 .../james/queue/rabbitmq/MailReferenceDTO.java  |  3 +-
 6 files changed, 84 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/5b46ce3c/core/src/main/java/org/apache/james/core/MailAddress.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/james/core/MailAddress.java b/core/src/main/java/org/apache/james/core/MailAddress.java
index d31a26d..c9ab6e0 100644
--- a/core/src/main/java/org/apache/james/core/MailAddress.java
+++ b/core/src/main/java/org/apache/james/core/MailAddress.java
@@ -113,6 +113,10 @@ public class MailAddress implements java.io.Serializable {
         return NULL_SENDER;
     }
 
+    /**
+     * Prefer using {@link MaybeSender#getMailSender(String)}
+     */
+    @Deprecated
     public static  MailAddress getMailSender(String sender) {
         if (sender == null || sender.trim().length() <= 0) {
             return null;

http://git-wip-us.apache.org/repos/asf/james-project/blob/5b46ce3c/core/src/main/java/org/apache/james/core/MaybeSender.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/james/core/MaybeSender.java b/core/src/main/java/org/apache/james/core/MaybeSender.java
index 6e91fce..cdd4474 100644
--- a/core/src/main/java/org/apache/james/core/MaybeSender.java
+++ b/core/src/main/java/org/apache/james/core/MaybeSender.java
@@ -24,10 +24,33 @@ import java.util.Objects;
 import java.util.Optional;
 import java.util.stream.Stream;
 
+import javax.mail.internet.AddressException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import com.google.common.base.MoreObjects;
 import com.google.common.collect.ImmutableList;
 
 public class MaybeSender {
+    private static final Logger LOGGER = LoggerFactory.getLogger(MaybeSender.class);
+
+    public static MaybeSender getMailSender(String sender) {
+        if (sender == null || sender.trim().isEmpty()) {
+            return MaybeSender.nullSender();
+        }
+        if (sender.equals(MailAddress.NULL_SENDER_AS_STRING)) {
+            return MaybeSender.nullSender();
+        }
+        try {
+            return MaybeSender.of(new MailAddress(sender));
+        } catch (AddressException e) {
+            // Should never happen as long as the user does not modify the header by himself
+            LOGGER.warn("Unable to parse the sender address {}, so we fallback to a null sender", sender, e);
+            return MaybeSender.nullSender();
+        }
+    }
+
     public static MaybeSender nullSender() {
         return new MaybeSender(Optional.empty());
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/5b46ce3c/core/src/test/java/org/apache/james/core/MaybeSenderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/james/core/MaybeSenderTest.java b/core/src/test/java/org/apache/james/core/MaybeSenderTest.java
index 627aacd..6423835 100644
--- a/core/src/test/java/org/apache/james/core/MaybeSenderTest.java
+++ b/core/src/test/java/org/apache/james/core/MaybeSenderTest.java
@@ -32,6 +32,7 @@ import org.junit.jupiter.api.Test;
 import nl.jqno.equalsverifier.EqualsVerifier;
 
 class MaybeSenderTest {
+    private static final String GOOD_ADDRESS = "server-dev@james.apache.org";
     private static final String MAIL_ADDRESS_STRING = "any@domain.tld";
 
     private MailAddress mailAddress;
@@ -155,4 +156,51 @@ class MaybeSenderTest {
             .isEqualTo("default");
     }
 
+    @Test
+    void getMailSenderShouldReturnNullSenderWhenNullSender() {
+        assertThat(MaybeSender.getMailSender(MailAddress.NULL_SENDER_AS_STRING))
+            .isEqualTo(MaybeSender.nullSender());
+    }
+
+    @Test
+    void getMailSenderShouldReturnParsedAddressWhenNotNullAddress() throws Exception {
+        assertThat(MaybeSender.getMailSender(GOOD_ADDRESS))
+            .isEqualTo(MaybeSender.of(new MailAddress(GOOD_ADDRESS)));
+    }
+
+    @Test
+    void getMailSenderShouldReturnNullSenderWhenNull() {
+        assertThat(MaybeSender.getMailSender(null))
+            .isEqualTo(MaybeSender.nullSender());
+    }
+
+    @Test
+    void getMailSenderShouldReturnNullSenderWhenEmptyString() {
+        assertThat(MaybeSender.getMailSender(""))
+            .isEqualTo(MaybeSender.nullSender());
+    }
+
+    @Test
+    void getMailSenderShouldReturnNullSenderWhenOnlySpaces() {
+        assertThat(MaybeSender.getMailSender("   "))
+            .isEqualTo(MaybeSender.nullSender());
+    }
+
+    @Test
+    void getMailSenderShouldReturnNullSenderWhenBadValue() {
+        assertThat(MaybeSender.getMailSender("this@is@a@bad@address"))
+            .isEqualTo(MaybeSender.nullSender());
+    }
+
+    @Test
+    void equalsShouldReturnFalseWhenOnlyFirstMemberIsANullSender() {
+        assertThat(MaybeSender.getMailSender(GOOD_ADDRESS))
+            .isNotEqualTo(MaybeSender.nullSender());
+    }
+
+    @Test
+    void equalsShouldReturnFalseWhenOnlySecondMemberIsANullSender() {
+        assertThat(MaybeSender.nullSender())
+            .isNotEqualTo(MaybeSender.getMailSender(GOOD_ADDRESS));
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/5b46ce3c/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryMailDAO.java
----------------------------------------------------------------------
diff --git a/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryMailDAO.java b/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryMailDAO.java
index 5645a59..51bbe30 100644
--- a/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryMailDAO.java
+++ b/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryMailDAO.java
@@ -68,6 +68,7 @@ import org.apache.james.backends.cassandra.init.CassandraTypesProvider;
 import org.apache.james.backends.cassandra.utils.CassandraAsyncExecutor;
 import org.apache.james.blob.api.BlobId;
 import org.apache.james.core.MailAddress;
+import org.apache.james.core.MaybeSender;
 import org.apache.james.mailrepository.api.MailKey;
 import org.apache.james.mailrepository.api.MailRepositoryUrl;
 import org.apache.james.server.core.MailImpl;
@@ -171,9 +172,9 @@ public class CassandraMailRepositoryMailDAO {
     }
 
     private MailDTO toMail(Row row) {
-        MailAddress sender = Optional.ofNullable(row.getString(SENDER))
-            .map(MailAddress::getMailSender)
-            .orElse(null);
+        MaybeSender sender = Optional.ofNullable(row.getString(SENDER))
+            .map(MaybeSender::getMailSender)
+            .orElse(MaybeSender.nullSender());
         List<MailAddress> recipients = row.getList(RECIPIENTS, String.class)
             .stream()
             .map(Throwing.function(MailAddress::new))

http://git-wip-us.apache.org/repos/asf/james-project/blob/5b46ce3c/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueue.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueue.java b/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueue.java
index 0684d45..07b3128 100644
--- a/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueue.java
+++ b/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueue.java
@@ -51,6 +51,7 @@ import javax.mail.internet.MimeMessage;
 
 import org.apache.commons.collections.iterators.EnumerationIterator;
 import org.apache.james.core.MailAddress;
+import org.apache.james.core.MaybeSender;
 import org.apache.james.lifecycle.api.Disposable;
 import org.apache.james.metrics.api.Gauge;
 import org.apache.james.metrics.api.GaugeRegistry;
@@ -419,7 +420,8 @@ public class JMSMailQueue implements ManageableMailQueue, JMSSupport, MailPriori
         splitter.split(attributeNames)
                 .forEach(name -> setMailAttribute(message, mail, name));
 
-        mail.setSender(MailAddress.getMailSender(message.getStringProperty(JAMES_MAIL_SENDER)));
+        MaybeSender.getMailSender(message.getStringProperty(JAMES_MAIL_SENDER))
+            .asOptional().ifPresent(mail::setSender);
         mail.setState(message.getStringProperty(JAMES_MAIL_STATE));
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/5b46ce3c/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/MailReferenceDTO.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/MailReferenceDTO.java b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/MailReferenceDTO.java
index 306e7f9..80cadcb 100644
--- a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/MailReferenceDTO.java
+++ b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/MailReferenceDTO.java
@@ -34,6 +34,7 @@ import javax.mail.internet.MimeMessage;
 import org.apache.commons.lang3.tuple.Pair;
 import org.apache.james.blob.mail.MimeMessagePartsId;
 import org.apache.james.core.MailAddress;
+import org.apache.james.core.MaybeSender;
 import org.apache.james.server.core.MailImpl;
 import org.apache.mailet.Attribute;
 import org.apache.mailet.AttributeName;
@@ -190,7 +191,7 @@ class MailReferenceDTO {
 
     MailImpl toMailWithMimeMessage(MimeMessage mimeMessage) throws MessagingException {
         MailImpl mail = new MailImpl(name,
-            sender.map(MailAddress::getMailSender).orElse(null),
+            sender.map(MaybeSender::getMailSender).orElse(MaybeSender.nullSender()).asOptional().orElse(null),
             recipients.stream()
                 .map(Throwing.<String, MailAddress>function(MailAddress::new).sneakyThrow())
                 .collect(Guavate.toImmutableList()),


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


[3/7] james-project git commit: JAMES-2557 SMTP session should use an Optional as a sender

Posted by bt...@apache.org.
JAMES-2557 SMTP session should use an Optional<MailAddress> as a sender


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

Branch: refs/heads/master
Commit: 0bdffec1d3bac025f8c2517609a78195b110bb7a
Parents: 5b673a0
Author: Benoit Tellier <bt...@linagora.com>
Authored: Thu Dec 6 11:30:28 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Dec 11 13:59:20 2018 +0700

----------------------------------------------------------------------
 ...tSenderAuthIdentifyVerificationRcptHook.java | 34 +++++++++++++-------
 .../protocols/smtp/core/DataCmdHandler.java     |  4 +--
 .../protocols/smtp/core/MailCmdHandler.java     | 33 +++++++++++--------
 .../protocols/smtp/core/RcptCmdHandler.java     | 11 +++----
 .../smtp/core/esmtp/MailSizeEsmtpExtension.java | 13 +++++---
 .../fastfail/ValidSenderDomainHandlerTest.java  |  9 +++---
 .../org/apache/james/server/core/MailImpl.java  |  8 +++--
 .../DataLineJamesMessageHookHandler.java        |  5 +--
 .../smtpserver/SpamAssassinHandlerTest.java     |  9 +++++-
 .../james/smtpserver/URIRBLHandlerTest.java     |  9 +++++-
 10 files changed, 86 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/0bdffec1/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/AbstractSenderAuthIdentifyVerificationRcptHook.java
----------------------------------------------------------------------
diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/AbstractSenderAuthIdentifyVerificationRcptHook.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/AbstractSenderAuthIdentifyVerificationRcptHook.java
index dea7d52..9265833 100644
--- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/AbstractSenderAuthIdentifyVerificationRcptHook.java
+++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/AbstractSenderAuthIdentifyVerificationRcptHook.java
@@ -31,6 +31,8 @@ import org.apache.james.protocols.smtp.hook.HookResult;
 import org.apache.james.protocols.smtp.hook.HookReturnCode;
 import org.apache.james.protocols.smtp.hook.RcptHook;
 
+import com.google.common.base.Preconditions;
+
 /**
  * Handler which check if the authenticated user is the same as the one used as MAIL FROM
  */
@@ -45,28 +47,36 @@ public abstract class AbstractSenderAuthIdentifyVerificationRcptHook implements
     @Override
     public HookResult doRcpt(SMTPSession session, MaybeSender sender, MailAddress rcpt) {
         if (session.getUser() != null) {
-            String authUser = (session.getUser()).toLowerCase(Locale.US);
-            MailAddress senderAddress = (MailAddress) session.getAttachment(
-                    SMTPSession.SENDER, ProtocolSession.State.Transaction);
-            String username = retrieveSender(sender, senderAddress);
+            MaybeSender senderAddress = (MaybeSender) session.getAttachment(SMTPSession.SENDER, ProtocolSession.State.Transaction);
             
             // Check if the sender address is the same as the user which was used to authenticate.
             // Its important to ignore case here to fix JAMES-837. This is save todo because if the handler is called
             // the user was already authenticated
-            if ((senderAddress == null)
-                || (!authUser.equalsIgnoreCase(username))
-                || (!isLocalDomain(senderAddress.getDomain()))) {
+            if (isAnonymous(sender)
+                || !senderMatchSessionUser(sender, session)
+                || !belongsToLocalDomain(senderAddress)) {
                 return INVALID_AUTH;
             }
         }
         return HookResult.DECLINED;
     }
 
-    public String retrieveSender(MaybeSender sender, MailAddress senderAddress) {
-        if (senderAddress != null && !sender.isNullSender()) {
-            return getUser(senderAddress);
-        }
-        return null;
+    private boolean isAnonymous(MaybeSender maybeSender) {
+        return maybeSender == null || maybeSender.isNullSender();
+    }
+
+    private boolean senderMatchSessionUser(MaybeSender maybeSender, SMTPSession session) {
+        Preconditions.checkArgument(!maybeSender.isNullSender());
+
+        String authUser = session.getUser().toLowerCase(Locale.US);
+        String username = getUser(maybeSender.get());
+
+        return username.equals(authUser);
+    }
+
+    private boolean belongsToLocalDomain(MaybeSender maybeSender) {
+        Preconditions.checkArgument(!maybeSender.isNullSender());
+        return isLocalDomain(maybeSender.get().getDomain());
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/0bdffec1/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/DataCmdHandler.java
----------------------------------------------------------------------
diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/DataCmdHandler.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/DataCmdHandler.java
index 00f1128..de3d001 100644
--- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/DataCmdHandler.java
+++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/DataCmdHandler.java
@@ -172,8 +172,8 @@ public class DataCmdHandler implements CommandHandler<SMTPSession>, ExtensibleHa
      */
     @SuppressWarnings("unchecked")
     protected Response doDATA(SMTPSession session, String argument) {
-        MailAddress sender = (MailAddress) session.getAttachment(SMTPSession.SENDER, ProtocolSession.State.Transaction);
-        MailEnvelope env = createEnvelope(session, MaybeSender.of(sender), new ArrayList<>((Collection<MailAddress>) session.getAttachment(SMTPSession.RCPT_LIST, ProtocolSession.State.Transaction)));
+        MaybeSender sender = (MaybeSender) session.getAttachment(SMTPSession.SENDER, ProtocolSession.State.Transaction);
+        MailEnvelope env = createEnvelope(session, sender, new ArrayList<>((Collection<MailAddress>) session.getAttachment(SMTPSession.RCPT_LIST, ProtocolSession.State.Transaction)));
         session.setAttachment(MAILENV, env,ProtocolSession.State.Transaction);
         session.pushLineHandler(lineHandler);
         

http://git-wip-us.apache.org/repos/asf/james-project/blob/0bdffec1/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/MailCmdHandler.java
----------------------------------------------------------------------
diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/MailCmdHandler.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/MailCmdHandler.java
index 5a18476..4ba8374 100644
--- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/MailCmdHandler.java
+++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/MailCmdHandler.java
@@ -115,13 +115,12 @@ public class MailCmdHandler extends AbstractHookableCmdHandler<MailHook> {
      */
     private Response doMAIL(SMTPSession session, String argument) {
         StringBuilder responseBuffer = new StringBuilder();
-        MailAddress sender = (MailAddress) session.getAttachment(
-                SMTPSession.SENDER, State.Transaction);
+        MaybeSender sender = (MaybeSender) session.getAttachment(SMTPSession.SENDER, State.Transaction);
         responseBuffer.append(
                 DSNStatus.getStatus(DSNStatus.SUCCESS, DSNStatus.ADDRESS_OTHER))
                 .append(" Sender <");
         if (sender != null) {
-            responseBuffer.append(sender);
+            responseBuffer.append(sender.asString());
         }
         responseBuffer.append("> OK");
         return new SMTPResponse(SMTPRetCode.MAIL_OK, responseBuffer);
@@ -214,7 +213,7 @@ public class MailCmdHandler extends AbstractHookableCmdHandler<MailHook> {
                 LOGGER.info("Error parsing sender address: {}: did not start and end with < >", sender);
                 return SYNTAX_ERROR;
             }
-            MailAddress senderAddress = null;
+            MaybeSender senderAddress = MaybeSender.nullSender();
 
             if (session.getConfiguration().useAddressBracketsEnforcement()
                     || (sender.startsWith("<") && sender.endsWith(">"))) {
@@ -223,7 +222,7 @@ public class MailCmdHandler extends AbstractHookableCmdHandler<MailHook> {
             }
 
             if (sender.length() == 0) {
-                // This is the <> case. Let senderAddress == null
+                // This is the <> case. Let senderAddress == MaybeSender.nullSender()
             } else {
 
                 if (!sender.contains("@")) {
@@ -233,34 +232,40 @@ public class MailCmdHandler extends AbstractHookableCmdHandler<MailHook> {
                 }
 
                 try {
-                    senderAddress = new MailAddress(sender);
+                    senderAddress = MaybeSender.of(new MailAddress(sender));
                 } catch (Exception pe) {
                     LOGGER.info("Error parsing sender address: {}", sender, pe);
                     return SYNTAX_ERROR_ADDRESS;
                 }
             }
-            if ((senderAddress == null) || 
-                    ((senderAddress.getLocalPart().length() == 0) && (senderAddress.getDomain().name().length() == 0))) {
-                senderAddress = MailAddress.nullSender();
+            if (isNullSender(senderAddress)) {
+                senderAddress = MaybeSender.nullSender();
             }
             // Store the senderAddress in session map
             session.setAttachment(SMTPSession.SENDER, senderAddress, State.Transaction);
         }
         return null;
     }
-    
+
+    private boolean isNullSender(MaybeSender senderAddress) {
+        if (senderAddress.isNullSender()) {
+            return true;
+        }
+        boolean hasEmptyLocalPart = senderAddress.get().getLocalPart().length() == 0;
+        boolean hasEmptyDomainPart = senderAddress.get().getDomain().name().length() == 0;
+        return hasEmptyLocalPart && hasEmptyDomainPart;
+    }
+
     @Override
     protected Class<MailHook> getHookInterface() {
         return MailHook.class;
     }
 
-
     @Override
     protected HookResult callHook(MailHook rawHook, SMTPSession session, String parameters) {
-        MailAddress sender = (MailAddress) session.getAttachment(SMTPSession.SENDER, State.Transaction);
-        return rawHook.doMail(session, MaybeSender.of(sender));
+        MaybeSender sender = (MaybeSender) session.getAttachment(SMTPSession.SENDER, State.Transaction);
+        return rawHook.doMail(session, sender);
     }
-
     
     @Override
     public List<Class<?>> getMarkerInterfaces() {

http://git-wip-us.apache.org/repos/asf/james-project/blob/0bdffec1/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/RcptCmdHandler.java
----------------------------------------------------------------------
diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/RcptCmdHandler.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/RcptCmdHandler.java
index 2640564..c8fc16b 100644
--- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/RcptCmdHandler.java
+++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/RcptCmdHandler.java
@@ -211,9 +211,9 @@ public class RcptCmdHandler extends AbstractHookableCmdHandler<RcptHook> impleme
         } else if (null != recipient) {
             sb.append(" [to:").append(recipient).append(']');
         }
-        if (null != session.getAttachment(SMTPSession.SENDER, State.Transaction)) {
-            MailAddress mailAddress = (MailAddress) session.getAttachment(SMTPSession.SENDER, State.Transaction);
-            sb.append(" [from:").append(mailAddress.asString()).append(']');
+       MaybeSender sender = (MaybeSender) session.getAttachment(SMTPSession.SENDER, State.Transaction);
+        if (null != sender && !sender.isNullSender()) {
+            sb.append(" [from:").append(sender.asString()).append(']');
         }
         return sb.toString();
     }
@@ -230,9 +230,8 @@ public class RcptCmdHandler extends AbstractHookableCmdHandler<RcptHook> impleme
 
     @Override
     protected HookResult callHook(RcptHook rawHook, SMTPSession session, String parameters) {
-        MailAddress sender = (MailAddress) session.getAttachment(SMTPSession.SENDER, State.Transaction);
-        return rawHook.doRcpt(session,
-                MaybeSender.of(sender),
+        MaybeSender sender = (MaybeSender) session.getAttachment(SMTPSession.SENDER, State.Transaction);
+        return rawHook.doRcpt(session, sender,
                 (MailAddress) session.getAttachment(CURRENT_RECIPIENT, State.Transaction));
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/0bdffec1/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/MailSizeEsmtpExtension.java
----------------------------------------------------------------------
diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/MailSizeEsmtpExtension.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/MailSizeEsmtpExtension.java
index 19f6012..02e63d8 100644
--- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/MailSizeEsmtpExtension.java
+++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/MailSizeEsmtpExtension.java
@@ -26,6 +26,7 @@ import java.util.List;
 
 import org.apache.commons.configuration.Configuration;
 import org.apache.commons.configuration.ConfigurationException;
+import org.apache.james.core.MaybeSender;
 import org.apache.james.protocols.api.ProtocolSession.State;
 import org.apache.james.protocols.api.Response;
 import org.apache.james.protocols.api.handler.LineHandler;
@@ -79,8 +80,8 @@ public class MailSizeEsmtpExtension implements MailParametersHook, EhloExtension
     @Override
     public HookResult doMailParameter(SMTPSession session, String paramName,
                                       String paramValue) {
-        return doMailSize(session, paramValue,
-                (String) session.getAttachment(SMTPSession.SENDER, State.Transaction));
+        MaybeSender tempSender = (MaybeSender) session.getAttachment(SMTPSession.SENDER, State.Transaction);
+        return doMailSize(session, paramValue, tempSender);
     }
 
     @Override
@@ -114,7 +115,7 @@ public class MailSizeEsmtpExtension implements MailParametersHook, EhloExtension
      * @return true if further options should be processed, false otherwise
      */
     private HookResult doMailSize(SMTPSession session,
-            String mailOptionValue, String tempSender) {
+            String mailOptionValue, MaybeSender tempSender) {
         int size = 0;
         try {
             size = Integer.parseInt(mailOptionValue);
@@ -128,7 +129,11 @@ public class MailSizeEsmtpExtension implements MailParametersHook, EhloExtension
         long maxMessageSize = session.getConfiguration().getMaxMessageSize();
         if ((maxMessageSize > 0) && (size > maxMessageSize)) {
             // Let the client know that the size limit has been hit.
-            LOGGER.error("Rejected message from {} from {} of size {} exceeding system maximum message size of {} based on SIZE option.", (tempSender != null ? tempSender : null), session.getRemoteAddress().getAddress().getHostAddress(), size, maxMessageSize);
+            LOGGER.error("Rejected message from {} to {} of size {} exceeding system maximum message size of {} based on SIZE option.",
+                tempSender,
+                session.getRemoteAddress().getAddress().getHostAddress(),
+                size,
+                maxMessageSize);
 
             return QUOTA_EXCEEDED;
         } else {

http://git-wip-us.apache.org/repos/asf/james-project/blob/0bdffec1/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/core/fastfail/ValidSenderDomainHandlerTest.java
----------------------------------------------------------------------
diff --git a/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/core/fastfail/ValidSenderDomainHandlerTest.java b/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/core/fastfail/ValidSenderDomainHandlerTest.java
index 3d5da19..71cd15e 100644
--- a/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/core/fastfail/ValidSenderDomainHandlerTest.java
+++ b/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/core/fastfail/ValidSenderDomainHandlerTest.java
@@ -25,7 +25,6 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
 import org.apache.james.core.MailAddress;
 import org.apache.james.core.MaybeSender;
 import org.apache.james.protocols.api.ProtocolSession.State;
@@ -40,7 +39,7 @@ public class ValidSenderDomainHandlerTest {
         return new ValidSenderDomainHandler() {
 
             @Override
-            public void init(Configuration config) throws ConfigurationException {
+            public void init(Configuration config) {
 
             }
 
@@ -66,7 +65,7 @@ public class ValidSenderDomainHandlerTest {
             @Override
             public Map<String,Object> getState() {
 
-                map.put(SMTPSession.SENDER, sender);
+                map.put(SMTPSession.SENDER, MaybeSender.of(sender));
 
                 return map;
             }
@@ -116,8 +115,8 @@ public class ValidSenderDomainHandlerTest {
     public void testInvalidSenderDomainReject() throws Exception {
         ValidSenderDomainHandler handler = createHandler();
         SMTPSession session = setupMockedSession(new MailAddress("invalid@invalid"));
-        MailAddress sender = (MailAddress) session.getAttachment(SMTPSession.SENDER, State.Transaction);
-        HookReturnCode response = handler.doMail(session, MaybeSender.of(sender)).getResult();
+        MaybeSender sender = (MaybeSender) session.getAttachment(SMTPSession.SENDER, State.Transaction);
+        HookReturnCode response = handler.doMail(session, sender).getResult();
         
         assertThat(HookReturnCode.deny()).describedAs("Blocked cause we use reject action").isEqualTo(response);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/0bdffec1/server/container/core/src/main/java/org/apache/james/server/core/MailImpl.java
----------------------------------------------------------------------
diff --git a/server/container/core/src/main/java/org/apache/james/server/core/MailImpl.java b/server/container/core/src/main/java/org/apache/james/server/core/MailImpl.java
index 9eaf52a..5720c0a 100644
--- a/server/container/core/src/main/java/org/apache/james/server/core/MailImpl.java
+++ b/server/container/core/src/main/java/org/apache/james/server/core/MailImpl.java
@@ -417,9 +417,13 @@ public class MailImpl implements Disposable, Mail {
      * @param recipients the collection of recipients of this MailImpl
      */
     public MailImpl(String name, MailAddress sender, Collection<MailAddress> recipients) {
+        this(name, Optional.ofNullable(sender), recipients);
+    }
+
+    public MailImpl(String name, Optional<MailAddress> sender, Collection<MailAddress> recipients) {
         this();
         setName(name);
-        setSender(sender);
+        sender.ifPresent(this::setSender);
 
         // Copy the recipient list
         if (recipients != null) {
@@ -427,7 +431,7 @@ public class MailImpl implements Disposable, Mail {
         }
     }
 
-    @SuppressWarnings({"unchecked", "deprecation"})
+    @SuppressWarnings({"unchecked", "deprecated"})
     private MailImpl(Mail mail, String newName) throws MessagingException {
         this(newName, mail.getSender(), mail.getRecipients(), mail.getMessage());
         setRemoteHost(mail.getRemoteHost());

http://git-wip-us.apache.org/repos/asf/james-project/blob/0bdffec1/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/DataLineJamesMessageHookHandler.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/DataLineJamesMessageHookHandler.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/DataLineJamesMessageHookHandler.java
index b90d603..de9a3ca 100644
--- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/DataLineJamesMessageHookHandler.java
+++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/DataLineJamesMessageHookHandler.java
@@ -25,6 +25,7 @@ import java.io.OutputStream;
 import java.nio.ByteBuffer;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Optional;
 
 import javax.mail.MessagingException;
 
@@ -99,9 +100,9 @@ public class DataLineJamesMessageHookHandler implements DataLineFilter, Extensib
 
                 @SuppressWarnings("unchecked")
                 List<MailAddress> recipientCollection = (List<MailAddress>) session.getAttachment(SMTPSession.RCPT_LIST, State.Transaction);
-                MailAddress mailAddress = (MailAddress) session.getAttachment(SMTPSession.SENDER, State.Transaction);
+                MaybeSender sender = (MaybeSender) session.getAttachment(SMTPSession.SENDER, State.Transaction);
 
-                MailImpl mail = new MailImpl(MailImpl.getId(), mailAddress, recipientCollection);
+                MailImpl mail = new MailImpl(MailImpl.getId(), Optional.ofNullable(sender).flatMap(MaybeSender::asOptional), recipientCollection);
 
                 // store mail in the session so we can be sure it get disposed later
                 session.setAttachment(SMTPConstants.MAIL, mail, State.Transaction);

http://git-wip-us.apache.org/repos/asf/james-project/blob/0bdffec1/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SpamAssassinHandlerTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SpamAssassinHandlerTest.java b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SpamAssassinHandlerTest.java
index eb56867..db8b783 100644
--- a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SpamAssassinHandlerTest.java
+++ b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SpamAssassinHandlerTest.java
@@ -24,8 +24,11 @@ import static org.assertj.core.api.Assertions.assertThat;
 import java.util.HashMap;
 
 import javax.mail.MessagingException;
+import javax.mail.internet.AddressException;
 import javax.mail.internet.MimeMessage;
 
+import org.apache.james.core.MailAddress;
+import org.apache.james.core.MaybeSender;
 import org.apache.james.core.builder.MimeMessageBuilder;
 import org.apache.james.metrics.api.NoopMetricFactory;
 import org.apache.james.protocols.smtp.SMTPSession;
@@ -72,7 +75,11 @@ public class SpamAssassinHandlerTest {
 
             @Override
             public Object getAttachment(String key, State state) {
-                sstate.put(SMTPSession.SENDER, "sender@james.apache.org");
+                try {
+                    sstate.put(SMTPSession.SENDER, MaybeSender.of(new MailAddress("sender@james.apache.org")));
+                } catch (AddressException e) {
+                    throw new RuntimeException(e);
+                }
                 if (state == State.Connection) {
                     return connectionState.get(key);
                 } else {

http://git-wip-us.apache.org/repos/asf/james-project/blob/0bdffec1/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/URIRBLHandlerTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/URIRBLHandlerTest.java b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/URIRBLHandlerTest.java
index 93edf95..0a632e8 100644
--- a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/URIRBLHandlerTest.java
+++ b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/URIRBLHandlerTest.java
@@ -29,8 +29,11 @@ import java.util.HashMap;
 import java.util.List;
 
 import javax.mail.MessagingException;
+import javax.mail.internet.AddressException;
 import javax.mail.internet.MimeMessage;
 
+import org.apache.james.core.MailAddress;
+import org.apache.james.core.MaybeSender;
 import org.apache.james.core.builder.MimeMessageBuilder;
 import org.apache.james.dnsservice.api.DNSService;
 import org.apache.james.dnsservice.api.mock.MockDNSService;
@@ -78,7 +81,11 @@ public class URIRBLHandlerTest {
 
             @Override
             public Object getAttachment(String key, State state) {
-                sstate.put(SMTPSession.SENDER, "sender@james.apache.org");
+                try {
+                    sstate.put(SMTPSession.SENDER, MaybeSender.of(new MailAddress("sender@james.apache.org")));
+                } catch (AddressException e) {
+                    throw new RuntimeException(e);
+                }
 
                 if (state == State.Connection) {
                     return connectionState.get(key);


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


[5/7] james-project git commit: JAMES-2456 Remove no more needed calls to MailAddress::isNullSender

Posted by bt...@apache.org.
JAMES-2456 Remove no more needed calls to MailAddress::isNullSender

Code working with optional directly take care of this.


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

Branch: refs/heads/master
Commit: 3ae94d0337cc99f66f41e3969a2b1b85ee110501
Parents: cc79534
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Oct 24 11:07:34 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Dec 11 14:00:07 2018 +0700

----------------------------------------------------------------------
 .../mailets/redirect/MailModifier.java          | 29 +++++++++++---------
 .../transport/util/SpecialAddressesUtils.java   |  4 ---
 2 files changed, 16 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/3ae94d03/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/MailModifier.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/MailModifier.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/MailModifier.java
index 2ffc92b..cdad611 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/MailModifier.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/MailModifier.java
@@ -37,6 +37,7 @@ import org.apache.mailet.base.RFC2822Headers;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.github.fge.lambdas.Throwing;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 
@@ -111,7 +112,6 @@ public class MailModifier {
         if (!recipients.isEmpty()) {
             mail.setRecipients(recipients
                 .stream()
-                .filter(address -> !address.isNullSender())
                 .collect(ImmutableList.toImmutableList()));
             if (mailet.getInitParameters().isDebug()) {
                 if (LOGGER.isDebugEnabled()) {
@@ -144,18 +144,21 @@ public class MailModifier {
      * the "Reply-To:" header. If the requested value is null does nothing.</p>
      */
     public void setReplyTo(Optional<MailAddress> optionalReplyTo) throws MessagingException {
-        if (optionalReplyTo.isPresent()) {
-            MailAddress replyTo = optionalReplyTo.get();
-            if (replyTo.isNullSender() || replyTo.equals(SpecialAddress.NULL)) {
-                mail.getMessage().setReplyTo(null);
-                if (mailet.getInitParameters().isDebug()) {
-                    LOGGER.debug("replyTo set to: null");
-                }
-            } else {
-                mail.getMessage().setReplyTo(new InternetAddress[] { replyTo.toInternetAddress() });
-                if (mailet.getInitParameters().isDebug()) {
-                    LOGGER.debug("replyTo set to: {}", replyTo);
-                }
+        optionalReplyTo.ifPresent(Throwing
+            .consumer((MailAddress address) -> setReplyTo(address))
+            .sneakyThrow());
+    }
+
+    private void setReplyTo(MailAddress replyTo) throws MessagingException {
+        if (replyTo.equals(SpecialAddress.NULL)) {
+            mail.getMessage().setReplyTo(null);
+            if (mailet.getInitParameters().isDebug()) {
+                LOGGER.debug("replyTo set to: null");
+            }
+        } else {
+            mail.getMessage().setReplyTo(new InternetAddress[] { replyTo.toInternetAddress() });
+            if (mailet.getInitParameters().isDebug()) {
+                LOGGER.debug("replyTo set to: {}", replyTo);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/3ae94d03/server/mailet/mailets/src/main/java/org/apache/james/transport/util/SpecialAddressesUtils.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/util/SpecialAddressesUtils.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/util/SpecialAddressesUtils.java
index f95175f..9abfd7c 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/util/SpecialAddressesUtils.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/util/SpecialAddressesUtils.java
@@ -87,10 +87,6 @@ public class SpecialAddressesUtils {
             return ImmutableSet.of(mailAddress);
         }
 
-        if (mailAddress.isNullSender()) {
-            return ImmutableList.of();
-        }
-
         SpecialAddressKind specialAddressKind = SpecialAddressKind.forValue(mailAddress.getLocalPart());
         if (specialAddressKind == null) {
             return ImmutableSet.of(mailAddress);


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