Barry Warsaw | ba92580 | 2001-09-23 03:17:28 +0000 | [diff] [blame] | 1 | # Copyright (C) 2001 Python Software Foundation |
| 2 | # Author: barry@zope.com (Barry Warsaw) |
| 3 | |
| 4 | """Class representing text/* type MIME documents. |
| 5 | """ |
| 6 | |
| 7 | import MIMEBase |
| 8 | from Encoders import encode_7or8bit |
| 9 | |
| 10 | |
| 11 | |
Barry Warsaw | 3dd978d | 2001-09-26 05:34:30 +0000 | [diff] [blame^] | 12 | class MIMEText(MIMEBase.MIMEBase): |
Barry Warsaw | ba92580 | 2001-09-23 03:17:28 +0000 | [diff] [blame] | 13 | """Class for generating text/* type MIME documents.""" |
| 14 | |
Barry Warsaw | 3dd978d | 2001-09-26 05:34:30 +0000 | [diff] [blame^] | 15 | def __init__(self, _text, _subtype='plain', _charset='us-ascii', |
Barry Warsaw | ba92580 | 2001-09-23 03:17:28 +0000 | [diff] [blame] | 16 | _encoder=encode_7or8bit): |
| 17 | """Create a text/* type MIME document. |
| 18 | |
| 19 | _text is the string for this message object. If the text does not end |
| 20 | in a newline, one is added. |
| 21 | |
Barry Warsaw | 3dd978d | 2001-09-26 05:34:30 +0000 | [diff] [blame^] | 22 | _subtype is the MIME sub content type, defaulting to "plain". |
Barry Warsaw | ba92580 | 2001-09-23 03:17:28 +0000 | [diff] [blame] | 23 | |
| 24 | _charset is the character set parameter added to the Content-Type: |
| 25 | header. This defaults to "us-ascii". |
| 26 | |
| 27 | _encoder is a function which will perform the actual encoding for |
| 28 | transport of the text data. It takes one argument, which is this |
| 29 | Text instance. It should use get_payload() and set_payload() to |
| 30 | change the payload to the encoded form. It should also add any |
| 31 | Content-Transfer-Encoding: or other headers to the message as |
| 32 | necessary. The default encoding doesn't actually modify the payload, |
| 33 | but it does set Content-Transfer-Encoding: to either `7bit' or `8bit' |
| 34 | as appropriate. |
| 35 | """ |
Barry Warsaw | 3dd978d | 2001-09-26 05:34:30 +0000 | [diff] [blame^] | 36 | MIMEBase.MIMEBase.__init__(self, 'text', _subtype, |
Barry Warsaw | ba92580 | 2001-09-23 03:17:28 +0000 | [diff] [blame] | 37 | **{'charset': _charset}) |
| 38 | if _text and _text[-1] <> '\n': |
| 39 | _text += '\n' |
| 40 | self.set_payload(_text) |
| 41 | _encoder(self) |