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."""
6from __future__ import unicode_literals
7from __future__ import division
8from __future__ import absolute_import
9
10__all__ = ['MIMEMultipart']
11
12from future.backports.email.mime.base import MIMEBase
13
14
15class MIMEMultipart(MIMEBase):
16 """Base class for MIME multipart/* type messages."""
17
18 def __init__(self, _subtype='mixed', boundary=None, _subparts=None,
19 **_params):
20 """Creates a multipart/* type message.
21
22 By default, creates a multipart/mixed message, with proper
23 Content-Type and MIME-Version headers.
24
25 _subtype is the subtype of the multipart content type, defaulting to
26 `mixed'.
27
28 boundary is the multipart boundary string. By default it is
29 calculated as needed.
30
31 _subparts is a sequence of initial subparts for the payload. It
32 must be an iterable object, such as a list. You can always
33 attach new subparts to the message by using the attach() method.
34
35 Additional parameters for the Content-Type header are taken from the
36 keyword arguments (or passed into the _params argument).
37 """
38 MIMEBase.__init__(self, 'multipart', _subtype, **_params)
39
40 # Initialise _payload to an empty list as the Message superclass's
41 # implementation of is_multipart assumes that _payload is a list for
42 # multipart messages.
43 self._payload = []
44
45 if _subparts:
46 for p in _subparts:
47 self.attach(p)
48 if boundary:
49 self.set_boundary(boundary)