jpayne@68: # Copyright (C) 2002-2006 Python Software Foundation jpayne@68: # Author: Barry Warsaw jpayne@68: # Contact: email-sig@python.org jpayne@68: jpayne@68: """Base class for MIME multipart/* type messages.""" jpayne@68: jpayne@68: __all__ = ['MIMEMultipart'] jpayne@68: jpayne@68: from email.mime.base import MIMEBase jpayne@68: jpayne@68: jpayne@68: jpayne@68: class MIMEMultipart(MIMEBase): jpayne@68: """Base class for MIME multipart/* type messages.""" jpayne@68: jpayne@68: def __init__(self, _subtype='mixed', boundary=None, _subparts=None, jpayne@68: *, policy=None, jpayne@68: **_params): jpayne@68: """Creates a multipart/* type message. jpayne@68: jpayne@68: By default, creates a multipart/mixed message, with proper jpayne@68: Content-Type and MIME-Version headers. jpayne@68: jpayne@68: _subtype is the subtype of the multipart content type, defaulting to jpayne@68: `mixed'. jpayne@68: jpayne@68: boundary is the multipart boundary string. By default it is jpayne@68: calculated as needed. jpayne@68: jpayne@68: _subparts is a sequence of initial subparts for the payload. It jpayne@68: must be an iterable object, such as a list. You can always jpayne@68: attach new subparts to the message by using the attach() method. jpayne@68: jpayne@68: Additional parameters for the Content-Type header are taken from the jpayne@68: keyword arguments (or passed into the _params argument). jpayne@68: """ jpayne@68: MIMEBase.__init__(self, 'multipart', _subtype, policy=policy, **_params) jpayne@68: jpayne@68: # Initialise _payload to an empty list as the Message superclass's jpayne@68: # implementation of is_multipart assumes that _payload is a list for jpayne@68: # multipart messages. jpayne@68: self._payload = [] jpayne@68: jpayne@68: if _subparts: jpayne@68: for p in _subparts: jpayne@68: self.attach(p) jpayne@68: if boundary: jpayne@68: self.set_boundary(boundary)