2006-03-18 11:41:53 -04:00
|
|
|
|
# Copyright (C) 2002-2006 Python Software Foundation
|
2004-10-03 00:16:19 -03:00
|
|
|
|
# Author: Barry Warsaw
|
|
|
|
|
# Contact: email-sig@python.org
|
2002-06-01 02:59:12 -03:00
|
|
|
|
|
2004-10-03 00:16:19 -03:00
|
|
|
|
"""Base class for MIME multipart/* type messages."""
|
2002-06-01 02:59:12 -03:00
|
|
|
|
|
2006-03-18 11:41:53 -04:00
|
|
|
|
__all__ = ['MIMEMultipart']
|
|
|
|
|
|
|
|
|
|
from email.mime.base import MIMEBase
|
2002-06-01 02:59:12 -03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-03-18 11:41:53 -04:00
|
|
|
|
class MIMEMultipart(MIMEBase):
|
2002-06-01 02:59:12 -03:00
|
|
|
|
"""Base class for MIME multipart/* type messages."""
|
|
|
|
|
|
2004-05-09 15:04:24 -03:00
|
|
|
|
def __init__(self, _subtype='mixed', boundary=None, _subparts=None,
|
|
|
|
|
**_params):
|
2002-06-01 02:59:12 -03:00
|
|
|
|
"""Creates a multipart/* type message.
|
|
|
|
|
|
|
|
|
|
By default, creates a multipart/mixed message, with proper
|
2002-09-30 18:24:00 -03:00
|
|
|
|
Content-Type and MIME-Version headers.
|
2002-06-01 02:59:12 -03:00
|
|
|
|
|
|
|
|
|
_subtype is the subtype of the multipart content type, defaulting to
|
|
|
|
|
`mixed'.
|
|
|
|
|
|
|
|
|
|
boundary is the multipart boundary string. By default it is
|
|
|
|
|
calculated as needed.
|
|
|
|
|
|
2002-09-30 18:24:00 -03:00
|
|
|
|
_subparts is a sequence of initial subparts for the payload. It
|
2004-05-09 15:04:24 -03:00
|
|
|
|
must be an iterable object, such as a list. You can always
|
2002-06-01 02:59:12 -03:00
|
|
|
|
attach new subparts to the message by using the attach() method.
|
|
|
|
|
|
2002-09-30 18:24:00 -03:00
|
|
|
|
Additional parameters for the Content-Type header are taken from the
|
2002-06-01 02:59:12 -03:00
|
|
|
|
keyword arguments (or passed into the _params argument).
|
|
|
|
|
"""
|
2006-03-18 11:41:53 -04:00
|
|
|
|
MIMEBase.__init__(self, 'multipart', _subtype, **_params)
|
2008-01-19 08:32:27 -04:00
|
|
|
|
|
|
|
|
|
# Initialise _payload to an empty list as the Message superclass's
|
|
|
|
|
# implementation of is_multipart assumes that _payload is a list for
|
|
|
|
|
# multipart messages.
|
|
|
|
|
self._payload = []
|
|
|
|
|
|
2002-07-08 23:44:26 -03:00
|
|
|
|
if _subparts:
|
2004-05-09 15:04:24 -03:00
|
|
|
|
for p in _subparts:
|
|
|
|
|
self.attach(p)
|
2002-07-08 23:44:26 -03:00
|
|
|
|
if boundary:
|
|
|
|
|
self.set_boundary(boundary)
|