blob: ccce9fb5b1a3d2137bc68c7c380a534f1dc6e555 [file] [log] [blame]
Barry Warsawba925802001-09-23 03:17:28 +00001# Copyright (C) 2001 Python Software Foundation
2# Author: barry@zope.com (Barry Warsaw)
3
4"""Class representing text/* type MIME documents.
5"""
6
7import MIMEBase
8from Encoders import encode_7or8bit
9
10
Barry Warsawe968ead2001-10-04 17:05:11 +000011
Barry Warsaw3dd978d2001-09-26 05:34:30 +000012class MIMEText(MIMEBase.MIMEBase):
Barry Warsawba925802001-09-23 03:17:28 +000013 """Class for generating text/* type MIME documents."""
14
Barry Warsaw3dd978d2001-09-26 05:34:30 +000015 def __init__(self, _text, _subtype='plain', _charset='us-ascii',
Barry Warsawba925802001-09-23 03:17:28 +000016 _encoder=encode_7or8bit):
17 """Create a text/* type MIME document.
18
19 _text is the string for this message object. If the text does not end
20 in a newline, one is added.
21
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
24 _charset is the character set parameter added to the Content-Type:
25 header. This defaults to "us-ascii".
26
27 _encoder is a function which will perform the actual encoding for
28 transport of the text data. It takes one argument, which is this
29 Text instance. It should use get_payload() and set_payload() to
30 change the payload to the encoded form. It should also add any
31 Content-Transfer-Encoding: or other headers to the message as
32 necessary. The default encoding doesn't actually modify the payload,
33 but it does set Content-Transfer-Encoding: to either `7bit' or `8bit'
34 as appropriate.
35 """
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'
40 self.set_payload(_text)
41 _encoder(self)