电子邮件解析器:未从原始电子邮件获取.eml附件

时间:2019-12-12 06:22:04

标签: python email parsing attachment

使用python(侧翼库)解析包含PDF和“ .eml ”文件的电子邮件时未获得附件 帮助将不胜感激。

这是我的代码

from flanker import mime

extracted_data = {}
inline_attachments = {}
base64_attachment = {}
mimeContents = mime.from_string(rawEmail)
if mimeContents.content_type.is_multipart():
    for part in mimeContents.walk(): 
    item_subtype = str(part.detected_subtype)
    if item_subtype.lower() == 'plain':
        if part.body is not None: 
            extracted_data['plain_body'] = part.body  
    elif item_subtype.lower() == 'html': 
        if part.body is not None: 
            extracted_data['html_body'] = part.body 
    elif part.is_inline():
        if part.body is not None: 
            for items in part.headers._v._items: 
                if str(items[0]).lower() == 'content-id':
                    temp_file_name = items[1]
                    content_id = temp_file_name[1: len(temp_file_name)-1]
                    inline_attachments[content_id] = part.body
       if part.is_attachment():
        if part.body is not None: 
            base64_attachment[part.detected_file_name] = part.body

0 个答案:

没有答案