1*cda5da8dSAndroid Build Coastguard Worker# Copyright (C) 2001-2006 Python Software Foundation 2*cda5da8dSAndroid Build Coastguard Worker# Author: Barry Warsaw 3*cda5da8dSAndroid Build Coastguard Worker# Contact: [email protected] 4*cda5da8dSAndroid Build Coastguard Worker 5*cda5da8dSAndroid Build Coastguard Worker"""Base class for MIME specializations.""" 6*cda5da8dSAndroid Build Coastguard Worker 7*cda5da8dSAndroid Build Coastguard Worker__all__ = ['MIMEBase'] 8*cda5da8dSAndroid Build Coastguard Worker 9*cda5da8dSAndroid Build Coastguard Workerimport email.policy 10*cda5da8dSAndroid Build Coastguard Worker 11*cda5da8dSAndroid Build Coastguard Workerfrom email import message 12*cda5da8dSAndroid Build Coastguard Worker 13*cda5da8dSAndroid Build Coastguard Worker 14*cda5da8dSAndroid Build Coastguard Worker 15*cda5da8dSAndroid Build Coastguard Workerclass MIMEBase(message.Message): 16*cda5da8dSAndroid Build Coastguard Worker """Base class for MIME specializations.""" 17*cda5da8dSAndroid Build Coastguard Worker 18*cda5da8dSAndroid Build Coastguard Worker def __init__(self, _maintype, _subtype, *, policy=None, **_params): 19*cda5da8dSAndroid Build Coastguard Worker """This constructor adds a Content-Type: and a MIME-Version: header. 20*cda5da8dSAndroid Build Coastguard Worker 21*cda5da8dSAndroid Build Coastguard Worker The Content-Type: header is taken from the _maintype and _subtype 22*cda5da8dSAndroid Build Coastguard Worker arguments. Additional parameters for this header are taken from the 23*cda5da8dSAndroid Build Coastguard Worker keyword arguments. 24*cda5da8dSAndroid Build Coastguard Worker """ 25*cda5da8dSAndroid Build Coastguard Worker if policy is None: 26*cda5da8dSAndroid Build Coastguard Worker policy = email.policy.compat32 27*cda5da8dSAndroid Build Coastguard Worker message.Message.__init__(self, policy=policy) 28*cda5da8dSAndroid Build Coastguard Worker ctype = '%s/%s' % (_maintype, _subtype) 29*cda5da8dSAndroid Build Coastguard Worker self.add_header('Content-Type', ctype, **_params) 30*cda5da8dSAndroid Build Coastguard Worker self['MIME-Version'] = '1.0' 31