Best Python Library for Downloading and Extracting Addresses - python

I've just been given a project which involves the following steps
Grab an email from a POP3 address
Open an attachment from the email
Extract the To: email address
Add this to a global suppression list
I'd like to try and do this in Python even though I could it in PHP in half the time (this is because I dont know anywhere near as much Python as PHP)
My question would be.
Can anyone recommend a Python library for interacting with email in the way described above?
Many thanks in advance

Two bits from the standard library: poplib to grab the email via POP3, email to slice and dice it as you wish.

Related

How to decode a mail in Python whatever the encoding?

I'm working on a NLP project for classifying email in Python. The main goal is to build a model that automatically redirect mails to the good service. I try to build a database with only the customers text mail and their demand.
I started to load the emails on the pop server with poplib and it works good.
I'm looking for a solution to decode any mail whatever the encoding.
I'm really not expert with encodings and I use a code that doesn't always work, I can't figure out why ..
I remark that it doesn't work on old messages, probably they are archived in one more different encoding.
I need a method that can detect and decode systematically, I searched on the web for two days and found nothing! Only website which propose to do it but I would like to integrate it directly in my code. I only need the body of the mail.
Does such a package exist? And if yes, which ?
Thanks a lot for reading me

Is it possible to scrape mails within hotmail using Python?

Can this actually be done? Like checking if my browser is logged in and if so, scraw some of my emails? Or does hotmail prevent you from scraping your mails?
Yes actually very easily.
All you have to do is connect to a POP or IMAP(gmail,hotmail) and then manipulate data however you want.import smtplib
Here's a link documentation --- Stackoverflow question
--- POP -email --- Gmail
You can use regular expressions if you want to find something specific
Python RE-Regular Expressions
I don't know how would you check if you're already logged in, there isn't an obvious way to tell.
Of course it could be done but in some weird manner.

Deleting attachment from email using Python [duplicate]

This question already has answers here:
Python email lib - How to remove attachment from existing message?
(4 answers)
Closed 1 year ago.
I want to be able to delete just the attachment in an email and keep the text content. Can i do this using IMAPClient package?
I found this article which tells me there is some feature like that for mozilla thunderbird which is IMAP client. the link is :
http://www.howtogeek.com/112734/how-to-free-up-space-in-gmail-5-ways-to-reclaim-space/
how do i do this using imaplib or imapclient package in python 2.7?
I think you are getting this wrong. IMAPClient is an IMAP client, so it can handle Imap, thunderbird is also an email (including Imap) client, so It's redudant, you don't need this to use that. Unfortunately IMAPclient doesn't seem to have an attachment handling method (atleast what I could tell from the docs). but a quick google search pointed me to python's native imaplib as a possible candidate to do what you want together with python's email lib. the first to access you gmail acount, and the second to get the message. a possible (also not exactly your use case) scenerio is outlined in this [receipe]ץ(http://code.activestate.com/recipes/302086-strip-attachments-from-an-email-message/)
also a very similiar stackoverflow question.
the trick is that there isn't a detach attachment method in **email* lib. you have to reset the message payload to simulate this effect.

Using Python 3.3 to access blocked webpages

I'm trying to download webpages off the internet. I'm able to steal the HTML (with URLlib), but I can't download images correctly. There's already a question for that though. My question is, is there any way I can use python to bypass a firewall to access 'blocked' webpages?
Ideally it would be using some obscure code or module, but if it's impossible, could someone tell me a good workaround using a different method (like a proxy)?
If you want to extract images from a HTML page, you need to parse it with re module
import re
using regex to extract only the img src tag. You can also use a parser alredy written. For example BeautifulSoup > http://www.crummy.com/software/BeautifulSoup/
A firewall is a passive component of a perimeter defense into a computer network that can also serve as contact points between two or more sections of the network, ensuring a protection in terms of security of the network itself. So you have to work directly in the network, not through the code language.

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