An EMLX file contains an individual email message created by Apple Mail
emlx_parse takes as input a raw emlx email and generates a parsed object. The properties of this object are the same name of RFC headers:
- bcc
- cc
- date
- delivered_to
- from_ (not
from
because is a keyword of Python) - message_id
- received
- reply_to
- subject
- to
There are other properties to get:
- body
- body html
- body plain
- headers
- attachments
Import emlx_parse
module:
import emlx_parse
sample_file_path = r'./test/sample/1.emlx'
my_eml = emlx_parse.Emlx(sample_file_path, decode=True)
Then you can get all parts
# Header
print(my_eml.header.subject)
print(my_eml.header.from_)
print(my_eml.header.to)
print('sent date:', my_eml.header.date_utc)
print('received date:', my_eml.header.received.date_utc)
print(my_eml.header.cc)
print(my_eml.header.bcc)
# Body
for part in my_eml.body:
if part.text_plain:
print('# TEXT #', part.text_plain)
if part.text_html:
print('# HTML #', part.text_html)
# save image
if part.image:
print('my image')
with open(part.filename, 'wb') as fh:
fh.write(part.image)
# save other attachment
if part.attachment:
with open(part.filename, 'wb') as fh:
fh.write(part.attachment)