Commit Graph

5 Commits

Author SHA1 Message Date
Scott Mitchell
4e37689774 SmtpRequestEncoderTest ByteBuf leak (#9075)
Motivation:
SmtpRequestEncoderTest#testThrowsIfContentExpected has a ByteBuf leak.

Modifications:
- SmtpRequestEncoderTest#testThrowsIfContentExpected should release buffers in a finally block

Result:
No more leaks in SmtpRequestEncoderTest#testThrowsIfContentExpected.
2019-04-19 08:47:28 +02:00
Nikolay Fedorovskikh
0234878c4b Fix the commands cache and hashCode() in SmtpCommand
Motivation:
- A `hashCode` of the SmtpCommand is recalculated on each call of `hashCode()`. Cached hash code value can be just replaced with call of `name.hashCode()`.
- The commands cache don't work for strings: `SmtpCommand.valueOf("HELO")` returns a new instance.
- Field `contentExpected` is redundant and can be replaced with `equals(DATA)`.

Modifications:
- Use the `name.hashCode()` as hash code result.
- Fix a command cache: use strings as map keys.
- Replace field `contentExpected` to using `this.equals(DATA)`.
- Add unit tests.

Result:
More correct and clean code.
2017-08-18 09:46:53 +02:00
Michael O'Brien
12a5754569 Don't add null to SmtpResponse.details()
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.
2017-05-23 19:17:59 +02:00
Michael O'Brien
6a8532acd1 Reset the contentExpected flag when RSET is written
Motivation:

If the remote server returns a 4xx/5xx error in response to
a DATA command (or earlier command if using pipelining),
SmtpRequestEncoder can become stuck in an invalid state,
not allowing any requests to be sent.

This makes the channel unusable and the connection has to be closed,
or the encoder handler has to be replaced.

Modifications:

If a RSET command is written to the channel, the contentExpected
flag is set to false, and the RSET is written to the channel.

Result:

Sending a RSET command after a server 4xx/5xx error will make it
possible to use the current connection for new mail transactions.
2017-05-19 19:36:04 +02:00
Norman Maurer
562d8d2200 Add smtp codec (client side only).
Motivation:

When writing a SMTP client a provided SMTP codec that follows RFC2821 is useful.

Modification:

Add client side codec and test.

Results:

People who want to write a SMTP client can reuse the codec.
2016-04-07 18:42:17 +02:00