Barry Warsaw | bb11386 | 2004-10-03 03:16:19 +0000 | [diff] [blame] | 1 | # Copyright (C) 2001-2004 Python Software Foundation |
| 2 | # Author: Barry Warsaw |
| 3 | # Contact: email-sig@python.org |
Barry Warsaw | 3dd978d | 2001-09-26 05:34:30 +0000 | [diff] [blame] | 4 | |
Barry Warsaw | bb11386 | 2004-10-03 03:16:19 +0000 | [diff] [blame] | 5 | """Class representing message/* MIME documents.""" |
Barry Warsaw | 3dd978d | 2001-09-26 05:34:30 +0000 | [diff] [blame] | 6 | |
Barry Warsaw | 524af6f | 2002-06-02 19:05:08 +0000 | [diff] [blame] | 7 | from email import Message |
| 8 | from email.MIMENonMultipart import MIMENonMultipart |
Barry Warsaw | 3dd978d | 2001-09-26 05:34:30 +0000 | [diff] [blame] | 9 | |
| 10 | |
Barry Warsaw | e968ead | 2001-10-04 17:05:11 +0000 | [diff] [blame] | 11 | |
Barry Warsaw | 524af6f | 2002-06-02 19:05:08 +0000 | [diff] [blame] | 12 | class MIMEMessage(MIMENonMultipart): |
Barry Warsaw | 3dd978d | 2001-09-26 05:34:30 +0000 | [diff] [blame] | 13 | """Class representing message/* MIME documents.""" |
| 14 | |
| 15 | def __init__(self, _msg, _subtype='rfc822'): |
| 16 | """Create a message/* type MIME document. |
| 17 | |
| 18 | _msg is a message object and must be an instance of Message, or a |
| 19 | derived class of Message, otherwise a TypeError is raised. |
| 20 | |
| 21 | Optional _subtype defines the subtype of the contained message. The |
| 22 | default is "rfc822" (this is defined by the MIME standard, even though |
| 23 | the term "rfc822" is technically outdated by RFC 2822). |
| 24 | """ |
Barry Warsaw | 524af6f | 2002-06-02 19:05:08 +0000 | [diff] [blame] | 25 | MIMENonMultipart.__init__(self, 'message', _subtype) |
Barry Warsaw | 3dd978d | 2001-09-26 05:34:30 +0000 | [diff] [blame] | 26 | if not isinstance(_msg, Message.Message): |
Barry Warsaw | bb11386 | 2004-10-03 03:16:19 +0000 | [diff] [blame] | 27 | raise TypeError('Argument is not an instance of Message') |
Barry Warsaw | 524af6f | 2002-06-02 19:05:08 +0000 | [diff] [blame] | 28 | # It's convenient to use this base class method. We need to do it |
| 29 | # this way or we'll get an exception |
| 30 | Message.Message.attach(self, _msg) |
Barry Warsaw | ed53bdb | 2002-07-09 02:40:35 +0000 | [diff] [blame] | 31 | # And be sure our default type is set correctly |
| 32 | self.set_default_type('message/rfc822') |