Skip to content

Commit

Permalink
implement Happy Eyeballs
Browse files Browse the repository at this point in the history
This allows OfflineIMAP to not stall on malfunctional IPv6 connections,
and fall-back to a functional IPv4 connection, if faster, as described
in RFC6555.

Signed-off-by: Olivier Mehani <shtrom@ssji.net>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
  • Loading branch information
shtrom authored and nicolas33 committed Jun 10, 2019
1 parent 06ed00a commit 0d5496b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion offlineimap/imaplibutil.py
Expand Up @@ -19,6 +19,7 @@
import time
import subprocess
import threading
import rfc6555
import socket
import errno
import zlib
Expand Down Expand Up @@ -78,8 +79,15 @@ def _mesg(self, s, tn=None, secs=None):
def open_socket(self):
"""open_socket()
Open socket choosing first address family available."""
if self.af == socket.AF_UNSPEC:
# happy-eyeballs!
return rfc6555.create_connection((self.host, self.port))
else:
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, self.af, socket.SOCK_STREAM):
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.
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Expand Up @@ -2,3 +2,4 @@
six
gssapi[kerberos]
portalocker[cygwin]
rfc6555

0 comments on commit 0d5496b

Please sign in to comment.