Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 33.9k
gh-73065: Add Date header if missing in smtplib send_message#136850
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
base:main
Are you sure you want to change the base?
Changes from all commits
6cfbdc6baf50255ffc0984c2353cc9e2af2a9cd436a4bc9c7f960ab20e6ec22be698653a8abdd00c870a6a5188ebcfe9d2a9da40eFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1467,6 +1467,7 @@ def test_send_unicode_with_SMTPUTF8_via_low_level_API(self): | ||
| self.assertIn('SMTPUTF8', self.serv.last_mail_options) | ||
| self.assertEqual(self.serv.last_rcpt_options, []) | ||
| @support.run_with_tz('UTC-02') | ||
| def test_send_message_uses_smtputf8_if_addrs_non_ascii(self): | ||
| msg = EmailMessage() | ||
| msg['From'] = "Páolo <főo@bar.com>" | ||
| @@ -1477,24 +1478,35 @@ def test_send_message_uses_smtputf8_if_addrs_non_ascii(self): | ||
| 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 :(. | ||
| smtp = smtplib.SMTP( | ||
| HOST, self.port, local_hostname='localhost', | ||
| timeout=support.LOOPBACK_TIMEOUT) | ||
| self.addCleanup(smtp.close) | ||
| self.assertEqual(smtp.send_message(msg),{}) | ||
| last_message = self.serv.last_message.decode() | ||
| date = email.message_from_string(last_message)['Date'] | ||
| # asserts RFC 5322 section 3.3 4th Paragraph | ||
| self.assertEqual( | ||
| email.utils.parsedate_to_datetime(date).tzname(), | ||
| "UTC+02:00" | ||
| ) | ||
| expected = textwrap.dedent("""\ | ||
| From: Páolo <főo@bar.com> | ||
| 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? | ||
| """) | ||
| smtp = smtplib.SMTP( | ||
| HOST, self.port, local_hostname='localhost', | ||
| timeout=support.LOOPBACK_TIMEOUT) | ||
| self.addCleanup(smtp.close) | ||
| self.assertEqual(smtp.send_message(msg),{}) | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am moving these assertions further up so that I can extract the date from the message in order to build the | ||
| """.format(date)) | ||
| self.assertEqual(self.serv.last_mailfrom, 'főo@bar.com') | ||
| self.assertEqual(self.serv.last_rcpttos, ['Dinsdale']) | ||
| self.assertEqual(self.serv.last_message.decode(), expected) | ||
| self.assertEqual(last_message, 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, []) | ||
| 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 :rfc:`5322`. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.