JAMES-2352 Null senders should be handled by James SMTP layer

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

Branch: refs/heads/master
Commit: 9d6d42f5bb8465eaec8c30e130d199bcdfb8bcd6
Parents: f70b8f2
Author: benwa <btell...@linagora.com>
Authored: Wed Mar 21 10:26:46 2018 +0700
Committer: benwa <btell...@linagora.com>
Committed: Tue Mar 27 15:14:04 2018 +0700

----------------------------------------------------------------------
 ...tSenderAuthIdentifyVerificationRcptHook.java |  4 +-
 .../apache/james/smtp/SmtpNullSenderTest.java   | 72 ++++++++++++++++++++
 .../DataLineJamesMessageHookHandler.java        | 18 +----
 .../model/MailetMailAddressAdapter.java         | 33 ---------
 4 files changed, 75 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/9d6d42f5/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 4c386c6..754df55 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
@@ -49,9 +49,9 @@ public abstract class 
AbstractSenderAuthIdentifyVerificationRcptHook implements
                     SMTPSession.SENDER, ProtocolSession.State.Transaction);
             String username = null;
 
-            if (senderAddress != null) {
+            if (senderAddress != null && !sender.isNullSender()) {
                 if (useVirtualHosting()) {
-                    username = senderAddress.toString();
+                    username = senderAddress.asString();
                 } else {
                     username = senderAddress.getLocalPart();
                 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/9d6d42f5/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpNullSenderTest.java
----------------------------------------------------------------------
diff --git 
a/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpNullSenderTest.java
 
b/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpNullSenderTest.java
new file mode 100644
index 0000000..13b05be
--- /dev/null
+++ 
b/server/mailet/integration-testing/src/test/java/org/apache/james/smtp/SmtpNullSenderTest.java
@@ -0,0 +1,72 @@
+/****************************************************************
+ * 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.smtp;
+
+import static org.apache.james.mailets.configuration.Constants.DEFAULT_DOMAIN;
+import static org.apache.james.mailets.configuration.Constants.LOCALHOST_IP;
+import static org.apache.james.mailets.configuration.Constants.PASSWORD;
+import static org.apache.james.mailets.configuration.Constants.SMTP_PORT;
+import static 
org.apache.james.mailets.configuration.Constants.awaitAtMostOneMinute;
+
+import org.apache.james.mailets.TemporaryJamesServer;
+import org.apache.james.probe.DataProbe;
+import org.apache.james.utils.DataProbeImpl;
+import org.apache.james.utils.IMAPMessageReader;
+import org.apache.james.utils.SMTPMessageSender;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+public class SmtpNullSenderTest {
+    private static final String USER = "user@" + DEFAULT_DOMAIN;
+
+    @Rule
+    public TemporaryFolder temporaryFolder = new TemporaryFolder();
+    @Rule
+    public SMTPMessageSender messageSender = new 
SMTPMessageSender(DEFAULT_DOMAIN);
+    @Rule
+    public IMAPMessageReader imapMessageReader = new IMAPMessageReader();
+
+    private TemporaryJamesServer jamesServer;
+
+    @Before
+    public void setUp() throws Exception {
+        jamesServer = TemporaryJamesServer.builder()
+            .build(temporaryFolder);
+
+        DataProbe dataProbe = jamesServer.getProbe(DataProbeImpl.class);
+        dataProbe.addDomain(DEFAULT_DOMAIN);
+        dataProbe.addUser(USER, PASSWORD);
+    }
+
+    @After
+    public void tearDown() {
+        jamesServer.shutdown();
+    }
+
+    @Test
+    public void smtpLayerShouldAcceptEmptySenders() throws Exception {
+        messageSender.connect(LOCALHOST_IP, SMTP_PORT)
+            .sendMessageWithHeaders("", USER,"Short message")
+            .awaitSent(awaitAtMostOneMinute);
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/9d6d42f5/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 5fc9825..70b3b47 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
@@ -53,7 +53,6 @@ import org.apache.james.server.core.MailImpl;
 import org.apache.james.server.core.MimeMessageCopyOnWriteProxy;
 import org.apache.james.server.core.MimeMessageInputStream;
 import org.apache.james.server.core.MimeMessageInputStreamSource;
-import org.apache.james.smtpserver.model.MailetMailAddressAdapter;
 import org.apache.mailet.Mail;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -101,17 +100,7 @@ public class DataLineJamesMessageHookHandler implements 
DataLineFilter, Extensib
                 List<MailAddress> recipientCollection = (List<MailAddress>) 
session.getAttachment(SMTPSession.RCPT_LIST, State.Transaction);
                 MailAddress mailAddress = (MailAddress) 
session.getAttachment(SMTPSession.SENDER, State.Transaction);
 
-                List<MailAddress> rcpts = new ArrayList<>();
-                for (MailAddress address : recipientCollection) {
-                    rcpts.add(new MailetMailAddressAdapter(address));
-                }
-
-                MailetMailAddressAdapter mailetMailAddressAdapter = null;
-                if (mailAddress != MailAddress.nullSender()) {
-                    mailetMailAddressAdapter = new 
MailetMailAddressAdapter(mailAddress);
-                }
-
-                MailImpl mail = new MailImpl(MailImpl.getId(), 
mailetMailAddressAdapter, rcpts);
+                MailImpl mail = new MailImpl(MailImpl.getId(), mailAddress, 
recipientCollection);
 
                 // store mail in the session so we can be sure it get disposed 
later
                 session.setAttachment(SMTPConstants.MAIL, mail, 
State.Transaction);
@@ -151,11 +140,6 @@ public class DataLineJamesMessageHookHandler implements 
DataLineFilter, Extensib
             SMTPResponse response = new SMTPResponse(SMTPRetCode.LOCAL_ERROR, 
DSNStatus.getStatus(DSNStatus.TRANSIENT, DSNStatus.UNDEFINED_STATUS) + " Error 
processing message: " + e.getMessage());
             LOGGER.error("Unknown error occurred while processing DATA.", e);
             return response;
-        } catch (AddressException e) {
-            LifecycleUtil.dispose(mmiss);
-            SMTPResponse response = new SMTPResponse(SMTPRetCode.LOCAL_ERROR, 
DSNStatus.getStatus(DSNStatus.TRANSIENT, DSNStatus.UNDEFINED_STATUS) + " Error 
processing message: " + e.getMessage());
-            LOGGER.error("Invalid email address while processing DATA.", e);
-            return response;
         }
         return null;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/9d6d42f5/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/model/MailetMailAddressAdapter.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/model/MailetMailAddressAdapter.java
 
b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/model/MailetMailAddressAdapter.java
deleted file mode 100644
index 1acb936..0000000
--- 
a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/model/MailetMailAddressAdapter.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-package org.apache.james.smtpserver.model;
-
-import javax.mail.internet.AddressException;
-
-import org.apache.james.core.MailAddress;
-
-public class MailetMailAddressAdapter extends MailAddress {
-    
-    private static final long serialVersionUID = 1L;
-
-    public MailetMailAddressAdapter(MailAddress mailAddress) throws 
AddressException {
-        super(mailAddress.getLocalPart(), mailAddress.getDomain());
-    }
-
-}


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

Reply via email to