diff --git a/jaraco/email/smtp.py b/jaraco/email/smtp.py index 2b071cf..ba75bb4 100644 --- a/jaraco/email/smtp.py +++ b/jaraco/email/smtp.py @@ -1,7 +1,8 @@ -import smtpd -import asyncore +import asyncio import argparse +from aiosmtpd.controller import Controller + def _get_args(): p = argparse.ArgumentParser() @@ -9,18 +10,17 @@ def _get_args(): return p.parse_args() -class DebuggingServer(smtpd.DebuggingServer): - def process_message(self, peer, mailfrom, rcpttos, data): - # seriously, why doesn't a debugging server just print everything? - print('peer:', peer) - print('mailfrom:', mailfrom) - print('rcpttos:', rcpttos) - smtpd.DebuggingServer.process_message(self, peer, mailfrom, rcpttos, data) +class DebuggingHandler: + async def handle_DATA(self, server, session, envelope): + print('peer:', session.peer) + print('mailfrom:', envelope.mail_from) + print('rcpttos:', envelope.rcpt_tos) + return '250 OK' def start_simple_server(): "A simple mail server that sends a simple response" args = _get_args() - addr = ('', args.port) - DebuggingServer(addr, None) - asyncore.loop() + controller = Controller(DebuggingHandler(), hostname='', port=args.port) + controller.start() + asyncio.new_event_loop().run_forever() diff --git a/setup.cfg b/setup.cfg index b7b90a3..d354dc3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -20,6 +20,7 @@ install_requires = jaraco.text>=1.3 jaraco.collections keyring + aiosmtpd [options.packages.find] exclude =