How to fetch only the "text/plain" and "text/html" parts of an email message?

40 views Asked by At

I am trying to fetch only the text part of an email and ignore attachments using imap in python. The only way I found out to do this is by first fetching the body structure of an email, parsing it, and choosing only the parts with the text. However, I am having a really hard time parsing the body structure. I have read RFC 3501 and I might have to write code by myself to parse it but it would be really helpful if there's a MIME handling package that can simply give me the BODY parts and their corresponding types.

So far I have fetched the body structure and went through the documentation for IMAP FETCH. I have code for extracting text from the text section, but I am getting no where with parsing body structure.

0

There are 0 answers