

def add_attachment(self, fname, fcontent, content_type=None):
    'add attachment'
    from email.mime.audio import MIMEAudio
    from email.mime.base import MIMEBase
    from email.mime.image import MIMEImage
    from email.mime.text import MIMEText
    import mimetypes
    if (not content_type):
        (content_type, encoding) = mimetypes.guess_type(fname)
    if (content_type is None):
        content_type = 'application/octet-stream'
    (maintype, subtype) = content_type.split('/', 1)
    if (maintype == 'text'):
        if isinstance(fcontent, unicode):
            fcontent = fcontent.encode('utf-8')
        part = MIMEText(fcontent, _subtype=subtype, _charset='utf-8')
    elif (maintype == 'image'):
        part = MIMEImage(fcontent, _subtype=subtype)
    elif (maintype == 'audio'):
        part = MIMEAudio(fcontent, _subtype=subtype)
    else:
        part = MIMEBase(maintype, part)
        part.set_payload(fcontent)
        from email import encoders
        encoders.encode_base64(part)
    if fname:
        part.add_header(b'Content-Disposition', ('attachment; filename="%s"' % fname).encode('utf-8'))
    self.msg_root.attach(part)

dataset/ETHPy150Open frappe/frappe/frappe/email/email_body.py EMail.add_attachment/VarMisuse@207/286 `subtype`->`part`