by the parser and attached to the message object this is especially important if we need to save the data to file--we either have to store as bytes in binary mode filesor specify the correct (or at least compatibleunicode encoding in order to use such strings for text-mode files decoding manually works the same wayq get_payload(decode= decode(unicodedecodeerror'utf codec can' decode bytes in position - unexpected get_content_charset('latin get_payload(decode= decode('latin ''aabq get_payload(decode= decode( get_content_charset()'aabknown type allow any type in factall the header details are available on message objectsif we know where to look the character set can also be absent entirelyin which case it' returned as noneclients need to define policies for such ambiguous text (they might try common typesguessor treat the data as raw byte string) ['content-type'mapping interface 'text/plaincharset="latin " items([('content-type''text/plaincharset="latin "')('mime-version'' ')('content-transfer-encoding''base ')> get_params(header='content-type'[('text/plain''')('charset''latin ') get_param('charset'header='content-type''latin param interface charset get_content_charset(if charsetprint( get_payload(decode= decode(charset)aab might be missing this handles encodings for message text parts in parsed emails for composing new emailswe still must apply session-wide user settings or allow the user to specify an encoding for each part interactively in some of this book' email clientspayload conversions are performed as needed--using encoding information in message headers after parsing and provided by users during mail composition message header encodingsemail package support on related notethe email package also provides support for encoding and decoding message headers themselves ( fromsubjectper email standards when they are not simple text such headers are often called internationalized (or nheadersbecause they support inclusion of non-ascii character set text in emails this term is also sometimes used to refer to encoded text of message payloadsunlike message headersemailparsing and composing mail content