Skip to content

Commit 3c526b4

Browse files
gh-61707: Clarify that Header.__str__() does not decode RFC 2047 encoded words
1 parent ce841a9 commit 3c526b4

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

‎Doc/library/email.header.rst‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,16 @@ Here is the :class:`Header` class description:
155155
charset of ``'unknown-8bit'`` are decoded as ASCII using the ``'replace'``
156156
error handler.
157157

158+
This does not decode :rfc:`2047` encoded words that appear in the header
159+
value itself. For example,
160+
``str(Header('=?utf-8?q?Caf=C3=A9?='))`` returns the string unchanged.
161+
To decode a raw header string, use :func:`decode_header` and
162+
:func:`make_header`::
163+
164+
>>> from email.header import decode_header, make_header
165+
>>> str(make_header(decode_header('=?utf-8?q?Caf=C3=A9?=')))
166+
'Café'
167+
158168
.. versionchanged:: 3.2
159169
Added handling for the ``'unknown-8bit'`` charset.
160170

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Clarify that :meth:`email.header.Header.__str__` does not decode :rfc:`2047`
2+
encoded words, and point to :func:`email.header.decode_header` and
3+
:func:`email.header.make_header` for decoding raw header strings.

0 commit comments

Comments
 (0)