From aa7239bab194c881e788b9148096961f4834d680 Mon Sep 17 00:00:00 2001 From: Tudor Aursulesei Date: Sun, 24 Jan 2016 16:26:33 +0200 Subject: [PATCH 1/2] patch client to raise the last error raised by the target MTA instead of anything else --- slimta/relay/smtp/client.py | 9 +++++++-- slimta/smtp/io.py | 7 +++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/slimta/relay/smtp/client.py b/slimta/relay/smtp/client.py index 4ef67af8..214c13a7 100644 --- a/slimta/relay/smtp/client.py +++ b/slimta/relay/smtp/client.py @@ -270,8 +270,13 @@ def _run(self): result.set_exception(e) except SmtpError as e: if not result.ready(): - reply = Reply('421', '4.3.0 {0!s}'.format(e), - command=self.current_command) + if self.client.io.last_error: + reply = Reply(self.client.io.last_error_code, self.client.io.last_error_message, + command=self.current_command) + else: + reply = Reply('421', '4.3.0 {0!s}'.format(e), + command=self.current_command) + relay_error = SmtpRelayError.factory(reply) result.set_exception(relay_error) except Timeout: diff --git a/slimta/smtp/io.py b/slimta/smtp/io.py index 224935a8..c4913fb6 100644 --- a/slimta/smtp/io.py +++ b/slimta/smtp/io.py @@ -60,6 +60,7 @@ def __init__(self, socket, tls_wrapper=None): self.send_buffer = BytesIO() self.recv_buffer = b'' + self.last_error = False @property def encrypted(self): @@ -141,6 +142,12 @@ def recv_reply(self): raise BadReply(match.group(1)) code = match.group(2) message_lines.append(match.group(4)) + + if code[0] in '45': + self.last_error = True + self.last_error_code = code + self.last_error_message = match.group(4) + self.recv_buffer = input[match.end(0):] if match.group(3) != b'-': From 721cadff11f5d76ae54c464b6c4c1fffb0b847e1 Mon Sep 17 00:00:00 2001 From: Tudor Aursulesei Date: Tue, 17 May 2016 14:09:13 +0300 Subject: [PATCH 2/2] force starttls when possible --- slimta/relay/smtp/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slimta/relay/smtp/client.py b/slimta/relay/smtp/client.py index 214c13a7..eaae2511 100644 --- a/slimta/relay/smtp/client.py +++ b/slimta/relay/smtp/client.py @@ -134,7 +134,7 @@ def _handshake(self): self.client.encrypt(self.tls) self._banner() self._ehlo() - if self.tls and not self.tls_immediately: + if self.tls or not self.tls_immediately: if self.tls_required or 'STARTTLS' in self.client.extensions: self._starttls() self._ehlo()