blob: d049ad9fd80bf92fdb795adbbc5a42c94faebf83 [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 Warsaw524af6f2002-06-02 19:05:08 +00008from email.MIMENonMultipart import MIMENonMultipart
9from email.Encoders import encode_7or8bit
Barry Warsawba925802001-09-23 03:17:28 +000010
11
Barry Warsawe968ead2001-10-04 17:05:11 +000012
Barry Warsaw524af6f2002-06-02 19:05:08 +000013class MIMEText(MIMENonMultipart):
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
Barry Warsawcbec7002003-03-11 05:04:09 +000020 _text is the string for this message object.
Barry Warsawba925802001-09-23 03:17:28 +000021
Barry Warsaw3dd978d2001-09-26 05:34:30 +000022 _subtype is the MIME sub content type, defaulting to "plain".
Barry Warsawba925802001-09-23 03:17:28 +000023
Barry Warsaw2d7fab12002-10-01 00:52:27 +000024 _charset is the character set parameter added to the Content-Type
Barry Warsaw409a4c02002-04-10 21:01:31 +000025 header. This defaults to "us-ascii". Note that as a side-effect, the
Barry Warsaw2d7fab12002-10-01 00:52:27 +000026 Content-Transfer-Encoding header will also be set.
Barry Warsawba925802001-09-23 03:17:28 +000027
Barry Warsaw409a4c02002-04-10 21:01:31 +000028 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 Warsawba925802001-09-23 03:17:28 +000034 """
Barry Warsaw524af6f2002-06-02 19:05:08 +000035 MIMENonMultipart.__init__(self, 'text', _subtype,
36 **{'charset': _charset})
Barry Warsaw409a4c02002-04-10 21:01:31 +000037 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 Warsaw2d7fab12002-10-01 00:52:27 +000042 # Content-Transfer-Encoding header, we need to delete the
Barry Warsaw409a4c02002-04-10 21:01:31 +000043 # existing one or will end up with two of them. :(
44 del self['content-transfer-encoding']
45 _encoder(self)