Created
January 20, 2017 15:52
-
-
Save dsprenkels/cebcbd5f4ce88bfd57384ab60a86779e to your computer and use it in GitHub Desktop.
example script for scraping IMAP mailboxes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import getpass | |
import email | |
import imaplib | |
HOST = 'dsprenkels.com' | |
USER = '[email protected]' | |
PASSWD = getpass.getpass() | |
MAILBOX = 'Voorraadcie.Reserveringen' | |
conn = imaplib.IMAP4_SSL(HOST) | |
typ, _ = conn.login(USER, PASSWD) | |
assert typ == 'OK' | |
typ, count = conn.select(MAILBOX) | |
assert typ == 'OK' | |
print("Downloading {} messages".format(count)) | |
typ, data = conn.search(None, 'ALL') | |
assert typ == 'OK' | |
messages = [] | |
for num in data[0].split(): | |
typ, data = conn.fetch(num, '(BODY[TEXT])') | |
assert typ == 'OK' | |
print('Message %s\n%s\n' % (num, data[0][1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment