Skip to content

Instantly share code, notes, and snippets.

Created February 4, 2013 21:50
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
email to LEDborg script for Raspberry Pi
import imaplib
import email
#connect to gmail
mail = imaplib.IMAP4_SSL('')
typ, data =, 'ALL')
for num in data[0].split():
typ, data = mail.fetch(num, '(RFC822)')
typ, data =, 'All')
ids = data[0]
id_list = ids.split()
# get most recent email id
latest_email_id = int( id_list[-1] )
for i in range( latest_email_id, latest_email_id-1, -1):
typ, data = mail.fetch( i, '(RFC822)')
for response_part in data:
if isinstance(response_part, tuple):
msg = email.message_from_string(response_part[1])
varSubject = msg['subject']
varFrom = msg['from']
varFrom = varFrom.replace('<','')
varFrom = varFrom.replace('>','')
if len( varSubject ) >35:
varSubject = varSubject[0:32] ='...'
#print the subject to test
print varSubject
#output the subject to the ledborg
LedBorg = open('/dev/ledborg', 'w')
del LedBorg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment