blob: 96618650c519c5cdf38cd2dbfe6ddba8d78ec63f [file] [log] [blame]
Barry Warsaw40ef0062006-03-18 15:41:53 +00001# Copyright (C) 2002-2006 Python Software Foundation
Barry Warsawbb113862004-10-03 03:16:19 +00002# Author: Barry Warsaw
3# Contact: email-sig@python.org
Barry Warsaw2f514a82002-06-01 05:59:12 +00004
Barry Warsawbb113862004-10-03 03:16:19 +00005"""Base class for MIME multipart/* type messages."""
Barry Warsaw2f514a82002-06-01 05:59:12 +00006
Barry Warsaw40ef0062006-03-18 15:41:53 +00007__all__ = ['MIMEMultipart']
8
9from email.mime.base import MIMEBase
Barry Warsaw2f514a82002-06-01 05:59:12 +000010
11
12
Barry Warsaw40ef0062006-03-18 15:41:53 +000013class MIMEMultipart(MIMEBase):
Barry Warsaw2f514a82002-06-01 05:59:12 +000014 """Base class for MIME multipart/* type messages."""
15
Barry Warsawd2856002004-05-09 18:04:24 +000016 def __init__(self, _subtype='mixed', boundary=None, _subparts=None,
17 **_params):
Barry Warsaw2f514a82002-06-01 05:59:12 +000018 """Creates a multipart/* type message.
19
20 By default, creates a multipart/mixed message, with proper
Barry Warsawfd2e8f72002-09-30 21:24:00 +000021 Content-Type and MIME-Version headers.
Barry Warsaw2f514a82002-06-01 05:59:12 +000022
23 _subtype is the subtype of the multipart content type, defaulting to
24 `mixed'.
25
26 boundary is the multipart boundary string. By default it is
27 calculated as needed.
28
Barry Warsawfd2e8f72002-09-30 21:24:00 +000029 _subparts is a sequence of initial subparts for the payload. It
Barry Warsawd2856002004-05-09 18:04:24 +000030 must be an iterable object, such as a list. You can always
Barry Warsaw2f514a82002-06-01 05:59:12 +000031 attach new subparts to the message by using the attach() method.
32
Barry Warsawfd2e8f72002-09-30 21:24:00 +000033 Additional parameters for the Content-Type header are taken from the
Barry Warsaw2f514a82002-06-01 05:59:12 +000034 keyword arguments (or passed into the _params argument).
35 """
Barry Warsaw40ef0062006-03-18 15:41:53 +000036 MIMEBase.__init__(self, 'multipart', _subtype, **_params)
Facundo Batista2b1b1952008-01-19 12:32:27 +000037
38 # Initialise _payload to an empty list as the Message superclass's
39 # implementation of is_multipart assumes that _payload is a list for
40 # multipart messages.
41 self._payload = []
42
Barry Warsawbb493a72002-07-09 02:44:26 +000043 if _subparts:
Barry Warsawd2856002004-05-09 18:04:24 +000044 for p in _subparts:
45 self.attach(p)
Barry Warsawbb493a72002-07-09 02:44:26 +000046 if boundary:
47 self.set_boundary(boundary)