diff --git a/Window.py b/Window.py index 8409da7..0542d98 100755 --- a/Window.py +++ b/Window.py @@ -1,5 +1,6 @@ import gtk +import gobject import imaplib class Window(object): @@ -11,6 +12,8 @@ class Window(object): self.conf['width'] = 32 if not 'height' in self.conf: self.conf['height'] = 32 + if not 'mailbox' in self.conf: + self.conf['mailbox'] = 'Inbox' sticky = True if 'sticky' in self.conf: sticky = self.conf['sticky'] @@ -44,6 +47,8 @@ class Window(object): self.connection = imaplib.IMAP4_SSL( self.conf['server'], self.conf['port']) self.connection.login(self.conf['user'], self.conf['password']) + self.update() + gobject.timeout_add(5000, self.update) except: self.connection = None @@ -59,6 +64,18 @@ class Window(object): self.conf['x'] = x 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): self.disconnect() self.update_conf()