""##############################################################################common superclassesused to turn trace massages on/off ##############################################################################""class mailtooldef trace(selfmessage)print(messagesuperclass for all mail tools redef me to disable or log to file class silentmailtooldef trace(selfmessage)pass to mixin instead of subclassing mailsender class the class used to compose and send messages is coded in example - this module provides convenient interface that combines standard library tools we've already met in this -the email package to compose messages with attachments and encodingsand the smtplib module to send the resulting email text attachments are passed in as list of filenames--mime types and any required encodings are determined automatically with the module mimetypes moreoverdate and time strings are automated with an email utils calland non-ascii headers are encoded per emailmimeand unicode standards study this file' code and comments for more on its operation unicode issues for attachmentssave filesand headers this is also where we open and add attachment filesgenerate message textand save sent messages to local file most attachment files are opened in binary modebut as we've seensome text attachments must be opened in text mode because the current email package requires them to be str strings when message objects are created as we also saw earlierthe email package requires attachments to be str text when mail text is later generatedpossibly as the result of mime encoding to satisfy these constraints with the python email packagewe must apply the two fixes described earlier-part file open calls select between text or binary mode (and thus read str or bytesbased upon the way email will process the dataand mime encoding calls for binary data are augmented to decode the result to ascii text the latter of these also splits the base text into lines here for binary parts (unlike email)because it is otherwise sent as one long linewhich may work in some contextsbut causes problems in some text editors if the raw text is viewed beyond these fixesclients may optionally provide the names of the unicode encoding scheme associated with the main text part and each text attachment part in ' pymailguithis is controlled in the mailconfig user settings modulewith utf- used as fallback default whenever user settings fail to encode text part we the mailtools utility package