def extract_mime_part(part, pid, encode_erros='strict'):
    """
    Use MIME parts of an email message https://docs.python.org/3/library/email.html
    Parameters
    ----------
    part : email.Meesage
    pid : int
    encode_erros : {'strict', 'ignore', 'replace', 'xmlcharrefreplace', 'backslashreplace'}, default 'strict'
        https://www.tutorialspoint.com/python3/string_decode.htm

    Returns
    -------
    part_data : dict
    
    """
    part_data = {'pid': pid, 'content_id': part.get('Content-id'),
        'content_main_type': part.get_content_maintype(),
        'content_sub_type': part.get_content_subtype(),
        'content_disposition': part.get_content_disposition(),
        'content_transfer_encoding': part.get('Content-Transfer-Encoding'),
        'content_charset': part.get_content_charset()}
    content_main_type = part_data['content_main_type']
    content_sub_type = part_data['content_sub_type']
    content_charset = part_data['content_charset']
    content_disposition = part_data['content_disposition']
    content_transfer_encoding = part_data['content_transfer_encoding']
    if (content_disposition != 'attachment' and content_main_type == 'text' and
        content_sub_type in ('plain', 'html')):
        isbody = True
        if content_charset is None:
            try:
                payload = part.get_payload(decode=True)
                for charset in ('ascii', 'latin1', 'utf-8', 'iso8859_1',
                    'Windows-1251', 'Windows-1252', 'iso8859_15'):
                    try:
                        payload = payload.decode(charset)
                    except:
                        raise
                decoded = True
            except:
                try:
                    payload = part.get_payload()
                    decoded = False
                except:
                    pass
        else:
            try:
                payload = part.get_payload(decode=True).decode(encoding=
                    content_charset, errors=encode_erros)
                decoded = True
            except:
                try:
                    payload = part.get_payload()
                    decoded = False
                except:
                    pass
        part_data.update({'isbody': isbody, 'payload': payload, 'decoded':
            decoded})
    elif content_main_type == 'message' and content_sub_type == 'rfc822':
        subject = part.get('subject')
        isbody = False
        payload = part.get_payload(decode=True)
        decoded = True
        part_data.update({'isbody': isbody, 'payload': payload, 'decoded':
            decoded})
    elif (content_disposition == 'attachment' or content_disposition ==
        'inline') or part.get_filename() != None:
        isbody = False
        payload = part.get_payload(decode=True)
        decoded = True
        part_data.update({'isbody': isbody, 'payload': payload, 'decoded':
            decoded, 'file_name': part.get_filename()})
    return part_data
