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 | 524af6f | 2002-06-02 19:05:08 +0000 | [diff] [blame] | 8 | from email.MIMENonMultipart import MIMENonMultipart |
| 9 | from email.Encoders import encode_7or8bit |
Barry Warsaw | ba92580 | 2001-09-23 03:17:28 +0000 | [diff] [blame] | 10 | |
| 11 | |
Barry Warsaw | e968ead | 2001-10-04 17:05:11 +0000 | [diff] [blame] | 12 | |
Barry Warsaw | 524af6f | 2002-06-02 19:05:08 +0000 | [diff] [blame] | 13 | class MIMEText(MIMENonMultipart): |
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 | |
Barry Warsaw | cbec700 | 2003-03-11 05:04:09 +0000 | [diff] [blame] | 20 | _text is the string for this message object. |
Barry Warsaw | ba92580 | 2001-09-23 03:17:28 +0000 | [diff] [blame] | 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 | |
Barry Warsaw | 2d7fab1 | 2002-10-01 00:52:27 +0000 | [diff] [blame] | 24 | _charset is the character set parameter added to the Content-Type |
Barry Warsaw | 409a4c0 | 2002-04-10 21:01:31 +0000 | [diff] [blame] | 25 | header. This defaults to "us-ascii". Note that as a side-effect, the |
Barry Warsaw | 2d7fab1 | 2002-10-01 00:52:27 +0000 | [diff] [blame] | 26 | Content-Transfer-Encoding header will also be set. |
Barry Warsaw | ba92580 | 2001-09-23 03:17:28 +0000 | [diff] [blame] | 27 | |
Barry Warsaw | 409a4c0 | 2002-04-10 21:01:31 +0000 | [diff] [blame] | 28 | The use of the _encoder is deprecated. The encoding of the payload, |
| 29 | and the setting of the character set parameter now happens implicitly |
| 30 | based on the _charset argument. If _encoder is supplied, then a |
| 31 | DeprecationWarning is used, and the _encoder functionality may |
| 32 | override any header settings indicated by _charset. This is probably |
| 33 | not what you want. |
Barry Warsaw | ba92580 | 2001-09-23 03:17:28 +0000 | [diff] [blame] | 34 | """ |
Barry Warsaw | 524af6f | 2002-06-02 19:05:08 +0000 | [diff] [blame] | 35 | MIMENonMultipart.__init__(self, 'text', _subtype, |
| 36 | **{'charset': _charset}) |
Barry Warsaw | 409a4c0 | 2002-04-10 21:01:31 +0000 | [diff] [blame] | 37 | self.set_payload(_text, _charset) |
| 38 | if _encoder is not None: |
| 39 | warnings.warn('_encoder argument is obsolete.', |
| 40 | DeprecationWarning, 2) |
| 41 | # Because set_payload() with a _charset will set its own |
Barry Warsaw | 2d7fab1 | 2002-10-01 00:52:27 +0000 | [diff] [blame] | 42 | # Content-Transfer-Encoding header, we need to delete the |
Barry Warsaw | 409a4c0 | 2002-04-10 21:01:31 +0000 | [diff] [blame] | 43 | # existing one or will end up with two of them. :( |
| 44 | del self['content-transfer-encoding'] |
| 45 | _encoder(self) |