gh-76984: Handle DATA correctly for LMTP with multiple RCPT #18896
+145
−9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Conform RFC 2033, the LMTP protocol gives for each successful recipient a reply.
The smtplib only reads one. This gives problems sending more than one message
with multiple recipients in a connection. See https://bugs.python.org/issue32803
To be backwards compatible, I added a new method
multi_data
to support aDATA
command with multiple replies. I modeled it afterdata
and wanted to keep the error handling in thesendmail
method. Because we need to close the connection once we receive a 421, I chose to yield the results instead of returning a list. Similar to the multiple RCTP solution, I only raise an Exception if all recipients fail.I am not sure about the naming of
LMTPDataError
. It breaks the structure of all errors beginning with LMTP, but it is really a specific LMTP error. An alternative could beSMTPMultiDataError
.I also fixed the assertion in
test_421_from_data_cmd
. I think it should comparerset_count
and notrcpt_count
. Thercpt_count
is only modified ifrcpt_response
is used. The purpose of the test is to be sure the method closed instead of reset.https://bugs.python.org/issue32803