How to Convert email from MBOX to EML using Python - python

Is there a way to convert some MBOX files to individual EML files using Python?
I have a client that downloaded his emails from GMail as MBOX collection. But I need to convert them to individual EML files so I can upload them to his new email client/server - which does not accept MBOX files.
Thanks in advance for any feedback.
UPDATE:
I have no code yet. I am wondering if it's even possible to do this via a small app, if not I'll purchase one of those available online. Just thought it would be cool to try it myself first.
Also, from my understanding, an mbox is a collection of emails (.eml files) and a single email would be just an .eml file.

Related

Is there a way to search for user defined strings in different outlook attachments using python?

Currently i am working on a project where i have to extract attachments and e-mails from outlook and check whether a user defined string present in them or not. I've completed the extraction part but still searching for a way to search for text/string within the attached documents. Is there a way to this by using python?
For Microsoft Office files you can:
Automate Office applications.
Use the open xml SDK if you deal with open XML documents only.
Use third-party libraries for dealing with documents.
It is up to you which way is to choose.

Encrypt a file with a password to send via email in python

Here is what I need to do in python:
Take a CSV from a saved location. Encrypt it. Send it via email.
We have a report that creates a csv every week and it needs to get emailed to someone. When they open the attachment from their email, it needs to ask them to input a predetermined password before they can view the csv contents.
I know how to send email with attachments using the smtp and mime modules.
I don't really know much about encryption but most of my searches turn up for files that are going to also be DEcrypted by python, or for encrypting passwords themselves.
Is asking for password upon opening a .csv file possible? Are there any resources out there for tutorials on this?
As an unsophisticated approach, you could zip the csv file that requires a password to unzip. This is a simple command line option (to the zip utility) that you could call from Python, then attach the resulting file. This wouldn't give you the best encryption, but may serve your purpose. See this link on using stronger encryption with zip archives.

Form through Email that can be Parsed Using Python

I want to email out a document that will be filled in by many people and emailed back to me. I will then parse the responses using Python and load them into my database.
What is the best format to send out the initial document in?
I was thinking an interactive .pdf but do not want to have to pay for Adobe XI. Alternatively maybe a .html file but I'm not sure how easy it is to save the state of it once its been filled in in order to be emailed back to me. A .xls file may also be a solution but I'm leaning away from it simply because it would not be a particularly professional looking format.
The key points are:
Answers can be easily parsed using Python
The format should common enough to open on most computers
The document should look relatively pleasing to the eye
Send them a web-page with a FORM section, complete with some Javascript to grab the contents of the controls and send them to you (e.g. in JSON format) when they press "submit".
Another option is to set it up as a web application. There are several Python web frameworks that could be used for that. You could then e-mail people a link to the web-app.
Why don't you use Google Docs for the form. Create the form in Google Docs and save the answer in an excel sheet. And then use any python Excel format reader (Google them) to read the file. This way you don't need to parse through mails and will be performance friendly too. Or you could just make a simple form using AppEngine and save the data directly to the database.

Python lib for publishing email to web

I want to read email and publish it to the web. Is there a good python library available to read email, understand headers, data, attachments etc. and which can easily convert this data to web publishable format?
Try python email module
This tutorial will also be helpful.

How to access GMail (IMAP Email) from my Shell/Python script to download a zip file attached to an email and process it?

I have to process a file everyday. This file is sent to my Email once everyday. If I can get to this email once every day and download the attachment, that had be awesome. Is it even remotely possible to do such a thing?
Thanks!
Please see How can I download all emails with attachments from Gmail? for a practical example.
This is certainly possible. Check out imaplib in Python's standard library; with it doing what you want should be quite straightforward. Also, you can process zip files directly in Python using the zipfile library.
Your best bet is to create an IMAP Folder for your daily emails to be sent to and then create a filter in GMail to send those files there. Your Python script can then check ONLY that folder on some interval and assume that whatever ends up in there is the file you want.
A quick search yielded sooo many results for IMAP fetching examples in Python, I'll leave that part up to you, but I will say that libgmail looks pretty neat.

Categories