blob: 1a3f9b51f6c04567671dbdd24ac1835526ff0aef [file] [log] [blame]
Guido van Rossum8b3febe2007-08-30 01:15:14 +00001# Copyright (C) 2001-2006 Python Software Foundation
2# Author: Barry Warsaw
3# Contact: email-sig@python.org
4
5"""Base class for MIME specializations."""
6
7__all__ = ['MIMEBase']
8
R David Murray56b1f1b2016-09-07 16:48:35 -04009import email.policy
10
Guido van Rossum8b3febe2007-08-30 01:15:14 +000011from email import message
12
13
14
15class MIMEBase(message.Message):
16 """Base class for MIME specializations."""
17
R David Murray56b1f1b2016-09-07 16:48:35 -040018 def __init__(self, _maintype, _subtype, *, policy=None, **_params):
Guido van Rossum8b3febe2007-08-30 01:15:14 +000019 """This constructor adds a Content-Type: and a MIME-Version: header.
20
21 The Content-Type: header is taken from the _maintype and _subtype
22 arguments. Additional parameters for this header are taken from the
23 keyword arguments.
24 """
R David Murray56b1f1b2016-09-07 16:48:35 -040025 if policy is None:
26 policy = email.policy.compat32
27 message.Message.__init__(self, policy=policy)
Guido van Rossum8b3febe2007-08-30 01:15:14 +000028 ctype = '%s/%s' % (_maintype, _subtype)
29 self.add_header('Content-Type', ctype, **_params)
30 self['MIME-Version'] = '1.0'