Created
January 5, 2015 02:16
-
-
Save Protoneer/8172ac35ee84edebdf50 to your computer and use it in GitHub Desktop.
Kanboard create task from incoming emails
This file contains hidden or 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
import imaplib | |
import email | |
mail = imaplib.IMAP4_SSL('imap.gmail.com') | |
mail.login('user','password') | |
mail.list() | |
# Out: list of "folders" aka labels in gmail. | |
mail.select("inbox") # connect to inbox. | |
mail.select('INBOX', readonly=True) | |
data = mail.search(None, "ALL") | |
ids = data[1][0] | |
id_list = ids.split() | |
for i in reversed(range(len(id_list)-9, len(id_list)+1)): | |
typ, msg_data = mail.fetch(str(i), '(RFC822)') | |
for response_part in msg_data: | |
if isinstance(response_part, tuple): | |
msg = email.message_from_string(response_part[1]) | |
##for header in [ 'subject', 'to', 'from' ]: | |
for header in [ 'subject','date','from']: | |
print '%-8s: %s' % (header.upper(), msg[header]) | |
print " " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment