Skip to content

bpo-32814: Handle 8BITMIME availabilty in smtplib.SMTP.send_message#8303

Open
segevfiner wants to merge 6 commits intopython:mainfrom
segevfiner:bpo-32814-8bitmime-handling
Open

bpo-32814: Handle 8BITMIME availabilty in smtplib.SMTP.send_message#8303
segevfiner wants to merge 6 commits intopython:mainfrom
segevfiner:bpo-32814-8bitmime-handling

Conversation

@segevfiner
Copy link
Copy Markdown
Contributor

@segevfiner segevfiner commented Jul 16, 2018

If the policy requests an 8bit content transfer encoding, than we will check for the 8BITMIME (RFC6152) extension and use it if available. Otherwise we will use a 7bit content transfer encoding since the server doesn't support 8bit messages.

Hopefully I got this right... RFCs tend to be long/verbose, and considering extensions, what you need to read is essentially spread across multiple RFCs with no central location that links them all, well... at least one that I could find that is.

Note the weird behavior in the tests regarding Content-Transfer-Encoding. One test ends up using quoted-printable while the other base64. I didn't dig into why...

@bitdancer

https://bugs.python.org/issue32814

… the policy requests an 8bit content transfer encoding, than we willcheck for the 8BITMIME extension and use it if available. Otherwise wewill use a 7bit content transfer encoding since the server doesn'tsupport 8bit messages.
@segevfiner segevfiner force-pushed the bpo-32814-8bitmime-handling branch from d3a75d4 to f1d84c0 Compare July 16, 2018 21:24
Copy link
Copy Markdown
Member

@bitdancer bitdancer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch. I have a few suggestions, but for the most part it looks good.

Comment thread Doc/library/smtplib.rst
Support for internationalized addresses (``SMTPUTF8``).

.. versionadded:: 3.8
Handling ``8BITMIME`` (:rfc:`6152`) availability automatically.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a bug fix, not a new feature.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's kinda both, hard to decide... 😛

I documented this like this since it's a breaking change. Do you think it should be documented differently? If so, then how?

Comment thread Lib/smtplib.py Outdated
to_addrs = [a[1] for a in email.utils.getaddresses(addr_fields)]
# Make a local copy so we can delete the bcc headers.
msg_copy = copy.copy(msg)
policy = msg.policy.clone()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There doesn't appear to be any reason to make an unchanged clone here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't. I think I originally intended to clone once and modify as needed, but later figured that Policy objects are immutable and forgot to remove this.

Comment thread Lib/test/test_logging.py
self.assertEqual(rcpttos, ['you'])
self.assertIn('\nSubject: Log\n', data)
self.assertTrue(data.endswith('\n\nHello \u2713'))
self.assertTrue(data.endswith('\n\nSGVsbG8g4pyTCg=='))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is problematic. I'm guessing the test server needs to be told to support utf8 so the test itself doesn't change, but I haven't looked at the code. Regardless, we'd need to get Vinay Sajep to sign off on any changes here.

Copy link
Copy Markdown
Contributor Author

@segevfiner segevfiner Jul 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this like this because the SMTP server used in this tests uses decode_data=True which makes it not support 8BITMIME. See smtpd.SMTPServer's documentation. What's the correct fix for this is open for discussion.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, OK, then not using decode_data=True would be the right fix. decode_data=True is deprecated.

Comment thread Lib/test/test_smtplib.py Outdated
self.addCleanup(smtp.close)
self.assertRaises(smtplib.SMTPNotSupportedError,
smtp.send_message(msg))
lambda: smtp.send_message(msg))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assertRaises call should read self.assertRaises(smtplib.SMTPNotSupportedError, smtp.send_message, msg). The fact that this test isn't failing as-is means it isn't being run, which is issue #32663, and we should fix that one before applying your patch.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After I changed this. I saw you merged a fix for bpo-32663. I will merge.

Comment thread Lib/smtplib.py Outdated
if policy.cte_type == '8bit':
if self.has_extn('8bitmime'):
if 'BODY=8BITMIME' not in mail_options:
mail_options.append('BODY=8BITMIME')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we could end up appending BODY=8BITMIME twice (once in the except, and then again here). Probably want to keep the international flag and append SMTPUTF8 iff it is true.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I called the boolean differently since this is about an 8-bit body and not about internationalized mail.

Comment thread Lib/smtplib.py Outdated
# Make a local copy so we can delete the bcc headers.
msg_copy = copy.copy(msg)
policy = msg.policy.clone()
mail_options = mail_options[:]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this line up to the top of the function, please. I'm not sure how those default argument values got pass the original review; I thought there was an issue to fix them but I can't find it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@bedevere-bot
Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

And if you don't make the requested changes, you will be poked with soft cushions!

@segevfiner
Copy link
Copy Markdown
Contributor Author

I have made the requested changes; please review again.

Well... except the ones I wasn't sure about and left a reply that is...

@bedevere-bot
Copy link
Copy Markdown

Thanks for making the requested changes!

@bitdancer: please review the changes made to this pull request.

@csabella csabella requested a review from bitdancer May 31, 2019 11:19
@csabella
Copy link
Copy Markdown
Contributor

cc @maxking

@csabella csabella requested a review from maxking October 20, 2019 19:51
@emersion
Copy link
Copy Markdown

Hi, any chance to get this merged?

@ddevault
Copy link
Copy Markdown

Seconding the bump

@github-actions
Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting change review stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants