From 589b70bb0921fcfaee569e319b08d40228bf2ff4 Mon Sep 17 00:00:00 2001 From: Philip Whitehouse Date: Thu, 31 Aug 2017 23:13:53 +0100 Subject: [PATCH] Add test for server rejecting recipient but OK to empty message --- .../k9/mail/transport/smtp/SmtpTransport.java | 3 +- .../transport/smtp/SmtpTransportTest.java | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/k9mail-library/src/main/java/com/fsck/k9/mail/transport/smtp/SmtpTransport.java b/k9mail-library/src/main/java/com/fsck/k9/mail/transport/smtp/SmtpTransport.java index b2cd02793..fb0da7a40 100644 --- a/k9mail-library/src/main/java/com/fsck/k9/mail/transport/smtp/SmtpTransport.java +++ b/k9mail-library/src/main/java/com/fsck/k9/mail/transport/smtp/SmtpTransport.java @@ -673,6 +673,7 @@ public class SmtpTransport extends Transport { if (negativeRecipient != null) { try { executeCommand("."); + throw negativeRecipient; } catch (NegativeSmtpReplyException e) { throw negativeRecipient; } @@ -683,7 +684,7 @@ public class SmtpTransport extends Transport { private CommandResponse responseLineToCommandResponse(String line, List results) throws MessagingException { int length = line.length(); if (length < 1) { - throw new MessagingException("SMTP response is 0 length"); + throw new MessagingException("SMTP response to line is 0 length"); } int replyCode = -1; diff --git a/k9mail-library/src/test/java/com/fsck/k9/mail/transport/smtp/SmtpTransportTest.java b/k9mail-library/src/test/java/com/fsck/k9/mail/transport/smtp/SmtpTransportTest.java index fd8323f2a..246b0dc85 100644 --- a/k9mail-library/src/test/java/com/fsck/k9/mail/transport/smtp/SmtpTransportTest.java +++ b/k9mail-library/src/test/java/com/fsck/k9/mail/transport/smtp/SmtpTransportTest.java @@ -825,6 +825,37 @@ public class SmtpTransportTest { server.verifyInteractionCompleted(); } + @Test + public void sendMessagePipelining_with250and550ReplyforRecipientsAnd250ForMessage_shouldThrow() throws Exception { + Message message = getMessageWithTwoRecipients(); + MockSmtpServer server = createServerAndSetupForPlainAuthentication("PIPELINING"); + server.expect("MAIL FROM:"); + server.expect("RCPT TO:"); + server.expect("RCPT TO:"); + server.expect("DATA"); + server.output("250 OK"); + server.output("250 OK"); + server.output("550 remote mail to not allowed"); + server.output("354 End data with ."); + server.expect("."); + server.output("250 OK"); + server.expect("QUIT"); + server.output("221 BYE"); + server.closeConnection(); + SmtpTransport transport = startServerAndCreateSmtpTransport(server); + + try { + transport.sendMessage(message); + fail("Expected exception"); + } catch (NegativeSmtpReplyException e) { + assertEquals(550, e.getReplyCode()); + assertEquals("remote mail to not allowed", e.getReplyText()); + } + + server.verifyConnectionClosed(); + server.verifyInteractionCompleted(); + } + private SmtpTransport startServerAndCreateSmtpTransport(MockSmtpServer server) throws IOException, MessagingException {