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