#8739: upgrade smtpd to RFC 5321 and 1870.

smtpd now handles EHLO and has infrastructure for extended smtp command mode.
The SIZE extension is also implemented.  In order to support parameters on
MAIL FROM, the RFC 5322 parser from the email package is used to parse the
address "token".

Logging subclasses things and overrides __init__, so it was necessary to
update those __init__ functions in the logging tests to make the logging tests
pass.

The original suggestion and patch were by Alberto Trevino.  Juhana Jauhiainen
added the --size argument and SIZE parameter support.  Michele Orrù improved
the patch and added more tests.  Dan Boswell conditionalized various bits of
code on whether or not we are in HELO or EHLO mode, as well as some other
improvements and tests.  I finalized the patch and added the address parsing.
This commit is contained in:
R David Murray 2012-05-26 14:33:59 -04:00
parent 032eed3c4a
commit d1a30c939c
7 changed files with 483 additions and 92 deletions

View file

@ -20,17 +20,24 @@ specific mail-sending strategies.
Additionally the SMTPChannel may be extended to implement very specific
interaction behaviour with SMTP clients.
The code supports :RFC:`5321`, plus the :rfc:`1870` SIZE extension.
SMTPServer Objects
------------------
.. class:: SMTPServer(localaddr, remoteaddr)
.. class:: SMTPServer(localaddr, remoteaddr, data_size_limit=33554432)
Create a new :class:`SMTPServer` object, which binds to local address
*localaddr*. It will treat *remoteaddr* as an upstream SMTP relayer. It
inherits from :class:`asyncore.dispatcher`, and so will insert itself into
:mod:`asyncore`'s event loop on instantiation.
*data_size_limit* specifies the maximum number of bytes that will be
accepted in a ``DATA`` command. A value of ``None`` or ``0`` means no
limit.
.. method:: process_message(peer, mailfrom, rcpttos, data)
Raise :exc:`NotImplementedError` exception. Override this in subclasses to
@ -155,11 +162,15 @@ SMTPChannel Objects
Command Action taken
======== ===================================================================
HELO Accepts the greeting from the client and stores it in
:attr:`seen_greeting`.
:attr:`seen_greeting`. Sets server to base command mode.
EHLO Accepts the greeting from the client and stores it in
:attr:`seen_greeting`. Sets server to extended command mode.
NOOP Takes no action.
QUIT Closes the connection cleanly.
MAIL Accepts the "MAIL FROM:" syntax and stores the supplied address as
:attr:`mailfrom`.
:attr:`mailfrom`. In extended command mode, accepts the
:rfc:`1870` SIZE attribute and responds appropriately based on the
value of ``data_size_limit``.
RCPT Accepts the "RCPT TO:" syntax and stores the supplied addresses in
the :attr:`rcpttos` list.
RSET Resets the :attr:`mailfrom`, :attr:`rcpttos`, and
@ -167,4 +178,7 @@ SMTPChannel Objects
DATA Sets the internal state to :attr:`DATA` and stores remaining lines
from the client in :attr:`received_data` until the terminator
"\r\n.\r\n" is received.
HELP Returns minimal information on command syntax
VRFY Returns code 252 (the server doesn't know if the address is valid)
EXPN Reports that the command is not implemented.
======== ===================================================================