Barry Warsaw | d285600 | 2004-05-09 18:04:24 +0000 | [diff] [blame] | 1 | # Copyright (C) 2002-2004 Python Software Foundation |
| 2 | # Author: barry@python.org (Barry Warsaw) |
Barry Warsaw | 2f514a8 | 2002-06-01 05:59:12 +0000 | [diff] [blame] | 3 | |
| 4 | """Base class for MIME multipart/* type messages. |
| 5 | """ |
| 6 | |
| 7 | from email import MIMEBase |
| 8 | |
| 9 | |
| 10 | |
| 11 | class MIMEMultipart(MIMEBase.MIMEBase): |
| 12 | """Base class for MIME multipart/* type messages.""" |
| 13 | |
Barry Warsaw | d285600 | 2004-05-09 18:04:24 +0000 | [diff] [blame] | 14 | def __init__(self, _subtype='mixed', boundary=None, _subparts=None, |
| 15 | **_params): |
Barry Warsaw | 2f514a8 | 2002-06-01 05:59:12 +0000 | [diff] [blame] | 16 | """Creates a multipart/* type message. |
| 17 | |
| 18 | By default, creates a multipart/mixed message, with proper |
Barry Warsaw | fd2e8f7 | 2002-09-30 21:24:00 +0000 | [diff] [blame] | 19 | Content-Type and MIME-Version headers. |
Barry Warsaw | 2f514a8 | 2002-06-01 05:59:12 +0000 | [diff] [blame] | 20 | |
| 21 | _subtype is the subtype of the multipart content type, defaulting to |
| 22 | `mixed'. |
| 23 | |
| 24 | boundary is the multipart boundary string. By default it is |
| 25 | calculated as needed. |
| 26 | |
Barry Warsaw | fd2e8f7 | 2002-09-30 21:24:00 +0000 | [diff] [blame] | 27 | _subparts is a sequence of initial subparts for the payload. It |
Barry Warsaw | d285600 | 2004-05-09 18:04:24 +0000 | [diff] [blame] | 28 | must be an iterable object, such as a list. You can always |
Barry Warsaw | 2f514a8 | 2002-06-01 05:59:12 +0000 | [diff] [blame] | 29 | attach new subparts to the message by using the attach() method. |
| 30 | |
Barry Warsaw | fd2e8f7 | 2002-09-30 21:24:00 +0000 | [diff] [blame] | 31 | Additional parameters for the Content-Type header are taken from the |
Barry Warsaw | 2f514a8 | 2002-06-01 05:59:12 +0000 | [diff] [blame] | 32 | keyword arguments (or passed into the _params argument). |
| 33 | """ |
Barry Warsaw | bb493a7 | 2002-07-09 02:44:26 +0000 | [diff] [blame] | 34 | MIMEBase.MIMEBase.__init__(self, 'multipart', _subtype, **_params) |
| 35 | if _subparts: |
Barry Warsaw | d285600 | 2004-05-09 18:04:24 +0000 | [diff] [blame] | 36 | for p in _subparts: |
| 37 | self.attach(p) |
Barry Warsaw | bb493a7 | 2002-07-09 02:44:26 +0000 | [diff] [blame] | 38 | if boundary: |
| 39 | self.set_boundary(boundary) |