binary data such as images (as we'll see in the next sectionlike mail payload partsi headers are encoded specially for emailand may also be encoded per unicode for instancehere' how to decode an encoded subject line from an arguably spammish email that just showed up in my inboxits =?utf- ?qpreamble declares that the data following it is utf- encoded unicode textwhich is also mimeencoded per quoted-printable for transmission in email (in shortunlike the prior section' part payloadswhich declare their encodings in separate header linesheaders themselves may declare their unicode and mime encodings by embedding them in their own content this way)rawheader '=?utf- ? ?introducing= top= values= = = special= selecti on= of= great= money= savers?=from email header import decode_header decode per email+mime decode_header(rawheader[( 'introducing top valuesa special selection of great money savers''utf- ')binenc decode_header(rawheader)[ and decode per unicode binenc ( 'introducing top valuesa special selection of great money savers''utf- 'bin decode(enc'introducing top valuesa special selection of great money saverssubtlythe email package can return multiple parts if there are encoded substrings in the headerand each must be decoded individually and joined to produce decoded header text even more subtlyin this package returns all bytes when any substring (or the entire headeris encoded but returns str for fully unencoded headerand uncoded substrings returned as bytes are encoded per "raw-unicode-escapein the package--an encoding scheme useful to convert str to bytes when no encoding type appliesfrom email header import decode_header 'man where did you get that assistant? '=?utf- ? ?man_where_did_you_get_that_assistant= ?= 'man where did you get that =?utf- ? ?assistant= ?=strdon' decode(decode_header( [('man where did you get that assistant?'none)bytesdo decode(decode_header( [( 'man where did you get that assistant?''utf- ')bytesdo decode(using raw-unicode-escape applied in package decode_header( [( 'man where did you get that'none)( 'assistant?''utf- ')join decoded parts if more than one client-side scripting