multipart.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Copyright (C) 2002-2006 Python Software Foundation
  2. # Author: Barry Warsaw
  3. # Contact: email-sig@python.org
  4. """Base class for MIME multipart/* type messages."""
  5. __all__ = ['MIMEMultipart']
  6. from email.mime.base import MIMEBase
  7. class MIMEMultipart(MIMEBase):
  8. """Base class for MIME multipart/* type messages."""
  9. def __init__(self, _subtype='mixed', boundary=None, _subparts=None,
  10. *, policy=None,
  11. **_params):
  12. """Creates a multipart/* type message.
  13. By default, creates a multipart/mixed message, with proper
  14. Content-Type and MIME-Version headers.
  15. _subtype is the subtype of the multipart content type, defaulting to
  16. `mixed'.
  17. boundary is the multipart boundary string. By default it is
  18. calculated as needed.
  19. _subparts is a sequence of initial subparts for the payload. It
  20. must be an iterable object, such as a list. You can always
  21. attach new subparts to the message by using the attach() method.
  22. Additional parameters for the Content-Type header are taken from the
  23. keyword arguments (or passed into the _params argument).
  24. """
  25. MIMEBase.__init__(self, 'multipart', _subtype, policy=policy, **_params)
  26. # Initialise _payload to an empty list as the Message superclass's
  27. # implementation of is_multipart assumes that _payload is a list for
  28. # multipart messages.
  29. self._payload = []
  30. if _subparts:
  31. for p in _subparts:
  32. self.attach(p)
  33. if boundary:
  34. self.set_boundary(boundary)