emersion / go-imap

📥 An IMAP library for clients and servers
MIT License
2.09k stars 296 forks source link

Example code does not work with icloud account #502

Closed quzhi1 closed 1 year ago

quzhi1 commented 1 year ago

Hello,

Sorry for bothering you again. This issue is related to https://github.com/emersion/go-imap/issues/500. I was testing with an icloud account, and got the same issue for logging out.

The code I ran is still from this example: https://godocs.io/github.com/emersion/go-imap/v2/imapclient#example-Client. I changed username, password, and imap server url to icloud.

I also added this option to client:

option := &imapclient.Options{
    DebugWriter: os.Stdout,
}

This is the error I saw:

T1 LOGIN "quzhi65222714@icloud.com" "<redacted>"
* OK [CAPABILITY XAPPLEPUSHSERVICE IMAP4 IMAP4rev1 SASL-IR AUTH=ATOKEN AUTH=PLAIN] (2313B20-3ff771b405ab) mr36p00im-tygg11191201.me.com
T1 OK user quzhi65222714 logged in
T2 LIST "" "%"
* LIST () "/" "Archive"
* LIST (\Trash) "/" "Deleted Messages"
* LIST () "/" "Junk"
* LIST () "/" "Notes"
* LIST (\Sent) "/" "Sent Messages"
* LIST (\Noinferiors) "/" "INBOX"
* LIST () "/" "Drafts"
T2 OK LIST completed (took 1 ms)
2023/04/05 17:06:50 Found 7 mailboxes
2023/04/05 17:06:50  - Archive
2023/04/05 17:06:50  - Deleted Messages
2023/04/05 17:06:50  - Junk
2023/04/05 17:06:50  - Notes
2023/04/05 17:06:50  - Sent Messages
2023/04/05 17:06:50  - INBOX
2023/04/05 17:06:50  - Drafts
T3 SELECT INBOX
* 0 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1]
* OK [UIDNEXT 4]
* FLAGS (\Answered \Flagged \Draft \Deleted \Seen \Recent $MailFlagBit0 $MailFlagBit1 $MailFlagBit2 $Forwarded Redirected $NotJunk NotJunk)
* OK [PERMANENTFLAGS (\Answered \Flagged \Draft \Deleted \Seen \Recent $MailFlagBit0 $MailFlagBit1 $MailFlagBit2 $Forwarded Redirected $NotJunk NotJunk \*)]
T3 OK [READ-WRITE] SELECT completed (took 115 ms)
2023/04/05 17:06:51 Inbox contains 0 messages
T4 LOGOUT
* BYE
T4 OK !!
2023/04/05 17:06:51 failed to logout: in resp-text: imapwire: expected text, got "\r"
exit status 1

Can you apply the same fix for log out? This is your previous commit: https://github.com/emersion/go-imap/commit/c3a0eed56682f058228a45c1ef77e6fdfcb89cb1

emersion commented 1 year ago

Can you try https://github.com/emersion/go-imap/pull/503?

(Please note, I only fix these issues myself because go-imap v2 is pretty new, at some point I'll expect users to open pull requests to fix the bugs themselves instead.)

quzhi1 commented 1 year ago

Thanks for the fix @emersion . Really appreciate your work. 😄 I am still seeing errors in #503 , so I put error output in that PR.