Skip to content

email module incorrectly qp-encodes References and In-Reply-To headers #100991

@mricon

Description

@mricon

Bug report

import email
import email.policy

msg = email.message.EmailMessage()
msg['Message-Id'] = '<long-but-perfectly-valid-message-id-that-does-not-end-up-qp-encoded@example.com>'
msg['References'] = '<reference-to-long-but-perfectly-valid-message-id-that-gets-qp-encoded@example.com>'
msg['In-Reply-To'] = '<reference-to-long-but-perfectly-valid-message-id-that-gets-qp-encoded@example.com>'
msg.set_payload('No body')

bdata = msg.as_bytes(policy=email.policy.SMTP)
print(bdata.decode())

Expected output:

Message-Id: <long-but-perfectly-valid-message-id-that-does-not-end-up-qp-encoded@example.com>
References: <reference-to-long-but-perfectly-valid-message-id-that-gets-qp-encoded@example.com>
In-Reply-To: <reference-to-long-but-perfectly-valid-message-id-that-gets-qp-encoded@example.com>

No body

Actual output:

Message-Id: <long-but-perfectly-valid-message-id-that-does-not-end-up-qp-encoded@example.com>
References: =?utf-8?q?=3Creference-to-long-but-perfectly-valid-message-id-th?=
 =?utf-8?q?at-gets-qp-encoded=40example=2Ecom=3E?=
In-Reply-To: =?utf-8?q?=3Creference-to-long-but-perfectly-valid-message-id-t?=
 =?utf-8?q?hat-gets-qp-encoded=40example=2Ecom=3E?=

No body

Your environment

  • CPython versions tested on: 3.11.1
  • Operating system and architecture: Fedora 37 x86_64

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions