Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d1a30c9

Browse files
committed
#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.
1 parent 032eed3 commit d1a30c9

7 files changed

Lines changed: 482 additions & 91 deletions

File tree

Doc/library/smtpd.rst

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,24 @@ specific mail-sending strategies.
2020
Additionally the SMTPChannel may be extended to implement very specific
2121
interaction behaviour with SMTP clients.
2222

23+
The code supports :RFC:`5321`, plus the :rfc:`1870` SIZE extension.
24+
25+
2326
SMTPServer Objects
2427
------------------
2528

2629

27-
.. class:: SMTPServer(localaddr, remoteaddr)
30+
.. class:: SMTPServer(localaddr, remoteaddr, data_size_limit=33554432)
2831

2932
Create a new :class:`SMTPServer` object, which binds to local address
3033
*localaddr*. It will treat *remoteaddr* as an upstream SMTP relayer. It
3134
inherits from :class:`asyncore.dispatcher`, and so will insert itself into
3235
:mod:`asyncore`'s event loop on instantiation.
3336

37+
*data_size_limit* specifies the maximum number of bytes that will be
38+
accepted in a ``DATA`` command. A value of ``None`` or ``0`` means no
39+
limit.
40+
3441
.. method:: process_message(peer, mailfrom, rcpttos, data)
3542

3643
Raise :exc:`NotImplementedError` exception. Override this in subclasses to
@@ -155,16 +162,23 @@ SMTPChannel Objects
155162
Command Action taken
156163
======== ===================================================================
157164
HELO Accepts the greeting from the client and stores it in
158-
:attr:`seen_greeting`.
165+
:attr:`seen_greeting`. Sets server to base command mode.
166+
EHLO Accepts the greeting from the client and stores it in
167+
:attr:`seen_greeting`. Sets server to extended command mode.
159168
NOOP Takes no action.
160169
QUIT Closes the connection cleanly.
161170
MAIL Accepts the "MAIL FROM:" syntax and stores the supplied address as
162-
:attr:`mailfrom`.
171+
:attr:`mailfrom`. In extended command mode, accepts the
172+
:rfc:`1870` SIZE attribute and responds appropriately based on the
173+
value of ``data_size_limit``.
163174
RCPT Accepts the "RCPT TO:" syntax and stores the supplied addresses in
164175
the :attr:`rcpttos` list.
165176
RSET Resets the :attr:`mailfrom`, :attr:`rcpttos`, and
166177
:attr:`received_data`, but not the greeting.
167178
DATA Sets the internal state to :attr:`DATA` and stores remaining lines
168179
from the client in :attr:`received_data` until the terminator
169180
"\r\n.\r\n" is received.
181+
HELP Returns minimal information on command syntax
182+
VRFY Returns code 252 (the server doesn't know if the address is valid)
183+
EXPN Reports that the command is not implemented.
170184
======== ===================================================================

0 commit comments

Comments
 (0)