-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
bpo-28879: Add Date header if missing in smtplib send_message #5176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
elafontaine
wants to merge
1
commit into
python:main
Choose a base branch
from
elafontaine:bpo-28879
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -23,7 +23,7 @@ | |
| from test.support import hashlib_helper | ||
| from test.support import socket_helper | ||
| from test.support import threading_helper | ||
| from unittest.mock import Mock | ||
| from unittest.mock import Mock, patch | ||
|
|
||
| HOST = socket_helper.HOST | ||
|
|
||
|
|
@@ -1342,36 +1342,40 @@ def test_send_unicode_with_SMTPUTF8_via_low_level_API(self): | |
| self.assertEqual(self.serv.last_rcpt_options, []) | ||
|
|
||
| def test_send_message_uses_smtputf8_if_addrs_non_ascii(self): | ||
| msg = EmailMessage() | ||
| msg['From'] = "Páolo <fő[email protected]>" | ||
| msg['To'] = 'Dinsdale' | ||
| msg['Subject'] = 'Nudge nudge, wink, wink \u1F609' | ||
| # XXX I don't know why I need two \n's here, but this is an existing | ||
| # bug (if it is one) and not a problem with the new functionality. | ||
| msg.set_content("oh là là, know what I mean, know what I mean?\n\n") | ||
| # XXX smtpd converts received /r/n to /n, so we can't easily test that | ||
| # we are successfully sending /r/n :(. | ||
| expected = textwrap.dedent("""\ | ||
| From: Páolo <fő[email protected]> | ||
| To: Dinsdale | ||
| Subject: Nudge nudge, wink, wink \u1F609 | ||
| Content-Type: text/plain; charset="utf-8" | ||
| Content-Transfer-Encoding: 8bit | ||
| MIME-Version: 1.0 | ||
|
|
||
| oh là là, know what I mean, know what I mean? | ||
| """) | ||
| smtp = smtplib.SMTP( | ||
| HOST, self.port, local_hostname='localhost', | ||
| timeout=support.LOOPBACK_TIMEOUT) | ||
| self.addCleanup(smtp.close) | ||
| self.assertEqual(smtp.send_message(msg), {}) | ||
| self.assertEqual(self.serv.last_mailfrom, 'fő[email protected]') | ||
| self.assertEqual(self.serv.last_rcpttos, ['Dinsdale']) | ||
| self.assertEqual(self.serv.last_message.decode(), expected) | ||
| self.assertIn('BODY=8BITMIME', self.serv.last_mail_options) | ||
| self.assertIn('SMTPUTF8', self.serv.last_mail_options) | ||
| self.assertEqual(self.serv.last_rcpt_options, []) | ||
| expected_date = "Thu, 19 Mar 2020 00:59:43 -0000" | ||
| with patch("email.utils.formatdate") as date_mock: | ||
| date_mock.return_value = expected_date | ||
| msg = EmailMessage() | ||
| msg['From'] = "Páolo <fő[email protected]>" | ||
| msg['To'] = 'Dinsdale' | ||
| msg['Subject'] = 'Nudge nudge, wink, wink \u1F609' | ||
| # XXX I don't know why I need two \n's here, but this is an existing | ||
| # bug (if it is one) and not a problem with the new functionality. | ||
| msg.set_content("oh là là, know what I mean, know what I mean?\n\n") | ||
| # XXX smtpd converts received /r/n to /n, so we can't easily test that | ||
| # we are successfully sending /r/n :(. | ||
| expected = textwrap.dedent("""\ | ||
| From: Páolo <fő[email protected]> | ||
| To: Dinsdale | ||
| Subject: Nudge nudge, wink, wink \u1F609 | ||
| Content-Type: text/plain; charset="utf-8" | ||
| Content-Transfer-Encoding: 8bit | ||
| MIME-Version: 1.0 | ||
| Date: {} | ||
|
|
||
| oh là là, know what I mean, know what I mean? | ||
| """.format(expected_date)) | ||
| smtp = smtplib.SMTP( | ||
| HOST, self.port, local_hostname='localhost', | ||
| timeout=support.LOOPBACK_TIMEOUT) | ||
| self.addCleanup(smtp.close) | ||
| self.assertEqual(smtp.send_message(msg), {}) | ||
| self.assertEqual(self.serv.last_mailfrom, 'fő[email protected]') | ||
| self.assertEqual(self.serv.last_rcpttos, ['Dinsdale']) | ||
| self.assertEqual(self.serv.last_message.decode(), expected) | ||
| self.assertIn('BODY=8BITMIME', self.serv.last_mail_options) | ||
| self.assertIn('SMTPUTF8', self.serv.last_mail_options) | ||
| self.assertEqual(self.serv.last_rcpt_options, []) | ||
|
|
||
|
|
||
| EXPECTED_RESPONSE = encode_base64(b'\0psu\0doesnotexist', eol='') | ||
|
|
||
2 changes: 2 additions & 0 deletions
2
Misc/NEWS.d/next/Library/2018-01-13-15-52-00.bpo-28879.aW2gj0.rst
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Fix ``smtplib.send_message`` to add a ``Date`` header if it is missing as per | ||
| RFC5322. |
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.
Uh oh!
There was an error while loading. Please reload this page.