Barry Warsaw pushed to branch master at mailman / Mailman
Commits: 845eaedf by Barry Warsaw at 2017-04-06T18:58:44-04:00 Port to aiosmtpd 1.0a5 - - - - - d4f8bac7 by Barry Warsaw at 2017-04-07T14:00:52+00:00 Merge branch 'aiosmtpd10a5' into 'master' Port to aiosmtpd 1.0a5 See merge request !257 - - - - - 2 changed files: - src/mailman/runners/lmtp.py - src/mailman/testing/mta.py Changes: ===================================== src/mailman/runners/lmtp.py ===================================== --- a/src/mailman/runners/lmtp.py +++ b/src/mailman/runners/lmtp.py @@ -35,7 +35,7 @@ so that the peer mail server can provide better diagnostics. """ import email -import socket +import asyncio import logging from aiosmtpd.controller import Controller @@ -122,19 +122,20 @@ def split_recipient(address): class LMTPHandler: + @asyncio.coroutine @transactional - def process_message(self, peer, mailfrom, rcpttos, data, **kwargs): + def handle_DATA(self, server, session, envelope): try: # Refresh the list of list names every time we process a message # since the set of mailing lists could have changed. listnames = set(getUtility(IListManager).names) # Parse the message data. If there are any defects in the # message, reject it right away; it's probably spam. - msg = email.message_from_bytes(data, Message) + msg = email.message_from_bytes(envelope.content, Message) except Exception: elog.exception('LMTP message parsing') config.db.abort() - return CRLF.join(ERR_451 for to in rcpttos) + return CRLF.join(ERR_451 for to in envelope.rcpt_tos) # Do basic post-processing of the message, checking it for defects or # other missing information. message_id = msg.get('message-id') @@ -142,9 +143,9 @@ class LMTPHandler: return ERR_550_MID if msg.defects: return ERR_501 - msg.original_size = len(data) + msg.original_size = len(envelope.content) add_message_hash(msg) - msg['X-MailFrom'] = mailfrom + msg['X-MailFrom'] = envelope.mail_from # RFC 2033 requires us to return a status code for every recipient. status = [] # Now for each address in the recipients, parse the address to first @@ -152,7 +153,7 @@ class LMTPHandler: # the message to the appropriate place and record a 250 status for # that recipient. If not, record a failure status for that recipient. received_time = now() - for to in rcpttos: + for to in envelope.rcpt_tos: try: to = parseaddr(to)[1].lower() local, subaddress, domain = split_recipient(to) @@ -219,11 +220,6 @@ class LMTPController(Controller): server.__ident__ = 'GNU Mailman LMTP runner 2.0' return server - def make_socket(self): - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True) - return sock - @public class LMTPRunner(Runner): ===================================== src/mailman/testing/mta.py ===================================== --- a/src/mailman/testing/mta.py +++ b/src/mailman/testing/mta.py @@ -17,7 +17,6 @@ """Fake MTA for testing purposes.""" -import socket import asyncio import smtplib @@ -54,6 +53,17 @@ class ConnectionCountingHandler(MessageHandler): def handle_message(self, message): self._msg_queue.put(message) + @asyncio.coroutine + def handle_EHLO(self, server, session, envelope, hostname): + session.host_name = hostname + yield from server.push('250-AUTH PLAIN') + return '250 HELP' + + @asyncio.coroutine + def handle_RSET(self, server, session, envelope): + self.connection_count = 0 + return '250 OK' + class ConnectionCountingSMTP(SMTP): def __init__(self, handler, oob_queue, err_queue, *args, **kws): @@ -96,14 +106,6 @@ class ConnectionCountingSMTP(SMTP): yield from self.push('571 Bad authentication') @asyncio.coroutine - def ehlo_hook(self): - yield from self.push('250-AUTH PLAIN') - - @asyncio.coroutine - def rset_hook(self): - self.event_handler.connection_count = 0 - - @asyncio.coroutine def smtp_STAT(self, arg): """Cause the server to send statistics to its controller.""" # Do not count the connection caused by the STAT connect. @@ -175,11 +177,6 @@ class ConnectionCountingController(Controller): return ConnectionCountingSMTP( self.handler, self._oob_queue, self.err_queue) - def make_socket(self): - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True) - return sock - def start(self): super().start() # Reset the connection statistics, since the base class's start() View it on GitLab: https://gitlab.com/mailman/mailman/compare/263711b3b7988c7c474e3b8952dc7e0f02f04fa2...d4f8bac7cc5a85b177f122ba78f3f837238027f6
_______________________________________________ Mailman-checkins mailing list Mailman-checkins@python.org Unsubscribe: https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org