Search code examples
pythonparsingmimeemail-attachments

Is it possible to extract/reconstitute a MIME attachment from a text only representation of an email?


I'm writing in python, but this is more of a generic question.

When you go to gmail or similar and you look at an email with an attachment and you click "show original" or some such button you get a huge wall of alphanumerics. My question is: is it possible to take that giant string and turn it back into its original format in python? And if so, how would one go about doing that? I don't necessarily need an answer, just a starting point.

I forgot to add: I'm not allowed to use any already existing email parsers. It's a programming test for getting a job with a programming company. I CAN however look at source code and copy those ideas.


Solution

  • Yes. Look at the email module, particularly email.parser.