c 20012006 python software foundation barry warsaw contact emailsigpython org class representing text type mime documents all mimetext from email mime nonmultipart import mimenonmultipart class mimetextmimenonmultipart create a text type mime document text is the string for this message object subtype is the mime sub content type defaulting to plain charset is the character set parameter added to the contenttype header this defaults to usascii note that as a sideeffect the contenttransferencoding header will also be set if no charset was specified check to see if there are nonascii characters present if not use usascii otherwise use utf8 xxx this can be removed once 7304 is fixed c 2001 2006 python software foundation barry warsaw contact email sig python org class representing text type mime documents class for generating text type mime documents create a text type mime document _text is the string for this message object _subtype is the mime sub content type defaulting to plain _charset is the character set parameter added to the content type header this defaults to us ascii note that as a side effect the content transfer encoding header will also be set if no _charset was specified check to see if there are non ascii characters present if not use us ascii otherwise use utf 8 xxx this can be removed once 7304 is fixed
__all__ = ['MIMEText']

from email.mime.nonmultipart import MIMENonMultipart


class MIMEText(MIMENonMultipart):
    

    def __init__(self, _text, _subtype='plain', _charset=None, *, policy=None):
        

        
        
        
        if _charset is None:
            try:
                _text.encode('us-ascii')
                _charset = 'us-ascii'
            except UnicodeEncodeError:
                _charset = 'utf-8'

        MIMENonMultipart.__init__(self, 'text', _subtype, policy=policy,
                                  charset=str(_charset))

        self.set_payload(_text, _charset)