fix to work on python <= 2.1
[python/dscho.git] / Lib / email / MIMEText.py
blobd049ad9fd80bf92fdb795adbbc5a42c94faebf83
1 # Copyright (C) 2001,2002 Python Software Foundation
2 # Author: barry@zope.com (Barry Warsaw)
4 """Class representing text/* type MIME documents.
5 """
7 import warnings
8 from email.MIMENonMultipart import MIMENonMultipart
9 from email.Encoders import encode_7or8bit
13 class MIMEText(MIMENonMultipart):
14 """Class for generating text/* type MIME documents."""
16 def __init__(self, _text, _subtype='plain', _charset='us-ascii',
17 _encoder=None):
18 """Create a text/* type MIME document.
20 _text is the string for this message object.
22 _subtype is the MIME sub content type, defaulting to "plain".
24 _charset is the character set parameter added to the Content-Type
25 header. This defaults to "us-ascii". Note that as a side-effect, the
26 Content-Transfer-Encoding header will also be set.
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.
34 """
35 MIMENonMultipart.__init__(self, 'text', _subtype,
36 **{'charset': _charset})
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
42 # Content-Transfer-Encoding header, we need to delete the
43 # existing one or will end up with two of them. :(
44 del self['content-transfer-encoding']
45 _encoder(self)