-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port the simple SMTP server to aiosmtpd. It's untested but at least a…
…llows some test suites to pass.
- Loading branch information
Showing
2 changed files
with
13 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
import smtpd | ||
import asyncore | ||
import asyncio | ||
import argparse | ||
|
||
from aiosmtpd.controller import Controller | ||
|
||
|
||
def _get_args(): | ||
p = argparse.ArgumentParser() | ||
p.add_argument('-p', '--port', type=int, help="Bind to port", default=25) | ||
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters