check unread count and update label

This commit is contained in:
Josh Holtrop 2011-07-07 13:07:10 -04:00
parent cf46b1b454
commit 2d704d0b9c

View File

@ -1,5 +1,6 @@
import gtk import gtk
import gobject
import imaplib import imaplib
class Window(object): class Window(object):
@ -11,6 +12,8 @@ class Window(object):
self.conf['width'] = 32 self.conf['width'] = 32
if not 'height' in self.conf: if not 'height' in self.conf:
self.conf['height'] = 32 self.conf['height'] = 32
if not 'mailbox' in self.conf:
self.conf['mailbox'] = 'Inbox'
sticky = True sticky = True
if 'sticky' in self.conf: if 'sticky' in self.conf:
sticky = self.conf['sticky'] sticky = self.conf['sticky']
@ -44,6 +47,8 @@ class Window(object):
self.connection = imaplib.IMAP4_SSL( self.connection = imaplib.IMAP4_SSL(
self.conf['server'], self.conf['port']) self.conf['server'], self.conf['port'])
self.connection.login(self.conf['user'], self.conf['password']) self.connection.login(self.conf['user'], self.conf['password'])
self.update()
gobject.timeout_add(5000, self.update)
except: except:
self.connection = None self.connection = None
@ -59,6 +64,18 @@ class Window(object):
self.conf['x'] = x self.conf['x'] = x
self.conf['y'] = y self.conf['y'] = y
def update(self):
if self.connection is not None:
try:
self.connection.select(self.conf['mailbox'])
msgs = self.connection.search(None, 'UnSeen')[1][0].split()
count = len(msgs)
self.label.set_text(str(count))
except:
self.connection = None
self.label.set_text('-')
return self.connection is not None
def destroy_event(self): def destroy_event(self):
self.disconnect() self.disconnect()
self.update_conf() self.update_conf()