I've searched for this topic at length and could not find an exact answer. Hope I can get some guidance here.
I would like to read emails from my email Inbox (say Gmail or any email endpoint), and for each email I want to figure out if it is in HTML format or plain text.
For HTML emails, I'd like to extract some data and metadata (like sender, subject, terms within email etc), replace a few things, then save the email in an HTML file, such that it can be opened in a browser with layout, images and links intact. So when I open that html file, the entire email content renders properly as it did in my email inbox.
For text email, I'd like to extract similar metadata, replace a few things and then save in a text file. So that when opened, the content of email are shown in the text file without any email headers.
I've looked at Beautiful Soup and some other libraries. I can't figure how to save the email in files while keeping their html intact that renders properly.
Appreciate any help. Thanks in advance!