message.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # Copyright (C) 2001-2006 Python Software Foundation
  2. # Author: Barry Warsaw
  3. # Contact: email-sig@python.org
  4. """Class representing message/* MIME documents."""
  5. from __future__ import unicode_literals
  6. from __future__ import division
  7. from __future__ import absolute_import
  8. __all__ = ['MIMEMessage']
  9. from future.backports.email import message
  10. from future.backports.email.mime.nonmultipart import MIMENonMultipart
  11. class MIMEMessage(MIMENonMultipart):
  12. """Class representing message/* MIME documents."""
  13. def __init__(self, _msg, _subtype='rfc822'):
  14. """Create a message/* type MIME document.
  15. _msg is a message object and must be an instance of Message, or a
  16. derived class of Message, otherwise a TypeError is raised.
  17. Optional _subtype defines the subtype of the contained message. The
  18. default is "rfc822" (this is defined by the MIME standard, even though
  19. the term "rfc822" is technically outdated by RFC 2822).
  20. """
  21. MIMENonMultipart.__init__(self, 'message', _subtype)
  22. if not isinstance(_msg, message.Message):
  23. raise TypeError('Argument is not an instance of Message')
  24. # It's convenient to use this base class method. We need to do it
  25. # this way or we'll get an exception
  26. message.Message.attach(self, _msg)
  27. # And be sure our default type is set correctly
  28. self.set_default_type('message/rfc822')