'Convert the content, mimetype pair into a MIME attachment object.
If the mimetype is message/rfc822, content may be an
email.Message or EmailMessage object, as well as a str.'

def _create_mime_attachment(self, content, mimetype):

    (basetype, subtype) = mimetype.split('/', 1)
    if (basetype == 'text'):
        encoding = (self.encoding or settings.DEFAULT_CHARSET)
        attachment = SafeMIMEText(content, subtype, encoding)
    elif ((basetype == 'message') and (subtype == 'rfc822')):
        if isinstance(content, EmailMessage):
            content = content.message()
        elif (not isinstance(content, Message)):
            content = message_from_string(force_text(content))
        attachment = SafeMIMEMessage(content, subtype)
    else:
        attachment = MIMEBase(basetype, subtype)
        attachment.set_payload(content)
        Encoders.encode_base64(attachment)
    return attachment
