james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [04/17] james-project git commit: JAMES-2557 Review mail envelope API
Date Thu, 01 Nov 2018 04:07:39 GMT
JAMES-2557 Review mail envelope API


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

Branch: refs/heads/master
Commit: 3d83c3dd1676545a47d661d88721c5dc7133807c
Parents: 3f68078
Author: Benoit Tellier <btellier@linagora.com>
Authored: Tue Oct 30 11:17:22 2018 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Thu Nov 1 10:56:32 2018 +0700

----------------------------------------------------------------------
 .../james/protocols/smtp/MailEnvelope.java      | 27 ++++++++++++++++++--
 .../james/protocols/smtp/MailEnvelopeImpl.java  |  7 ++---
 .../protocols/smtp/core/DataCmdHandler.java     |  6 +++--
 .../protocols/smtp/AbstractSMTPServerTest.java  |  2 +-
 .../DataLineJamesMessageHookHandler.java        |  6 ++---
 5 files changed, 37 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/3d83c3dd/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/MailEnvelope.java
----------------------------------------------------------------------
diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/MailEnvelope.java
b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/MailEnvelope.java
index f85d861..3cba413 100644
--- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/MailEnvelope.java
+++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/MailEnvelope.java
@@ -25,6 +25,7 @@ import java.io.OutputStream;
 import java.util.List;
 
 import org.apache.james.core.MailAddress;
+import org.apache.james.core.MaybeSender;
 
 /**
  * The MailEnvelope of a SMTP-Transaction
@@ -51,10 +52,32 @@ public interface MailEnvelope {
     /**
      * Return the sender of the mail which was supplied int the MAIL FROM:
      * command. If its a "null" sender, null will get returned
-     * 
+     *
+     * @deprecated @see {@link #getMaybeSender()}
+     *
+     * Note that SMTP null sender ( "&lt;&gt;" ) needs to be implicitly handled by
the caller under the form of 'null' or
+     * {@link MailAddress#nullSender()}. Replacement method adds type safety on this operation.
+     *
      * @return sender
      */
-    MailAddress getSender();
+    @Deprecated
+    default MailAddress getSender() {
+        return getMaybeSender().asOptional().orElse(MailAddress.nullSender());
+    }
+
+    /**
+     * Returns the sender of the message, as specified by the SMTP "MAIL FROM" command,
+     * or internally defined.
+     *
+     * 'null' or {@link MailAddress#nullSender()} are handled with {@link MaybeSender}.
+     *
+     * @since Mailet API v3.2.0
+     * @return the sender of this message wrapped in an optional
+     */
+    @SuppressWarnings("deprecated")
+    default MaybeSender getMaybeSender() {
+        return MaybeSender.of(getSender());
+    }
 
     /**
      * Return the OutputStream of the message

http://git-wip-us.apache.org/repos/asf/james-project/blob/3d83c3dd/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/MailEnvelopeImpl.java
----------------------------------------------------------------------
diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/MailEnvelopeImpl.java
b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/MailEnvelopeImpl.java
index 59dbe97..2f51d58 100644
--- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/MailEnvelopeImpl.java
+++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/MailEnvelopeImpl.java
@@ -27,6 +27,7 @@ import java.io.OutputStream;
 import java.util.List;
 
 import org.apache.james.core.MailAddress;
+import org.apache.james.core.MaybeSender;
 
 /**
  * MailEnvelope implementation which stores everything in memory
@@ -37,7 +38,7 @@ public class MailEnvelopeImpl implements MailEnvelope {
 
     private List<MailAddress> recipients;
 
-    private MailAddress sender;
+    private MaybeSender sender;
 
     private ByteArrayOutputStream outputStream;
 
@@ -55,7 +56,7 @@ public class MailEnvelopeImpl implements MailEnvelope {
     }
 
     @Override
-    public MailAddress getSender() {
+    public MaybeSender getMaybeSender() {
         return sender;
     }
 
@@ -73,7 +74,7 @@ public class MailEnvelopeImpl implements MailEnvelope {
      * 
      * @param sender
      */
-    public void setSender(MailAddress sender) {
+    public void setSender(MaybeSender sender) {
         this.sender = sender;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/3d83c3dd/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 0a0e594..906da01 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
@@ -31,6 +31,7 @@ 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;
@@ -171,14 +172,15 @@ public class DataCmdHandler implements CommandHandler<SMTPSession>,
ExtensibleHa
      */
     @SuppressWarnings("unchecked")
     protected Response doDATA(SMTPSession session, String argument) {
-        MailEnvelope env = createEnvelope(session, (MailAddress) session.getAttachment(SMTPSession.SENDER,ProtocolSession.State.Transaction),
new ArrayList<>((Collection<MailAddress>) session.getAttachment(SMTPSession.RCPT_LIST,
ProtocolSession.State.Transaction)));
+        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, MailAddress sender, List<MailAddress>
recipients) {
+    protected MailEnvelope createEnvelope(SMTPSession session, MaybeSender sender, List<MailAddress>
recipients) {
         MailEnvelopeImpl env = new MailEnvelopeImpl();
         env.setRecipients(recipients);
         env.setSender(sender);

http://git-wip-us.apache.org/repos/asf/james-project/blob/3d83c3dd/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/AbstractSMTPServerTest.java
----------------------------------------------------------------------
diff --git a/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/AbstractSMTPServerTest.java
b/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/AbstractSMTPServerTest.java
index bf3f756..74aa841 100644
--- a/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/AbstractSMTPServerTest.java
+++ b/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/AbstractSMTPServerTest.java
@@ -1115,7 +1115,7 @@ public abstract class AbstractSMTPServerTest {
     }
     
     protected static void checkEnvelope(MailEnvelope env, String sender, List<String>
recipients, String msg) throws IOException {
-        assertThat(env.getSender().toString()).isEqualTo(sender);
+        assertThat(env.getMaybeSender().asString()).isEqualTo(sender);
 
         List<MailAddress> envRecipients = env.getRecipients();
         assertThat(envRecipients.size()).isEqualTo(recipients.size());

http://git-wip-us.apache.org/repos/asf/james-project/blob/3d83c3dd/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 a051e7e..b90d603 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
@@ -31,6 +31,7 @@ import javax.mail.MessagingException;
 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.lifecycle.api.LifecycleUtil;
 import org.apache.james.protocols.api.ProtocolSession.State;
 import org.apache.james.protocols.api.Response;
@@ -259,10 +260,9 @@ public class DataLineJamesMessageHookHandler implements DataLineFilter,
Extensib
             return ImmutableList.copyOf(mail.getRecipients());
         }
 
-        @SuppressWarnings("deprecated") // This will be handled in a followup pull request
See JAMES-2557
         @Override
-        public MailAddress getSender() {
-            return mail.getSender();
+        public MaybeSender getMaybeSender() {
+            return mail.getMaybeSender();
         }
 
         @Override


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


Mime
View raw message