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
Koni Marti, Feb 04, 2024 at 00:20:
> On Sun Feb 4, 2024 at 12:11 AM CET, Robin Jarry wrote:> > 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(-)> >>> ss(8) shows that the tcp socket for imaps is now IPv6 (was IPv4 before).>> Tested-by: Koni Marti <koni.marti@gmail.com>
Special FOSDEM live fix applied :)
Thanks!
On Sun Feb 4, 2024 at 12:11 AM CET, Robin Jarry wrote:
> Some IMAP servers report both IPv4 and IPv6 addresses from their DNS> name:
I seem to have the same problem with sending. I have here
outgoing = smtp://mcepl%40cepl.eu@redcrew.org
and
$ host redcrew.orgredcrew.org has address 37.157.195.192
redcrew.org has IPv6 address 2a02:2b88:2:1::1cde:1
redcrew.org mail is handled by 10 redcrew.org.
$
and when sending an email (actually sending Tested-by: to this patch ;))
I get error:
DEBUG 2024/02/04 11:40:49.097348 send.go:125: send config uri:
smtp://mcepl%40cepl.eu:verysecret@redcrew.org
DEBUG 2024/02/04 11:40:49.097398 send.go:126: send config scheme: smtp
DEBUG 2024/02/04 11:40:49.097402 send.go:127: send config auth: plain
DEBUG 2024/02/04 11:40:49.097415 send.go:128: send config from:
=?utf-8?q?Mat=C4=9Bj_Cepl?= <mcepl@cepl.eu>
DEBUG 2024/02/04 11:40:49.097424 send.go:129: send config rcpts: ["Robin
Jarry" <robin@jarry.cc> <~rjarry/aerc-devel@lists.sr.ht> "Jonathan
Dowland" <jon@dow.land>]
DEBUG 2024/02/04 11:40:49.097429 send.go:130: send config domain:
DEBUG 2024/02/04 11:40:49.097443 status.go:104: Sending...
DEBUG 2024/02/04 11:40:49.097459 send.go:175: send uri:
smtp://mcepl%40cepl.eu:%5DfJTTIuHF7zunkNd@redcrew.org
ERROR 2024/02/04 11:40:49.132260 status.go:129: send:: Connection
failed: smtp.Dial: dial tcp [2a02:2b88:2:1::1cde:1]:587: connect:
connection refused
DEBUG 2024/02/04 11:40:49.132294 status.go:104: send:: Connection
failed: smtp.Dial: dial tcp [2a02:2b88:2:1::1cde:1]:587: connect:
connection refused
Any idea what's going on?
Best,
Matěj
--
http://matej.ceplovi.cz/blog/, @mcepl@floss.social
GPG Finger: 3C76 A027 CA45 AD70 98B5 BC1D 7920 5802 880B C9D8
God is not worried about my financial situation.
mcepl, Feb 04, 2024 at 11:31:
> Any idea what's going on?
If IMAP works, maybe your SMTP server has the 587 port blocked on IPv6.
If you control the server, can you have a look at nft list ruleset
output?
On Sun Feb 4, 2024 at 10:31 AM GMT, wrote:
> On Sun Feb 4, 2024 at 12:11 AM CET, Robin Jarry wrote:> > Some IMAP servers report both IPv4 and IPv6 addresses from their DNS> > name:>> I seem to have the same problem with sending.
Me too, but I can't otherwise confirm that it's aerc (or go) at fault
(I can't send via neomutt today either)