Skip to content

Instantly share code, notes, and snippets.

@Protoneer
Created January 5, 2015 02:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Protoneer/8172ac35ee84edebdf50 to your computer and use it in GitHub Desktop.
Save Protoneer/8172ac35ee84edebdf50 to your computer and use it in GitHub Desktop.
Kanboard create task from incoming emails
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