diff --git a/Window.py b/Window.py index 1411b93..8409da7 100755 --- a/Window.py +++ b/Window.py @@ -5,6 +5,8 @@ import imaplib class Window(object): def __init__(self, title, conf): self.conf = conf + self.connection = None + if not 'width' in self.conf: self.conf['width'] = 32 if not 'height' in self.conf: @@ -26,6 +28,8 @@ class Window(object): self.window.add(self.label) + self.connect() + self.window.show_all() if 'x' in self.conf and 'y' in self.conf: @@ -35,6 +39,18 @@ class Window(object): def run(self): gtk.main() + def connect(self): + try: + self.connection = imaplib.IMAP4_SSL( + self.conf['server'], self.conf['port']) + self.connection.login(self.conf['user'], self.conf['password']) + except: + self.connection = None + + def disconnect(self): + if self.connection is not None: + self.connection = None + def update_conf(self): w, h = self.window.get_size() self.conf['width'] = w @@ -44,6 +60,7 @@ class Window(object): self.conf['y'] = y def destroy_event(self): + self.disconnect() self.update_conf() gtk.main_quit() return False