pip install flankerdef emlAnayalyse(path):with open(path, 'rb') as fhdl:raw_email = fhdl.read()eml = mime.from_string(raw_email)subject = eml.subjecteml_header_from = eml.headers.get('From')eml_header_to = eml.headers.get('To')eml_header_cc=eml.headers.get('Cc')eml_time = eml.headers.get('Date')# get_annex(eml, '1')eml_attachs=attachEml1(eml)eml_body = contentEml(eml)f = HTMLFilter()f.feed(eml_body)print(f.text)def main():path='邮件名.eml'emlAnayalyse(path)if __name__ == "__main__":main()
# 邮件正文def contentEml(eml):# 判断是否为单部分if eml.content_type.is_singlepart():eml_body = eml.bodyelse:eml_body = ''for part in eml.parts:# 判断是否是多部分if part.content_type.is_multipart():eml_body = contentEml(part)else:if part.content_type.main == 'text':eml_body = part.bodyreturn eml_body
def attachEml1(eml):for part in eml.parts:if not part.content_type.is_multipart():name = part.detected_file_namewith open(name, 'wb') as annex:annex.write(part.body)
分享
点收藏
点点赞
点在看
文章转发自AI科技大本营微信公众号,版权归其所有。文章内容不代表本站立场和任何投资暗示。
Copyright © 2021.Company 元宇宙YITB.COM All rights reserved.元宇宙YITB.COM