From 48f2df426727f4cc869eebf7ce14ff2a5c731089 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolfo=20Garc=C3=ADa=20Pe=C3=B1as=20=28kix=29?= Date: Sat, 7 Aug 2021 20:33:06 +0200 Subject: [PATCH 1/2] Handle connection refused messages This patch handle the connection refused messages. One of these messages is related to returned zeros. --- offlineimap/imapserver.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/offlineimap/imapserver.py b/offlineimap/imapserver.py index fb533a0..6acb331 100644 --- a/offlineimap/imapserver.py +++ b/offlineimap/imapserver.py @@ -677,6 +677,13 @@ class IMAPServer: "for repository '%s'. Remote does not answer." % (self.hostname, self.repos), OfflineImapError.ERROR.REPO, exc_info()[2]) + elif e.args and \ + e.args[0][:35] == 'IMAP4 protocol error: socket error:': + raise OfflineImapError( + "Could not connect to remote server '{}' " + "for repository '{}'. Connection Refused.".format( + self.hostname, self.repos), + OfflineImapError.ERROR.CRITICAL) else: # re-raise all other errors raise From 6a888966075caa4888efd4dc09862ac0885ff9f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolfo=20Garc=C3=ADa=20Pe=C3=B1as=20=28kix=29?= Date: Sat, 7 Aug 2021 20:51:48 +0200 Subject: [PATCH 2/2] Handle socks connection errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch handles the socks connection problems. First, move the "msg" variable to the places where the variable is used. This variable could be unset in the for loop, so is better move to these places. This patch also removes the "msg" variable set in th except blocks, like except socket.error as msg, because the variable is not used. The patch also removes the "i" variable, not used. Finally, the patch correct some typos. Close: #67 Signed-off-by: Rodolfo García Peñas (kix) --- offlineimap/imaplibutil.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/offlineimap/imaplibutil.py b/offlineimap/imaplibutil.py index 5f6f6f9..13b2299 100644 --- a/offlineimap/imaplibutil.py +++ b/offlineimap/imaplibutil.py @@ -89,16 +89,15 @@ class UsefulIMAPMixIn: return self._open_socket_for_af(self.af) def _open_socket_for_af(self, af): - msg = (-1, 'could not open socket') for res in socket.getaddrinfo(self.host, self.port, af, socket.SOCK_STREAM): af, socktype, proto, canonname, sa = res try: - # use socket of our own, possiblly socksified socket. + # use socket of our own, possibly SOCKS socket. s = self.socket(af, socktype, proto) - except socket.error as msg: + except socket.error: continue try: - for i in (0, 1): + for _ in (0, 1): try: s.connect(sa) break @@ -106,12 +105,14 @@ class UsefulIMAPMixIn: if len(msg.args) < 2 or msg.args[0] != errno.EINTR: raise else: + msg = (-1, 'could not open socket') raise socket.error(msg) - except socket.error as msg: + except socket.error: s.close() continue break else: + msg = (-1, 'could not open socket') raise socket.error(msg) return s