Parsing msg / eml files using Python 2.7

Is there a library that can parse msg or eml files? I wrote a script that parses an email message after converting it to a txt file, but I cannot find an email client that allows me to easily drag emails from gui to a folder as a txt file (if someone knows this, I would like to know!)

Drag-n-dropping from Outlook creates a .msg file, and Thunderbird creates a .eml file. Does anyone know a library that will parse these files like these?

+4
source share
2 answers

For * .eml files, you can use the email module from the standard library. You will need to use the Parser from email.parser to create the message object.

+7
source
`from mailparser import MailParser parser = MailParser() parser.parse_from_file(f) parser.parse_from_string(raw_mail) parser.body parser.headers parser.message_id parser.to_ parser.from_ parser.subject parser.text_plain_list: only text plain mail parts in a list parser.attachments_list: list of all attachments parser.date_mail parser.parsed_mail_obj: tokenized mail in a object parser.parsed_mail_json: tokenized mail in a JSON parser.defects: defect RFC not compliance parser.defects_category: only defects categories parser.has_defects parser.anomalies parser.has_anomalies parser.get_server_ipaddress(trust="my_server_mail_trust")` 
+1
source

Source: https://habr.com/ru/post/1386127/


All Articles