blob: 8669d28568361303d10aceb4f6ad7457af6b65fa [file] [log] [blame]
Barry Warsaw409a4c02002-04-10 21:01:31 +00001# Copyright (C) 2001,2002 Python Software Foundation
Barry Warsawba925802001-09-23 03:17:28 +00002# Author: barry@zope.com (Barry Warsaw)
3
4"""Class representing text/* type MIME documents.
5"""
6
Barry Warsaw409a4c02002-04-10 21:01:31 +00007import warnings
Barry Warsawba925802001-09-23 03:17:28 +00008import MIMEBase
9from Encoders import encode_7or8bit
10
11
Barry Warsawe968ead2001-10-04 17:05:11 +000012
Barry Warsaw3dd978d2001-09-26 05:34:30 +000013class MIMEText(MIMEBase.MIMEBase):
Barry Warsawba925802001-09-23 03:17:28 +000014 """Class for generating text/* type MIME documents."""
15
Barry Warsaw3dd978d2001-09-26 05:34:30 +000016 def __init__(self, _text, _subtype='plain', _charset='us-ascii',
Barry Warsaw409a4c02002-04-10 21:01:31 +000017 _encoder=None):
Barry Warsawba925802001-09-23 03:17:28 +000018 """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 Warsaw3dd978d2001-09-26 05:34:30 +000023 _subtype is the MIME sub content type, defaulting to "plain".
Barry Warsawba925802001-09-23 03:17:28 +000024
25 _charset is the character set parameter added to the Content-Type:
Barry Warsaw409a4c02002-04-10 21:01:31 +000026 header. This defaults to "us-ascii". Note that as a side-effect, the
27 Content-Transfer-Encoding: header will also be set.
Barry Warsawba925802001-09-23 03:17:28 +000028
Barry Warsaw409a4c02002-04-10 21:01:31 +000029 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 Warsawba925802001-09-23 03:17:28 +000035 """
Barry Warsaw3dd978d2001-09-26 05:34:30 +000036 MIMEBase.MIMEBase.__init__(self, 'text', _subtype,
Barry Warsawba925802001-09-23 03:17:28 +000037 **{'charset': _charset})
38 if _text and _text[-1] <> '\n':
39 _text += '\n'
Barry Warsaw409a4c02002-04-10 21:01:31 +000040 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)