python eml解析器库

eml-parser的Python项目详细描述


Code Healthhttps://travis-ci.com/GOVCERT-LU/eml_parser.svg?branch=masterDocumentation Statushttps://badge.fury.io/py/eml-parser.svg

eml_parser用作一个python模块,用于分析eml文件并返回各种 在电子邮件中找到的信息以及计算的信息。

提取和生成的信息包括但不限于:

  • attachments - hashes - names
  • from, to, cc
  • received servers path
  • subject
  • list of URLs parsed from the text content of the mail (including HTML body/attachments)

请随时向我发送您的评论/请求。

使用pip安装最新版本:

pip install eml_parser[file-magic]

注意:如果您不想/不能使用文件魔术(例如,如果您使用的是python魔术),请通过安装:

pip install eml_parser

OSX用户注意事项

Make sure to install libmagic, else eml_parser will not work.

警告

This release is only compatible with Python3. The last release to be compatible with
Python2 is v1.2. If you do require Python2 support, please download that version.
You are strongly encouraged though to use Python3 as there are many parsing improvements
and much better RFC support.
This release is only tested with Python >=3.5.

如何使用的示例:

importdatetimeimportjsonimporteml_parserdefjson_serial(obj):ifisinstance(obj,datetime.datetime):serial=obj.isoformat()returnserialwithopen('sample.eml','rb')asfhdl:raw_email=fhdl.read()parsed_eml=eml_parser.eml_parser.decode_email_b(raw_email)print(json.dumps(parsed_eml,default=json_serial))

它提供了一个类似这样的极简主义的eml文件:

{"body":[{"content_header":{"content-language":["en-US"]},"hash":"6c9f343bdb040e764843325fc5673b0f43a021bac9064075d285190d6509222d"}],"header":{"received_src":null,"from":"john.doe@example.com","to":["test@example.com"],"subject":"Sample EML","received_foremail":["test@example.com"],"date":"2013-04-26T11:15:47+00:00","header":{"content-language":["en-US"],"received":["from localhost\tby mta.example.com (Postfix) with ESMTPS id 6388F684168\tfor <test@example.com>; Fri, 26 Apr 2013 13:15:55 +0200"],"to":["test@example.com"],"subject":["Sample EML"],"date":["Fri, 26 Apr 2013 11:15:47 +0000"],"message-id":["<F96257F63EAEB94C890EA6CE1437145C013B01FA@example.com>"],"from":["John Doe <john.doe@example.com>"]},"received_domain":["mta.example.com"],"received":[{"with":"esmtps id 6388f684168","for":["test@example.com"],"by":["mta.example.com"],"date":"2013-04-26T13:15:55+02:00","src":"from localhost by mta.example.com (postfix) with esmtps id 6388f684168 for <test@example.com>; fri, 26 apr 2013 13:15:55 +0200"}]}}

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
Java岩石、布、剪刀程序,带文件输入   java迭代Hashmap中的值列表   数组不能正确循环   JavaHibernate:对于一个遥远的惰性依赖,有一个渴望的获取者吗?   交通阻塞下的java车辆路径选择   如何在java中创建布尔方法来检查添加到具有特定索引的arraylist的对象   java Tomcat配置文件/上下文xml似乎已经崩溃了。请确保它是可分析和有效的。有关详细信息,请参阅服务器日志   为什么坐标有时相等,有时不相等?   java libgdx CameraInputController过于敏感,平移开始得太早   将C++排序函数移植到java   java应该是十进制的   swing Java JFrame中的所有内容都不可见   java使用数组中除一个元素以外的所有元素   从子类运行构造函数的Java