Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-67022: Improve email.header.decode_header() documentation #95020

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions Doc/library/email.header.rst
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,24 @@ The :mod:`email.header` module also provides the following convenient functions.
Decode a message header value without converting the character set. The header
value is in *header*.

This function returns a list of ``(decoded_string, charset)`` pairs containing
each of the decoded parts of the header. *charset* is ``None`` for non-encoded
parts of the header, otherwise a lower case string containing the name of the
character set specified in the encoded string.
In case the original header is unencoded, this returns a list with one
element with a ``(original_header, None)`` pair, where the first element
is a ``str``. In case at least one element is encoded, this function
returns a list of ``(decoded_string, charset)`` pairs containing each of
the decoded parts of the header. *decoded_string* is a ``bytes``.
*charset* is ``None`` for non-encoded parts of the header, otherwise a
lower case ``str`` containing the name of the character set specified in
the encoded string.

Here's an example::

>>> from email.header import decode_header
>>> decode_header('=?iso-8859-1?q?p=F6stal?=')
[(b'p\xf6stal', 'iso-8859-1')]
>>> decode_header('Eierloffel')
[('Eierloffel', None)]
>>> decode_header('=?utf-8?q?Eierl=C3=B6ffel?=')
[(b'Eierl\xc3\xb6ffel', 'utf-8')]
>>> decode_header('Eier=?utf-8?q?l=C3=B6ffel?=')
[(b'Eier', None), (b'l\xc3\xb6ffel', 'utf-8')]


.. function:: make_header(decoded_seq, maxlinelen=None, header_name=None, continuation_ws=' ')
Expand Down