7.1.12 Differences from mimelib

Python 2.5

7.1.12 Differences from mimelib

The email package was originally prototyped as a separate library called mimelib. Changes have been made so that method names are more consistent, and some methods or modules have either been added or removed. The semantics of some of the methods have also changed. For the most part, any functionality available in mimelib is still available in the email package, albeit often in a different way. Backward compatibility between the mimelib package and the email package was not a priority.

Here is a brief description of the differences between the mimelib and the email packages, along with hints on how to port your applications.

Of course, the most visible difference between the two packages is that the package name has been changed to email. In addition, the top-level package has the following differences:

  • messageFromString() has been renamed to message_from_string().

  • messageFromFile() has been renamed to message_from_file().

The Message class has the following differences:

  • The method asString() was renamed to as_string().

  • The method ismultipart() was renamed to is_multipart().

  • The get_payload() method has grown a decode optional argument.

  • The method getall() was renamed to get_all().

  • The method addheader() was renamed to add_header().

  • The method gettype() was renamed to get_type().

  • The method getmaintype() was renamed to get_main_type().

  • The method getsubtype() was renamed to get_subtype().

  • The method getparams() was renamed to get_params(). Also, whereas getparams() returned a list of strings, get_params() returns a list of 2-tuples, effectively the key/value pairs of the parameters, split on the "=" sign.

  • The method getparam() was renamed to get_param().

  • The method getcharsets() was renamed to get_charsets().

  • The method getfilename() was renamed to get_filename().

  • The method getboundary() was renamed to get_boundary().

  • The method setboundary() was renamed to set_boundary().

  • The method getdecodedpayload() was removed. To get similar functionality, pass the value 1 to the decode flag of the get_payload() method.

  • The method getpayloadastext() was removed. Similar functionality is supported by the DecodedGenerator class in the email.generator module.

  • The method getbodyastext() was removed. You can get similar functionality by creating an iterator with typed_subpart_iterator() in the email.iterators module.

The Parser class has no differences in its public interface. It does have some additional smarts to recognize message/delivery-status type messages, which it represents as a Message instance containing separate Message subparts for each header block in the delivery status notification7.4.

The Generator class has no differences in its public interface. There is a new class in the email.generator module though, called DecodedGenerator which provides most of the functionality previously available in the Message.getpayloadastext() method.

The following modules and classes have been changed:

  • The MIMEBase class constructor arguments _major and _minor have changed to _maintype and _subtype respectively.

  • The Image class/module has been renamed to MIMEImage. The _minor argument has been renamed to _subtype.

  • The Text class/module has been renamed to MIMEText. The _minor argument has been renamed to _subtype.

  • The MessageRFC822 class/module has been renamed to MIMEMessage. Note that an earlier version of mimelib called this class/module RFC822, but that clashed with the Python standard library module rfc822 on some case-insensitive file systems.

    Also, the MIMEMessage class now represents any kind of MIME message with main type message. It takes an optional argument _subtype which is used to set the MIME subtype. _subtype defaults to rfc822.

mimelib provided some utility functions in its address and date modules. All of these functions have been moved to the email.utils module.

The MsgReader class/module has been removed. Its functionality is most closely supported in the body_line_iterator() function in the email.iterators module.


Footnotes

Delivery Status Notifications (DSN) are defined in RFC 1894.
See About this document... for information on suggesting changes.