Home | History | Annotate | Download | only in mime
      1 # Copyright (C) 2001-2006 Python Software Foundation
      2 # Author: Barry Warsaw
      3 # Contact: email-sig (at] python.org
      4 
      5 """Class representing message/* MIME documents."""
      6 
      7 __all__ = ['MIMEMessage']
      8 
      9 from email import message
     10 from email.mime.nonmultipart import MIMENonMultipart
     11 
     12 
     13 
     15 class MIMEMessage(MIMENonMultipart):
     16     """Class representing message/* MIME documents."""
     17 
     18     def __init__(self, _msg, _subtype='rfc822'):
     19         """Create a message/* type MIME document.
     20 
     21         _msg is a message object and must be an instance of Message, or a
     22         derived class of Message, otherwise a TypeError is raised.
     23 
     24         Optional _subtype defines the subtype of the contained message.  The
     25         default is "rfc822" (this is defined by the MIME standard, even though
     26         the term "rfc822" is technically outdated by RFC 2822).
     27         """
     28         MIMENonMultipart.__init__(self, 'message', _subtype)
     29         if not isinstance(_msg, message.Message):
     30             raise TypeError('Argument is not an instance of Message')
     31         # It's convenient to use this base class method.  We need to do it
     32         # this way or we'll get an exception
     33         message.Message.attach(self, _msg)
     34         # And be sure our default type is set correctly
     35         self.set_default_type('message/rfc822')
     36