Guido van Rossum | 8b3febe | 2007-08-30 01:15:14 +0000 | [diff] [blame] | 1 | # Copyright (C) 2002-2006 Python Software Foundation |
| 2 | # Author: Barry Warsaw |
| 3 | # Contact: email-sig@python.org |
| 4 | |
| 5 | """Base class for MIME multipart/* type messages.""" |
| 6 | |
| 7 | __all__ = ['MIMEMultipart'] |
| 8 | |
| 9 | from email.mime.base import MIMEBase |
| 10 | |
| 11 | |
| 12 | |
| 13 | class MIMEMultipart(MIMEBase): |
| 14 | """Base class for MIME multipart/* type messages.""" |
| 15 | |
| 16 | def __init__(self, _subtype='mixed', boundary=None, _subparts=None, |
R David Murray | 56b1f1b | 2016-09-07 16:48:35 -0400 | [diff] [blame] | 17 | *, policy=None, |
Guido van Rossum | 8b3febe | 2007-08-30 01:15:14 +0000 | [diff] [blame] | 18 | **_params): |
| 19 | """Creates a multipart/* type message. |
| 20 | |
| 21 | By default, creates a multipart/mixed message, with proper |
| 22 | Content-Type and MIME-Version headers. |
| 23 | |
| 24 | _subtype is the subtype of the multipart content type, defaulting to |
| 25 | `mixed'. |
| 26 | |
| 27 | boundary is the multipart boundary string. By default it is |
| 28 | calculated as needed. |
| 29 | |
| 30 | _subparts is a sequence of initial subparts for the payload. It |
| 31 | must be an iterable object, such as a list. You can always |
| 32 | attach new subparts to the message by using the attach() method. |
| 33 | |
| 34 | Additional parameters for the Content-Type header are taken from the |
| 35 | keyword arguments (or passed into the _params argument). |
| 36 | """ |
R David Murray | 56b1f1b | 2016-09-07 16:48:35 -0400 | [diff] [blame] | 37 | MIMEBase.__init__(self, 'multipart', _subtype, policy=policy, **_params) |
Christian Heimes | 587c2bf | 2008-01-19 16:21:02 +0000 | [diff] [blame] | 38 | |
| 39 | # Initialise _payload to an empty list as the Message superclass's |
| 40 | # implementation of is_multipart assumes that _payload is a list for |
| 41 | # multipart messages. |
| 42 | self._payload = [] |
| 43 | |
Guido van Rossum | 8b3febe | 2007-08-30 01:15:14 +0000 | [diff] [blame] | 44 | if _subparts: |
| 45 | for p in _subparts: |
| 46 | self.attach(p) |
| 47 | if boundary: |
| 48 | self.set_boundary(boundary) |