Skip to content

behaviour change with EmailMessage.set_content #85378

Closed

Description

@bremner
mannequin
BPO 41206
Nosy @warsaw, @doko42, @bitdancer, @ambv, @maxking, @tirkarthi, @ivyl
PRs
  • bpo-41206: Fix EmailMessage.set_content for empty content. #21349
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2020-07-09.00:13:38.485>
    created_at = <Date 2020-07-03.23:14:58.577>
    labels = ['3.8', 'expert-email', 'release-blocker']
    title = 'behaviour change with EmailMessage.set_content'
    updated_at = <Date 2020-07-09.00:13:38.483>
    user = 'https://bugs.python.org/bremner'

    bugs.python.org fields:

    activity = <Date 2020-07-09.00:13:38.483>
    actor = 'maxking'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-07-09.00:13:38.485>
    closer = 'maxking'
    components = ['email']
    creation = <Date 2020-07-03.23:14:58.577>
    creator = 'bremner'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 41206
    keywords = ['patch', '3.8regression', '3.9regression']
    message_count = 10.0
    messages = ['372971', '372979', '373080', '373099', '373101', '373110', '373113', '373115', '373248', '373361']
    nosy_count = 8.0
    nosy_names = ['barry', 'doko', 'r.david.murray', 'bremner', 'lukasz.langa', 'maxking', 'xtreak', 'ivyl']
    pr_nums = ['21349']
    priority = 'release blocker'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue41206'
    versions = ['Python 3.8']

    Activity

    1. bremner commented on Jul 3, 2020

      bremnermannequin
      MannequinAuthor

      Works in 3.8.3, but not in 3.8.4rc1

      from email.message import EmailMessage
      msg = EmailMessage()
      msg.set_content("")

      Apparently now at least one newline is required.

    2. tirkarthi commented on Jul 4, 2020

      @tirkarthi
      Member

      This is caused due to c1f1ddf introduced as part of bpo-40597 which is reported back in the issue with https://bugs.python.org/msg370395

    3. doko42 commented on Jul 6, 2020

      @doko42
      Member

      that's a regression for the 3.8 branch, marking as a release blocker for 3.8.4. This should be a documented change for 3.9, and probably reverted/fixed for 3.8.

    4. ambv commented on Jul 6, 2020

      @ambv
      Contributor

      Good catch!

      No need to revert anything. The raised ValueError is a relatively simple thing to fix. xtreak, mind making a follow-up PR to restore behavior with no \n characters?

    5. tirkarthi commented on Jul 6, 2020

      @tirkarthi
      Member

      Sure, I guess the fix would be to check for lines to be non-empty before doing a call to max and also convert the report as a test case?

    6. tirkarthi commented on Jul 6, 2020

      @tirkarthi
      Member

      There is a behavior change with my fix. 7bit is returned for Content-Transfer-Encoding before commit and skipping the heuristic if line is empty to avoid ValueError will return quoted-printable for Content-Transfer-Encoding. This is a behavior change even if the ValueError is fixed. I would like to confirm which is the correct behavior and to be documented appropriately.

      Test Case in test_contentmanager.py :

          def test_set_text_plain_empty_content_heuristics(self):
              m = self._make_message()
              content = ""
              raw_data_manager.set_content(m, content)
              self.assertEqual(str(m), textwrap.dedent("""\                             
                  Content-Type: text/plain; charset="utf-8"                             
                  Content-Transfer-Encoding: quoted-printable                           
                                                                                        
                                                                                        
                  """))
              self.assertEqual(m.get_payload(decode=True).decode('utf-8'), "\n")
              self.assertEqual(m.get_content(), "\n")
    7. ambv commented on Jul 6, 2020

      @ambv
      Contributor

      Yes.

    8. tirkarthi commented on Jul 6, 2020

      @tirkarthi
      Member

      Łukasz, There is already a PR open for this from May linking to original issue at #20542 . I missed it during triaging this issue. I guess someone needs to approve that PR and merge it to master to backport to 3.9 and 3.8 to fix the error.

    9. bitdancer commented on Jul 7, 2020

      @bitdancer
      Member

      I'm short of time, if someone could approve Mark's PR and merge it it would be great. There wasn't supposed to be any behavior change other than the one documented in bpo-40597.

    10. maxking commented on Jul 9, 2020

      @maxking
      Contributor

      I have merged #20542 and backported to 3.8 and 3.9 branches (#21404 & #21405).

      Closing this issue.

    11. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions