c 20012006 python software foundation barry warsaw contact emailsigpython org class representing message mime documents all mimemessage from email import message from email mime nonmultipart import mimenonmultipart class mimemessagemimenonmultipart create a message type mime document msg is a message object and must be an instance of message or a derived class of message otherwise a typeerror is raised optional subtype defines the subtype of the contained message the default is rfc822 this is defined by the mime standard even though the term rfc822 is technically outdated by rfc 2822 it s convenient to use this base class method we need to do it this way or we ll get an exception and be sure our default type is set correctly c 2001 2006 python software foundation barry warsaw contact email sig python org class representing message mime documents class representing message mime documents create a message type mime document _msg is a message object and must be an instance of message or a derived class of message otherwise a typeerror is raised optional _subtype defines the subtype of the contained message the default is rfc822 this is defined by the mime standard even though the term rfc822 is technically outdated by rfc 2822 it s convenient to use this base class method we need to do it this way or we ll get an exception and be sure our default type is set correctly
__all__ = ['MIMEMessage']

from email import message
from email.mime.nonmultipart import MIMENonMultipart


class MIMEMessage(MIMENonMultipart):
    

    def __init__(self, _msg, _subtype='rfc822', *, policy=None):
        
        MIMENonMultipart.__init__(self, 'message', _subtype, policy=policy)
        if not isinstance(_msg, message.Message):
            raise TypeError('Argument is not an instance of Message')
        
        
        message.Message.attach(self, _msg)
        
        self.set_default_type('message/rfc822')