Add test for server rejecting recipient but OK to empty message
This commit is contained in:
parent
346bdc8cd2
commit
589b70bb09
2 changed files with 33 additions and 1 deletions
|
@ -673,6 +673,7 @@ public class SmtpTransport extends Transport {
|
||||||
if (negativeRecipient != null) {
|
if (negativeRecipient != null) {
|
||||||
try {
|
try {
|
||||||
executeCommand(".");
|
executeCommand(".");
|
||||||
|
throw negativeRecipient;
|
||||||
} catch (NegativeSmtpReplyException e) {
|
} catch (NegativeSmtpReplyException e) {
|
||||||
throw negativeRecipient;
|
throw negativeRecipient;
|
||||||
}
|
}
|
||||||
|
@ -683,7 +684,7 @@ public class SmtpTransport extends Transport {
|
||||||
private CommandResponse responseLineToCommandResponse(String line, List<String> results) throws MessagingException {
|
private CommandResponse responseLineToCommandResponse(String line, List<String> results) throws MessagingException {
|
||||||
int length = line.length();
|
int length = line.length();
|
||||||
if (length < 1) {
|
if (length < 1) {
|
||||||
throw new MessagingException("SMTP response is 0 length");
|
throw new MessagingException("SMTP response to line is 0 length");
|
||||||
}
|
}
|
||||||
|
|
||||||
int replyCode = -1;
|
int replyCode = -1;
|
||||||
|
|
|
@ -825,6 +825,37 @@ public class SmtpTransportTest {
|
||||||
server.verifyInteractionCompleted();
|
server.verifyInteractionCompleted();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void sendMessagePipelining_with250and550ReplyforRecipientsAnd250ForMessage_shouldThrow() throws Exception {
|
||||||
|
Message message = getMessageWithTwoRecipients();
|
||||||
|
MockSmtpServer server = createServerAndSetupForPlainAuthentication("PIPELINING");
|
||||||
|
server.expect("MAIL FROM:<user@localhost>");
|
||||||
|
server.expect("RCPT TO:<user2@localhost>");
|
||||||
|
server.expect("RCPT TO:<user3@localhost>");
|
||||||
|
server.expect("DATA");
|
||||||
|
server.output("250 OK");
|
||||||
|
server.output("250 OK");
|
||||||
|
server.output("550 remote mail to <user3@localhost> not allowed");
|
||||||
|
server.output("354 End data with <CR><LF>.<CR><LF>");
|
||||||
|
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 <user3@localhost> not allowed", e.getReplyText());
|
||||||
|
}
|
||||||
|
|
||||||
|
server.verifyConnectionClosed();
|
||||||
|
server.verifyInteractionCompleted();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private SmtpTransport startServerAndCreateSmtpTransport(MockSmtpServer server) throws IOException,
|
private SmtpTransport startServerAndCreateSmtpTransport(MockSmtpServer server) throws IOException,
|
||||||
MessagingException {
|
MessagingException {
|
||||||
|
|
Loading…
Reference in a new issue