在Python中使用imaplib提取多语言电子邮件数据时解码十六进制

问题描述 投票:0回答:1

我该如何转动:

With Best Regards, JS Chen*\r\n\r\n=E9=A0=8E=E9=82=A6=E7=A7=91=E6=8A=80=E8=82=A1=E4=BB=BD=E6=9C=89=E9=99=90=E5=\r\n=85=AC=E5=8F=B8/Chipbond Technology 

至此:

With Best Regards, JS Chen*\r\n\r\n頎邦科技股份有限公司/Chipbond Technology

使用python吗?

[我正在使用imaplib提取混合语言的电子邮件数据,并且当有其他语言字符时,会在中间用等号向我提供此十六进制代码

这是我的代码:

mail = imaplib.IMAP4_SSL('imap.gmail.com')
mail.login('****@gmail.com', '*********')

mail.select('Inbox')

type, data = mail.search(None,'(SUBJECT "ULVAC RSH-820")')
mail_ids = data[0]
id_list = mail_ids.split()
print('searching...')

for num in data[0].split():
    typ, data = mail.fetch(num, '(RFC822)' )
    raw_email = data[0][1]
    raw_email_string = raw_email.decode('utf-8')
    email_message = email.message_from_string(raw_email_string)
    print('decoding..')
    for response_part in data:
        if isinstance(response_part, tuple):
            msg = email.message_from_string(response_part[1].decode('utf-8')) 

            if msg.is_multipart():
                print('de-partitioning...')
                for part in msg.walk():
                    ctype = part.get_content_type()
                    cdispo = str(part.get('Content-Disposition'))
                    if ctype == 'text/plain' and 'attachment' not in cdispo:
                        body = part.get_payload()


            else:
                body = msg.get_payload()
python email hex decode imaplib
1个回答
0
投票

您的电子邮件具有传输编码

© www.soinside.com 2019 - 2024. All rights reserved.