Skip to content

Commit

Permalink
Merge pull request slimta#61 from slimta/add-post-data-handler
Browse files Browse the repository at this point in the history
Fix slimta#56: Add handle_queued callback for reply modification
  • Loading branch information
icgood committed Dec 18, 2015
2 parents abc59e2 + 0601cfd commit fb726f6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 5 additions & 1 deletion slimta/edge/smtp.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ class SmtpValidators(object):
a :class:`~pysasl.AuthenticationCredentials` object.
- ``handle_mail(reply, sender, params)``: Validate the sender address.
- ``handle_rcpt(reply, recipient, params)``: Validate one recipient
address.
address.
- ``handle_data(reply)``: Any remaining validation before receiving data.
- ``handle_have_data(reply, data)``: Validate the received message data.
- ``handle_queued(reply, results)``: Once the message has been queued,
modify the returned |Reply| using the ``results`` from calling
:meth:`~slimta.queue.Queue.enqueue`.
- ``handle_rset(reply)``: Called before replying to an RSET command.
- ``handle_tls()``: Called after a successful TLS handshake. This may be at
the beginning of the session or after a `STARTTLS` command.
Expand Down Expand Up @@ -186,6 +189,7 @@ def HAVE_DATA(self, reply, data, err):
reply.copy(relay_reply)
else:
reply.message = '2.6.0 Message accepted for delivery'
self._call_validator('queued', reply, results)

self.envelope = None

Expand Down
8 changes: 3 additions & 5 deletions slimta/smtp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

import re

from gevent.ssl import SSLError
from gevent.socket import timeout as socket_timeout
from gevent import Timeout
from pysasl import SASLAuth
from six.moves import range
Expand All @@ -40,7 +38,7 @@
from .io import IO
from .extensions import Extensions
from .auth import ServerAuthError, AuthSession
from .reply import *
from .reply import * # NOQA

__all__ = ['Server']

Expand Down Expand Up @@ -157,7 +155,7 @@ def _get_message_data(self):
data = None
err = e

reply = Reply('250', '2.6.0 Message Accepted for Delivery')
reply = Reply('250', '2.6.0 Message accepted for delivery')
self._call_custom_handler('HAVE_DATA', reply, data, err)

self.io.send_reply(reply)
Expand Down Expand Up @@ -212,7 +210,7 @@ def handle(self):
break
except ConnectionLost:
raise
except Exception as e:
except Exception:
unhandled_error.send(self.io)
raise
finally:
Expand Down
4 changes: 2 additions & 2 deletions test/test_slimta_smtp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_recv_command(self):
self.assertEqual('ARG', arg)

def test_get_message_data(self):
expected_reply = b'250 2.6.0 Message Accepted for Delivery\r\n'
expected_reply = b'250 2.6.0 Message accepted for delivery\r\n'
self.sock.recv(IsA(int)).AndReturn(b'one\r\n')
self.sock.recv(IsA(int)).AndReturn(b'.\r\n')
self.sock.sendall(expected_reply)
Expand Down Expand Up @@ -280,7 +280,7 @@ def test_data(self):
self.sock.recv(IsA(int)).AndReturn(b'DATA\r\n')
self.sock.sendall(b'354 Start mail input; end with <CRLF>.<CRLF>\r\n')
self.sock.recv(IsA(int)).AndReturn(b'.\r\nQUIT\r\n')
self.sock.sendall(b'250 2.6.0 Message Accepted for Delivery\r\n')
self.sock.sendall(b'250 2.6.0 Message accepted for delivery\r\n')
self.sock.sendall(b'221 2.0.0 Bye\r\n')
self.mox.ReplayAll()
s = Server(self.sock, None)
Expand Down

0 comments on commit fb726f6

Please sign in to comment.