today it seems the best we can do hereapart from hoping for an improved email package in few yearstimeis to specialize text message construction calls by unicode typeand assume both that encoding names match those expected by the package and that message data is valid for the unicode type selected here is the sort of arguably magic code that the upcoming mailtools package (again in example - will apply to choose text typesfrom email charset import charsetbase qp for in ('us-ascii''latin- ''utf ''latin ''ascii')cset charset(ebenc cset body_encoding if benc in (noneqp)print(ebenc'text'read/fetch data as str elseprint(ebenc'binary'read/fetch data as bytes us-ascii none text latin- text utf binary latin binary ascii none text we'll proceed this way in this bookwith the major caveat that this is almost certainly likely to require changes in the future because of its strong coupling with the current email implementation late-breaking newslike the prior sectionit now appears that this section' bug will also be fixed in python making the workaround here unnecessary in this and later python releases the nature of the fix is unknownthoughand we still need the fix for the version of python current when this was written as of just before publicationthe alpha release of is still somewhat type specific on this issuebut now accepts either str or bytes for text that triggers base encodingsinstead of just bytes summarysolutions and workarounds the email package in python provides powerful tools for parsing and composing mailsand can be used as the basis for full-featured mail clients like those in this book with just few workarounds as you can seethoughit is less than fully functional today because of thatfurther specializing code to its current api is perhaps temporary solution short of writing our own email parser and composer (not practical option in finitely-sized book!)some compromises are in order here moreoverthe inherent complexity of unicode support in email places some limits on how much we can pursue this thread in this book client-side scripting