go-imap icon indicating copy to clipboard operation
go-imap copied to clipboard

Yahoo is not fetching email/folder list anymore

Open shamim083 opened this issue 4 years ago • 10 comments

Hi @emersion . Here is the sample code

package main

import (
	"log"

	"github.com/emersion/go-imap/client"
	"github.com/emersion/go-imap"
)

func main() {
	log.Println("Connecting to server...")

	// Connect to server
	c, err := client.DialTLS("imap.mail.yahoo.com:993", nil)
	if err != nil {
		log.Fatal(err)
	}
	log.Println("Connected")

	// Don't forget to logout
	defer c.Logout()

	// Login
	if err := c.Login("[email protected]", "app_password"); err != nil {
		log.Fatal(err)
	}
	log.Println("Logged in")

	// List mailboxes
	mailboxes := make(chan *imap.MailboxInfo, 10)
	done := make(chan error, 1)
	go func () {
		done <- c.List("", "*", mailboxes)
	}()

	log.Println("Mailboxes:")
	for m := range mailboxes {
		log.Println("* " + m.Name)
	}
	log.Println("hello...")
	if err := <-done; err != nil {
		log.Fatal("folder fetch error", err.Error())
	}
	log.Println("folder fetched...")
	// Select INBOX
	mbox, err := c.Select("INBOX", false)
	if err != nil {
		log.Fatal(err)
	}
	log.Println("Flags for INBOX:", mbox.Flags)

	// Get the last 4 messages
	from := uint32(1)
	to := mbox.Messages
	if mbox.Messages > 3 {
		// We're using unsigned integers here, only substract if the result is > 0
		from = mbox.Messages - 3
	}
	seqset := new(imap.SeqSet)
	seqset.AddRange(from, to)

	messages := make(chan *imap.Message, 10)
	done = make(chan error, 1)
	go func() {
		done <- c.Fetch(seqset, []imap.FetchItem{imap.FetchEnvelope}, messages)
	}()

	log.Println("Last 4 messages:")
	for msg := range messages {
		log.Println("* " + msg.Envelope.Subject)
	}

	if err := <-done; err != nil {
		log.Fatal(err)
	}

	log.Println("Done!")
}

I have added some logs to check if it was sending correct imap commands. Looks like it is.

2020/03/23 10:34:27 Connecting to server...
2020/03/23 10:34:28 added timeout..
2020/03/23 10:34:29 Connected
2020/03/23 10:34:29 cmd.Name LOGIN
2020/03/23 10:34:29 fields [F0c7tw LOGIN [email protected] app_password]
2020/03/23 10:34:29 len(fields) 4
2020/03/23 10:34:35 Logged in
2020/03/23 10:34:35 Mailboxes:
2020/03/23 10:34:35 c.ensureAuthenticated() true
2020/03/23 10:34:35 cmd &{ * false}
2020/03/23 10:34:35 cmd.Name LIST
2020/03/23 10:34:35 fields [iR9gCA LIST  *]
2020/03/23 10:34:35 len(fields) 4
2020/03/23 10:34:35 fields[2] [] 0
2020/03/23 10:34:39 c.execute error imap: connection closed
2020/03/23 10:34:39 hello...
2020/03/23 10:34:39 folder fetch errorimap: connection closed
exit status 1

Anybody can help me, please?.

shamim083 avatar Mar 23 '20 04:03 shamim083

Can you add

c.SetDebug(os.Stdout)

And copy-paste the output, removing any sensitive data?

emersion avatar Mar 23 '20 11:03 emersion

Thanks for the quick reply. I have added the line you mentioned.

2020/03/24 14:16:17 Connecting to server...
2020/03/24 14:16:17 added timeout..
2020/03/24 14:16:18 Connected
2020/03/24 14:16:18 cmd.Name NOOP
2020/03/24 14:16:18 fields [DuhLKw NOOP]
2020/03/24 14:16:18 len(fields) 2
2020/03/24 14:16:18 cmd.Name LOGIN
2020/03/24 14:16:18 fields [KJ6y3Q LOGIN [email protected] fake_password]
2020/03/24 14:16:18 len(fields) 4
KJ6y3Q LOGIN "[email protected]" "fake_password"
KJ6y3Q OK LOGIN completed
2020/03/24 14:16:19 Logged in
2020/03/24 14:16:19 Mailboxes:
2020/03/24 14:16:19 c.ensureAuthenticated() true
2020/03/24 14:16:19 cmd &{ * false}
2020/03/24 14:16:19 cmd.Name LIST
2020/03/24 14:16:19 fields [zrMOwg LIST  *]
2020/03/24 14:16:19 len(fields) 4
2020/03/24 14:16:19 fields[2] [] 0
zrMOwg LIST "" "*"
* BYE IMAP4rev1 Server logging out
2020/03/24 14:16:19 c.execute error imap: connection closed
2020/03/24 14:16:19 hello...
2020/03/24 14:16:19 folder fetch errorimap: connection closed
exit status 1

shamim083 avatar Mar 24 '20 08:03 shamim083

This sounds like a Yahoo server bug.

emersion avatar Mar 24 '20 09:03 emersion

But the email fetching works perfectly with nodemailer. Thanks for your time again.

shamim083 avatar Mar 24 '20 09:03 shamim083

Maybe they use different arguments in the LIST command. Debug logs would tell.

emersion avatar Mar 24 '20 09:03 emersion

It does not work with go version

go version go1.13.8 darwin/amd64

but works with

go version go1.12.17 darwin/amd64

shamim083 avatar Mar 24 '20 11:03 shamim083

Eh, interesting. That would be a Go net or crypto/tls bug then.

emersion avatar Mar 24 '20 11:03 emersion

Support for SSL version 3.0 (SSLv3) is now deprecated and will be removed in Go 1.14. Note that SSLv3 is the cryptographically broken protocol predating TLS.

SSLv3 was always disabled by default, other than in Go 1.12, when it was mistakenly enabled by default server-side. It is now again disabled by default. (SSLv3 was never supported client-side.)

Ed25519 certificates are now supported in TLS versions 1.2 and 1.3.

As announced in Go 1.12, Go 1.13 enables support for TLS 1.3 in the crypto/tls package by default. It can be disabled by adding the value tls13=0 to the GODEBUG environment variable. The opt-out will be removed in Go 1.14.

itsthisjustin avatar May 12 '20 23:05 itsthisjustin

It does not work with go version

go version go1.13.8 darwin/amd64

but works with

go version go1.12.17 darwin/amd64

@emersion Do you know if it works on any version older than 1.12? See my comment above with what changed between the two versions. There's a clue in there somewhere.

itsthisjustin avatar May 12 '20 23:05 itsthisjustin

Looks like it works well

go version go1.15 darwin/amd64

shamimevatix avatar Sep 07 '20 15:09 shamimevatix

Closing because this is unlikely to be a go-imap bug.

emersion avatar Mar 23 '23 11:03 emersion