blob: 275dbfd088652abedbf062ef99521261510141b4 [file] [log] [blame]
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001# Copyright (C) 2001-2006 Python Software Foundation
Barry Warsawbb113862004-10-03 03:16:19 +00002# Author: Barry Warsaw
3# Contact: email-sig@python.org
Barry Warsaw3dd978d2001-09-26 05:34:30 +00004
Barry Warsawbb113862004-10-03 03:16:19 +00005"""Class representing message/* MIME documents."""
Barry Warsaw3dd978d2001-09-26 05:34:30 +00006
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00007__all__ = ['MIMEMessage']
8
9from email import message
10from email.mime.nonmultipart import MIMENonMultipart
Barry Warsaw3dd978d2001-09-26 05:34:30 +000011
12
Barry Warsawe968ead2001-10-04 17:05:11 +000013
Barry Warsaw524af6f2002-06-02 19:05:08 +000014class MIMEMessage(MIMENonMultipart):
Barry Warsaw3dd978d2001-09-26 05:34:30 +000015 """Class representing message/* MIME documents."""
16
17 def __init__(self, _msg, _subtype='rfc822'):
18 """Create a message/* type MIME document.
19
20 _msg is a message object and must be an instance of Message, or a
21 derived class of Message, otherwise a TypeError is raised.
22
23 Optional _subtype defines the subtype of the contained message. The
24 default is "rfc822" (this is defined by the MIME standard, even though
25 the term "rfc822" is technically outdated by RFC 2822).
26 """
Barry Warsaw524af6f2002-06-02 19:05:08 +000027 MIMENonMultipart.__init__(self, 'message', _subtype)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000028 if not isinstance(_msg, message.Message):
Barry Warsawbb113862004-10-03 03:16:19 +000029 raise TypeError('Argument is not an instance of Message')
Barry Warsaw524af6f2002-06-02 19:05:08 +000030 # It's convenient to use this base class method. We need to do it
31 # this way or we'll get an exception
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000032 message.Message.attach(self, _msg)
Barry Warsawed53bdb2002-07-09 02:40:35 +000033 # And be sure our default type is set correctly
34 self.set_default_type('message/rfc822')