sophuwu.site > mailboxxer
python parser??
sophuwu sophie@skisiel.com
Wed, 24 Jul 2024 01:14:45 +0200
commit

d8c921cb24faa0d4bfb73d0323af4a97cad2bd4e

parent

9f471806d78bf5b3180d1888ea6dcf1bf1747a1a

1 files changed, 25 insertions(+), 0 deletions(-)

jump to
A mailbox.py

@@ -0,0 +1,25 @@

+#!/bin/python3.11 + +import email +from email import policy +from email.parser import BytesParser +import os + + +def openeml(file): + with open(file, 'rb') as fp: + eml = BytesParser(policy=policy.default).parse(fp) + return eml + + +def showparts(eml): + for part in eml.walk(): + if part.get_content_disposition() == None and part.get_content_maintype() == 'text': + print(part.get_content_maintype(), part.get_content_subtype(), len(part.get_payload(decode=True))) + elif part.get_content_disposition() == 'attachment': + print(part.get_content_disposition(),part.get_content_maintype(), part.get_content_subtype(), len(part.get_payload(decode=True))) + + +eml = openeml('test/pro.eml') +print(eml.get('Subject'), eml.get('From'), eml.get('Date')) +showparts(eml)