example - implements the last major class in the mailtools package--given the (already decodedtext of an email messageits tools parse the mail' content into message objectwith headers and decoded parts this module is largely just wrapper around the standard library' email packagebut it adds convenience tools--finding the main text part of messagefilename generation for message partssaving attached parts to filesdecoding headerssplitting address listsand so on see the code for more information also notice the parts walker hereby coding its search logic in one place as generator functionwe guarantee that all its three clients hereas well as any others elsewhereimplement the same traversal unicode decoding for text part payloads and message headers this module also provides support for decoding message headers per email standards (both full headers and names in address headers)and handles decoding per text part encodings headers are decoded according to their contentusing tools in the email packagethe headers themselves give their mime and unicode encodingsso no user intervention is required for client conveniencewe also perform unicode decoding for main text parts to convert them from bytes to str here if needed the latter main-text decoding merits elaboration as discussed earlier in this message objects (main or attachedmay return their payloads as bytes if we fetch with decode= argumentor if they are bytes to begin within other casespayloads may be returned as str we generally need to decode bytes in order to treat payloads as text in mailtools itselfstr text part payloads are automatically encoded to bytes by decode= and then saved to binary-mode files to finesse encoding issuesbut main-text payloads are decoded to str if they are bytes this main-text decoding is performed per the encoding name in the part' message header (if present and correct)the platform defaultor guess as we learned in while guis may allow bytes for displaystr text generally provides broader unicode supportfurthermorestr is sometimes needed for later processing such as line wrapping and webpage generation since this package can' predict the role of other part payloads besides the main textclients are responsible for decoding and encoding as necessary for instanceother text parts which are saved in binary mode here may require that message headers be consulted later to extract unicode encoding names for better display for example' pymailgui will proceed this way to open text parts on demandpassing message header encoding information on to pyedit for decoding as text is loaded some of the to-text conversions performed here are potentially partial solutions (some parts may lack the required headers and fail per the platform defaultsand may need to be improvedsince this seems likely to be addressed in future release of python' email packagewe'll settle for our assumptions here client-side scripting