PyDocs

Nav

Internet Data Handling

decode_header

email.header

function (source)
  • decode_header(header)
Decode a message header value without converting charset.

For historical reasons, this function may return either:

1. A list of length 1 containing a pair (str, None).
2. A list of (bytes, 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.

header may be a string that may or may not contain RFC2047 encoded words,
or it may be a Header object.

An email.errors.HeaderParseError may be raised when certain decoding error
occurs (e.g. a base64 decoding exception).

This function exists for backwards compatibility only. For new code, we
recommend using email.headerregistry.HeaderRegistry instead.
1 Example
>>> from email.header import decode_header
>>> decode_header('=?iso-8859-1?q?p=F6stal?=')
[(b'p\xf6stal', 'iso-8859-1')]
>>> decode_header('unencoded_string')
[('unencoded_string', None)]
>>> decode_header('bar =?utf-8?B?ZsOzbw==?=')
[(b'bar ', None), (b'f\xc3\xb3o', 'utf-8')]
from the Python docs
See Also
No see-alsos for email.header/decode_header
0 Notes
No notes for decode_header