Barry Warsaw | 409a4c0 | 2002-04-10 21:01:31 +0000 | [diff] [blame] | 1 | # Copyright (C) 2001,2002 Python Software Foundation |
Barry Warsaw | ba92580 | 2001-09-23 03:17:28 +0000 | [diff] [blame] | 2 | # Author: barry@zope.com (Barry Warsaw) |
| 3 | |
| 4 | """Class representing text/* type MIME documents. |
| 5 | """ |
| 6 | |
Barry Warsaw | 409a4c0 | 2002-04-10 21:01:31 +0000 | [diff] [blame] | 7 | import warnings |
Barry Warsaw | ba92580 | 2001-09-23 03:17:28 +0000 | [diff] [blame] | 8 | import MIMEBase |
| 9 | from Encoders import encode_7or8bit |
| 10 | |
| 11 | |
Barry Warsaw | e968ead | 2001-10-04 17:05:11 +0000 | [diff] [blame] | 12 | |
Barry Warsaw | 3dd978d | 2001-09-26 05:34:30 +0000 | [diff] [blame] | 13 | class MIMEText(MIMEBase.MIMEBase): |
Barry Warsaw | ba92580 | 2001-09-23 03:17:28 +0000 | [diff] [blame] | 14 | """Class for generating text/* type MIME documents.""" |
| 15 | |
Barry Warsaw | 3dd978d | 2001-09-26 05:34:30 +0000 | [diff] [blame] | 16 | def __init__(self, _text, _subtype='plain', _charset='us-ascii', |
Barry Warsaw | 409a4c0 | 2002-04-10 21:01:31 +0000 | [diff] [blame] | 17 | _encoder=None): |
Barry Warsaw | ba92580 | 2001-09-23 03:17:28 +0000 | [diff] [blame] | 18 | """Create a text/* type MIME document. |
| 19 | |
| 20 | _text is the string for this message object. If the text does not end |
| 21 | in a newline, one is added. |
| 22 | |
Barry Warsaw | 3dd978d | 2001-09-26 05:34:30 +0000 | [diff] [blame] | 23 | _subtype is the MIME sub content type, defaulting to "plain". |
Barry Warsaw | ba92580 | 2001-09-23 03:17:28 +0000 | [diff] [blame] | 24 | |
| 25 | _charset is the character set parameter added to the Content-Type: |
Barry Warsaw | 409a4c0 | 2002-04-10 21:01:31 +0000 | [diff] [blame] | 26 | header. This defaults to "us-ascii". Note that as a side-effect, the |
| 27 | Content-Transfer-Encoding: header will also be set. |
Barry Warsaw | ba92580 | 2001-09-23 03:17:28 +0000 | [diff] [blame] | 28 | |
Barry Warsaw | 409a4c0 | 2002-04-10 21:01:31 +0000 | [diff] [blame] | 29 | The use of the _encoder is deprecated. The encoding of the payload, |
| 30 | and the setting of the character set parameter now happens implicitly |
| 31 | based on the _charset argument. If _encoder is supplied, then a |
| 32 | DeprecationWarning is used, and the _encoder functionality may |
| 33 | override any header settings indicated by _charset. This is probably |
| 34 | not what you want. |
Barry Warsaw | ba92580 | 2001-09-23 03:17:28 +0000 | [diff] [blame] | 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' |
Barry Warsaw | 409a4c0 | 2002-04-10 21:01:31 +0000 | [diff] [blame] | 40 | self.set_payload(_text, _charset) |
| 41 | if _encoder is not None: |
| 42 | warnings.warn('_encoder argument is obsolete.', |
| 43 | DeprecationWarning, 2) |
| 44 | # Because set_payload() with a _charset will set its own |
| 45 | # Content-Transfer-Encoding: header, we need to delete the |
| 46 | # existing one or will end up with two of them. :( |
| 47 | del self['content-transfer-encoding'] |
| 48 | _encoder(self) |