From 3dd978dfff316a521a899c9e17daa0795ec17edb Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Wed, 26 Sep 2001 05:34:30 +0000 Subject: Image.py and class Image => MIMEImage.py and MIMEImage Text.py and class Text => MIMEText.py and MIMEText MessageRFC822.py and class MessageRFC822 => MIMEMessage.py and MIMEMessage These are renamed so as to be more consistent; these are MIME specific derived classes for when creating the object model out of whole cloth. --- Lib/email/Image.py | 46 ---------------------------------------------- Lib/email/MIMEImage.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ Lib/email/MIMEMessage.py | 28 ++++++++++++++++++++++++++++ Lib/email/MIMEText.py | 41 +++++++++++++++++++++++++++++++++++++++++ Lib/email/MessageRFC822.py | 24 ------------------------ Lib/email/Text.py | 41 ----------------------------------------- 6 files changed, 115 insertions(+), 111 deletions(-) delete mode 100644 Lib/email/Image.py create mode 100644 Lib/email/MIMEImage.py create mode 100644 Lib/email/MIMEMessage.py create mode 100644 Lib/email/MIMEText.py delete mode 100644 Lib/email/MessageRFC822.py delete mode 100644 Lib/email/Text.py diff --git a/Lib/email/Image.py b/Lib/email/Image.py deleted file mode 100644 index d350785..0000000 --- a/Lib/email/Image.py +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright (C) 2001 Python Software Foundation -# Author: barry@zope.com (Barry Warsaw) - -"""Class representing image/* type MIME documents. -""" - -import imghdr - -# Intrapackage imports -import MIMEBase -import Errors -import Encoders - - - -class Image(MIMEBase.MIMEBase): - """Class for generating image/* type MIME documents.""" - - def __init__(self, _imagedata, _minor=None, - _encoder=Encoders.encode_base64, **_params): - """Create an image/* type MIME document. - - _imagedata is a string containing the raw image data. If this data - can be decoded by the standard Python `imghdr' module, then the - subtype will be automatically included in the Content-Type: header. - Otherwise, you can specify the specific image subtype via the _minor - parameter. - - _encoder is a function which will perform the actual encoding for - transport of the image data. It takes one argument, which is this - Image instance. It should use get_payload() and set_payload() to - change the payload to the encoded form. It should also add any - Content-Transfer-Encoding: or other headers to the message as - necessary. The default encoding is Base64. - - Any additional keyword arguments are passed to the base class - constructor, which turns them into parameters on the Content-Type: - header. - """ - if _minor is None: - _minor = imghdr.what(None, _imagedata) - if _minor is None: - raise TypeError, 'Could not guess image _minor type' - MIMEBase.MIMEBase.__init__(self, 'image', _minor, **_params) - self.set_payload(_imagedata) - _encoder(self) diff --git a/Lib/email/MIMEImage.py b/Lib/email/MIMEImage.py new file mode 100644 index 0000000..963da23 --- /dev/null +++ b/Lib/email/MIMEImage.py @@ -0,0 +1,46 @@ +# Copyright (C) 2001 Python Software Foundation +# Author: barry@zope.com (Barry Warsaw) + +"""Class representing image/* type MIME documents. +""" + +import imghdr + +# Intrapackage imports +import MIMEBase +import Errors +import Encoders + + + +class MIMEImage(MIMEBase.MIMEBase): + """Class for generating image/* type MIME documents.""" + + def __init__(self, _imagedata, _subtype=None, + _encoder=Encoders.encode_base64, **_params): + """Create an image/* type MIME document. + + _imagedata is a string containing the raw image data. If this data + can be decoded by the standard Python `imghdr' module, then the + subtype will be automatically included in the Content-Type: header. + Otherwise, you can specify the specific image subtype via the _subtype + parameter. + + _encoder is a function which will perform the actual encoding for + transport of the image data. It takes one argument, which is this + Image instance. It should use get_payload() and set_payload() to + change the payload to the encoded form. It should also add any + Content-Transfer-Encoding: or other headers to the message as + necessary. The default encoding is Base64. + + Any additional keyword arguments are passed to the base class + constructor, which turns them into parameters on the Content-Type: + header. + """ + if _subtype is None: + _subtype = imghdr.what(None, _imagedata) + if _subtype is None: + raise TypeError, 'Could not guess image MIME subtype' + MIMEBase.MIMEBase.__init__(self, 'image', _subtype, **_params) + self.set_payload(_imagedata) + _encoder(self) diff --git a/Lib/email/MIMEMessage.py b/Lib/email/MIMEMessage.py new file mode 100644 index 0000000..fc4b2c6 --- /dev/null +++ b/Lib/email/MIMEMessage.py @@ -0,0 +1,28 @@ +# Copyright (C) 2001 Python Software Foundation +# Author: barry@zope.com (Barry Warsaw) + +"""Class representing message/* MIME documents. +""" + +import Message +import MIMEBase + + + +class MIMEMessage(MIMEBase.MIMEBase): + """Class representing message/* MIME documents.""" + + def __init__(self, _msg, _subtype='rfc822'): + """Create a message/* type MIME document. + + _msg is a message object and must be an instance of Message, or a + derived class of Message, otherwise a TypeError is raised. + + Optional _subtype defines the subtype of the contained message. The + default is "rfc822" (this is defined by the MIME standard, even though + the term "rfc822" is technically outdated by RFC 2822). + """ + MIMEBase.MIMEBase.__init__(self, 'message', _subtype) + if not isinstance(_msg, Message.Message): + raise TypeError, 'Argument is not an instance of Message' + self.set_payload(_msg) diff --git a/Lib/email/MIMEText.py b/Lib/email/MIMEText.py new file mode 100644 index 0000000..ccce9fb --- /dev/null +++ b/Lib/email/MIMEText.py @@ -0,0 +1,41 @@ +# Copyright (C) 2001 Python Software Foundation +# Author: barry@zope.com (Barry Warsaw) + +"""Class representing text/* type MIME documents. +""" + +import MIMEBase +from Encoders import encode_7or8bit + + + +class MIMEText(MIMEBase.MIMEBase): + """Class for generating text/* type MIME documents.""" + + def __init__(self, _text, _subtype='plain', _charset='us-ascii', + _encoder=encode_7or8bit): + """Create a text/* type MIME document. + + _text is the string for this message object. If the text does not end + in a newline, one is added. + + _subtype is the MIME sub content type, defaulting to "plain". + + _charset is the character set parameter added to the Content-Type: + header. This defaults to "us-ascii". + + _encoder is a function which will perform the actual encoding for + transport of the text data. It takes one argument, which is this + Text instance. It should use get_payload() and set_payload() to + change the payload to the encoded form. It should also add any + Content-Transfer-Encoding: or other headers to the message as + necessary. The default encoding doesn't actually modify the payload, + but it does set Content-Transfer-Encoding: to either `7bit' or `8bit' + as appropriate. + """ + MIMEBase.MIMEBase.__init__(self, 'text', _subtype, + **{'charset': _charset}) + if _text and _text[-1] <> '\n': + _text += '\n' + self.set_payload(_text) + _encoder(self) diff --git a/Lib/email/MessageRFC822.py b/Lib/email/MessageRFC822.py deleted file mode 100644 index 81cc4dc..0000000 --- a/Lib/email/MessageRFC822.py +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright (C) 2001 Python Software Foundation -# Author: barry@zope.com (Barry Warsaw) - -"""Class for generating message/rfc822 MIME documents. -""" - -import Message -import MIMEBase - - - -class MessageRFC822(MIMEBase.MIMEBase): - """Class for generating message/rfc822 MIME documents.""" - - def __init__(self, _msg): - """Create a message/rfc822 type MIME document. - - _msg is a message object and must be an instance of Message, or a - derived class of Message, otherwise a TypeError is raised. - """ - MIMEBase.MIMEBase.__init__(self, 'message', 'rfc822') - if not isinstance(_msg, Message.Message): - raise TypeError, 'Argument is not an instance of Message' - self.set_payload(_msg) diff --git a/Lib/email/Text.py b/Lib/email/Text.py deleted file mode 100644 index 5abfd0b..0000000 --- a/Lib/email/Text.py +++ /dev/null @@ -1,41 +0,0 @@ -# Copyright (C) 2001 Python Software Foundation -# Author: barry@zope.com (Barry Warsaw) - -"""Class representing text/* type MIME documents. -""" - -import MIMEBase -from Encoders import encode_7or8bit - - - -class Text(MIMEBase.MIMEBase): - """Class for generating text/* type MIME documents.""" - - def __init__(self, _text, _minor='plain', _charset='us-ascii', - _encoder=encode_7or8bit): - """Create a text/* type MIME document. - - _text is the string for this message object. If the text does not end - in a newline, one is added. - - _minor is the minor content type, defaulting to "plain". - - _charset is the character set parameter added to the Content-Type: - header. This defaults to "us-ascii". - - _encoder is a function which will perform the actual encoding for - transport of the text data. It takes one argument, which is this - Text instance. It should use get_payload() and set_payload() to - change the payload to the encoded form. It should also add any - Content-Transfer-Encoding: or other headers to the message as - necessary. The default encoding doesn't actually modify the payload, - but it does set Content-Transfer-Encoding: to either `7bit' or `8bit' - as appropriate. - """ - MIMEBase.MIMEBase.__init__(self, 'text', _minor, - **{'charset': _charset}) - if _text and _text[-1] <> '\n': - _text += '\n' - self.set_payload(_text) - _encoder(self) -- cgit v0.12