aboutsummaryrefslogtreecommitdiffstats
path: root/worker
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2024-02-03 23:58:34 +0100
committerRobin Jarry <robin@jarry.cc>2024-02-04 10:20:56 +0100
commit2187ea163e879556cb9fdb45657c96d99db8a6f0 (patch)
tree055256d8623e33e687e7583fed8c36d1b65f3e7f /worker
parent6ea74eb3045735940dea005443f5e22a35a9a1a8 (diff)
downloadaerc-2187ea163e879556cb9fdb45657c96d99db8a6f0.tar.gz
imap: fix connection when host only has ipv6 address
Some IMAP servers report both IPv4 and IPv6 addresses from their DNS name: $ host imap.gmail.com imap.gmail.com has address 108.177.15.109 imap.gmail.com has address 108.177.15.108 imap.gmail.com has IPv6 address 2a00:1450:400c:c0a::6c imap.gmail.com has IPv6 address 2a00:1450:400c:c0a::6d ResolveTCPAddr actually returns the first *IPv4* address by default, unless the address string is an explicit IPv6 address. Directly use net.Dial which has a fast fallback mechanism. It first tries to connect with an IPv6 address (if any) and if that fails, it will retry with an IPv4 address (if any) before failing completely. Link: https://cs.opensource.google/go/go/+/refs/tags/go1.21.6:src/net/ipsock.go;l=81 Link: https://lists.sr.ht/~rjarry/aerc-discuss/%3CCYVLU3AOA00I.26I5IMAF3T4CK%40dow.land%3E Link: https://pkg.go.dev/net#Dial Reported-by: Jonathan Dowland <jon@dow.land> Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Koni Marti <koni.marti@gmail.com>
Diffstat (limited to 'worker')
-rw-r--r--worker/imap/connect.go10
1 files changed, 2 insertions, 8 deletions
diff --git a/worker/imap/connect.go b/worker/imap/connect.go
index 818952ac..79254bb9 100644
--- a/worker/imap/connect.go
+++ b/worker/imap/connect.go
@@ -123,19 +123,13 @@ func newTCPConn(addr string, timeout time.Duration) (*net.TCPConn, error) {
done := make(chan tcpConn)
go func() {
defer log.PanicHandler()
- addr, err := net.ResolveTCPAddr("tcp", addr)
- if err != nil {
- done <- tcpConn{nil, err}
- return
- }
- newConn, err := net.DialTCP("tcp", nil, addr)
+ newConn, err := net.Dial("tcp", addr)
if err != nil {
done <- tcpConn{nil, err}
return
}
-
- done <- tcpConn{newConn, nil}
+ done <- tcpConn{newConn.(*net.TCPConn), nil}
}()
select {