From 1b6dd7ea3388fac8d4069fb7c1e820fa790a21f9 Mon Sep 17 00:00:00 2001 From: Raphael Scholer Date: Thu, 9 Jun 2016 22:11:43 +0200 Subject: [PATCH] imap - Catch socket.gaierror if no internet connection is available --- i3pystatus/mail/imap.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/i3pystatus/mail/imap.py b/i3pystatus/mail/imap.py index 58dc252..ebbe8e9 100644 --- a/i3pystatus/mail/imap.py +++ b/i3pystatus/mail/imap.py @@ -54,9 +54,14 @@ class IMAP(Backend): @property def unread(self): - conn = self.get_connection() - self.last = len(conn.search(None, "UnSeen")[1][0].split()) - return self.last + try: + conn = self.get_connection() + except socket.gaierror: + pass + else: + self.last = len(conn.search(None, "UnSeen")[1][0].split()) + finally: + return self.last Backend = IMAP