- import imaplib, re
- # --- SETTINGS
- SERVER = "127.0.0.1"
- PORT = 143
- USER = "mail@box"
- PASSW = "..."
- # ---
- unreadCount = 0
- def connect():
- global unreadCount
- conn = imaplib.IMAP4(SERVER, PORT)
- conn.login(USER, PASSW)
- conn.select('INBOX', readonly=True)
- unreadCount = re.search("UNSEEN (\d+)", conn.status("INBOX", "(UNSEEN)")[1][0]).group(1)
- conn.close()
- conn.logout()
- def trigger(status):
- f = open('/sys/class/leds/alix:3/trigger', 'w')
- if status == 1:
- f.write('timer')
- f.close()
- f = open('/sys/class/leds/alix:3/delay_on', 'w')
- f.write('1000')
- f.close()
- f = open('/sys/class/leds/alix:3/delay_off', 'w')
- f.write('3000')
- f.close()
- else:
- f.write('none')
- f.close()
- trigger(0)
- connect()
- if int(unreadCount) > 0:
- trigger(1)