[PLUG] Python and IMAP4 server...

Michael Christopher Robinson michael at robinson-west.com
Wed Jul 31 01:39:14 UTC 2019


I have my email hosted by Eskimo North.  I want to write a python
script to go through the spam folder and email me every subject of
every email in it.  Properly encoded of course as ASCII text.

Looks like I want to use imaplib.

I would like to eventually process the spam folder and move dangerous
emails...  would be nice if I could grab a subject list and say
quarantine message 10, 30, and 49 out of say 100 spam messages.
I'd also like to quarantine dangerous attachments or at least sanitize
them...

Been trying to get the subject list part done, not doing too well
though.

The following script doesn't seem to work:

#! /usr/bin/env python

import imaplib
from email.parser import HeaderParser

conn = imaplib.IMAP4('mail.eskimo.com')
conn.login('fakeusername','fakepassword')
conn.select()
conn.search(None, 'ALL')
data = conn.fetch(1, '(BODY[HEADER])')

header_data = data[1][0][1]

parser = HeaderParser()
msg = parser.parsestr(header_data)

print msg.keys()

fakeusername and fakepassword are placeholders of course...




More information about the PLUG mailing list