Skip to content

Commit

Permalink
Don't add null to SmtpResponse.details()
Browse files Browse the repository at this point in the history
Motivation:

If the remote server returns an invalid response in the form "000 \r\n"
(i.e. a three digit code, then space, but no details), null is added
as a singletonList to the response being constructed.

This seems unexpected and it would be easier to handle an empty
details list in client code.

Modifications:

If detail is null (because frame.isReadable() returned false after
reading the separator), initialise DefaultSmtpResponse with an empty
list instead of a list containing a single null value.

Result:

When encountering this malformed server response, a DefaultSmtpResponse
with a code but no details will be created.
  • Loading branch information
mcobrien authored and normanmaurer committed May 23, 2017
1 parent 2db4f25 commit 12a5754
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ protected SmtpResponse decode(ChannelHandlerContext ctx, ByteBuf buffer) throws
details.add(detail);
}
} else {
details = Collections.singletonList(detail);
if (detail == null) {
details = Collections.emptyList();
} else {
details = Collections.singletonList(detail);
}
}
return new DefaultSmtpResponse(code, details);
case '-':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ public void testDecodeOneLineResponse() {
assertNull(channel.readInbound());
}

@Test
public void testDecodeOneLineResponseNoDetails() {
EmbeddedChannel channel = newChannel();
assertTrue(channel.writeInbound(newBuffer("250 \r\n")));
assertTrue(channel.finish());

SmtpResponse response = channel.readInbound();
assertEquals(250, response.code());
List<CharSequence> sequences = response.details();
assertEquals(0, sequences.size());
}

@Test
public void testDecodeOneLineResponseChunked() {
EmbeddedChannel channel = newChannel();
Expand Down

0 comments on commit 12a5754

Please sign in to comment.