~rjarry/aerc-devel

aerc: imap: fix connection when host only has ipv6 address v1 APPLIED

Robin Jarry: 1
 imap: fix connection when host only has ipv6 address

 1 files changed, 3 insertions(+), 9 deletions(-)
#1143024 alpine-edge.yml success
#1143025 openbsd.yml success
Koni Marti, Feb 04, 2024 at 00:20:
Next
mcepl, Feb 04, 2024 at 11:31:
Next
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~rjarry/aerc-devel/patches/49165/mbox | git am -3
Learn more about email & git

[PATCH aerc] imap: fix connection when host only has ipv6 address Export this patch

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>
---
 worker/imap/connect.go | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/worker/imap/connect.go b/worker/imap/connect.go
index 818952accbe7..79254bb92c4e 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)

		newConn, err := net.Dial("tcp", addr)
		if err != nil {
			done <- tcpConn{nil, err}
			return
		}

		newConn, err := net.DialTCP("tcp", nil, addr)
		if err != nil {
			done <- tcpConn{nil, err}
			return
		}

		done <- tcpConn{newConn, nil}
		done <- tcpConn{newConn.(*net.TCPConn), nil}
	}()

	select {
-- 
2.43.0
aerc/patches: SUCCESS in 2m1s

[imap: fix connection when host only has ipv6 address][0] from [Robin Jarry][1]

[0]: https://lists.sr.ht/~rjarry/aerc-devel/patches/49165
[1]: mailto:robin@jarry.cc

✓ #1143025 SUCCESS aerc/patches/openbsd.yml     https://builds.sr.ht/~rjarry/job/1143025
✓ #1143024 SUCCESS aerc/patches/alpine-edge.yml https://builds.sr.ht/~rjarry/job/1143024
To confirm this patch (2187ea16 in tree) fixes IMAP for me :-)