emersion / go-imap

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

Getting `in response: imapwire: expected CRLF, got "]"` error when listing mailboxes #639

Closed quzhi1 closed 2 months ago

quzhi1 commented 2 months ago

Hi @emersion ,

I am having trouble listing folders for an IMAP account. This is the IMAP settings:

If I use

mailboxes, err := c.List("", "*", nil).Collect()

I get this error

in response: imapwire: expected CRLF, got "]"

If I use openssl to list mailboxes directly, this is the response:

a LIST "" "*"
* LIST (\HasNoChildren \UnMarked) "." "Downtown Nampa"
* LIST (\HasNoChildren \UnMarked) "." "Restoration Systems"
* LIST (\HasNoChildren \UnMarked) "." Steidl
* LIST (\HasNoChildren \UnMarked) "." Stability
* LIST (\HasNoChildren \UnMarked) "." SHE
* LIST (\HasNoChildren \UnMarked) "." "SDI UT Holdings"
* LIST (\HasNoChildren \UnMarked) "." Revoice
* LIST (\HasNoChildren \UnMarked) "." "Rawson Technologies"
* LIST (\HasNoChildren \UnMarked) "." "QuickBooks Payments"
* LIST (\HasNoChildren \UnMarked) "." "Quality First"
* LIST (\HasNoChildren \UnMarked) "." QFC
* LIST (\HasNoChildren \UnMarked) "." "Potential Clients"
* LIST (\HasChildren \UnMarked) "." "Old Clients"
* LIST (\HasNoChildren \UnMarked) "." "Old Clients.Bright Beacon"
* LIST (\HasNoChildren \UnMarked) "." "Old Clients.AtoZ Construction"
* LIST (\HasNoChildren \UnMarked) "." "Old Clients.Cabrillo"
* LIST (\HasNoChildren \UnMarked) "." "Old Clients.ProGear (K-Mac)"
* LIST (\HasNoChildren \UnMarked) "." "Old Clients.Affordable Mirror"
* LIST (\HasNoChildren \UnMarked) "." "Old Clients.Synthepor"
* LIST (\HasNoChildren \UnMarked) "." "Old Clients.Dallmann"
* LIST (\HasNoChildren \UnMarked) "." "Old Clients.True Lawn Care"
* LIST (\HasNoChildren \UnMarked) "." "Old Clients.The Well"
* LIST (\HasNoChildren \UnMarked) "." "Old Clients.West to East"
* LIST (\HasNoChildren \UnMarked) "." "Old Clients.Boston Solar"
* LIST (\HasNoChildren \UnMarked) "." "North City PC"
* LIST (\HasNoChildren \UnMarked) "." "Noble Consulting"
* LIST (\HasNoChildren \UnMarked) "." Martini
* LIST (\HasNoChildren \UnMarked) "." "KL Creative"
* LIST (\HasNoChildren \UnMarked) "." HMG
* LIST (\HasNoChildren \UnMarked) "." "High Road"
* LIST (\HasNoChildren \UnMarked) "." "Cyber 301"
* LIST (\HasNoChildren \UnMarked) "." "Continuing Education"
* LIST (\HasNoChildren \UnMarked) "." "Clarity Focus"
* LIST (\HasNoChildren \UnMarked) "." "Breaking Chains"
* LIST (\HasNoChildren \UnMarked) "." "Bookkeeping Coach"
* LIST (\HasNoChildren \UnMarked) "." "Becky &- Mom"
* LIST (\HasChildren \UnMarked) "." "AP Lucas Info"
* LIST (\HasNoChildren \UnMarked) "." "AP Lucas Info.Jonah"
* LIST (\HasNoChildren \UnMarked) "." "AP Lucas Info.Taxes"
* LIST (\HasNoChildren \UnMarked) "." "AP Lucas Info.Computer"
* LIST (\HasNoChildren \UnMarked) "." "AP Lucas Info.Service Providers"
* LIST (\HasNoChildren \UnMarked) "." "AP Lucas Info.Marketing"
* LIST (\HasNoChildren \UnMarked) "." "AP Lucas Info.Ken Laymon"
* LIST (\HasNoChildren \UnMarked) "." "AP Lucas Info.Confirmations"
* LIST (\HasNoChildren \UnMarked) "." "AP Lucas Info.Insurance"
* LIST (\HasChildren \UnMarked) "." "AP Lucas Info.QuickBooks"
* LIST (\HasNoChildren \UnMarked) "." "AP Lucas Info.QuickBooks.Coaching"
* LIST (\HasNoChildren \UnMarked) "." "Alpine Youth Center"
* LIST (\HasNoChildren \UnMarked) "." "Alpine Construction"
* LIST (\HasNoChildren \UnMarked) "." "Allied Resource Corp"
* LIST (\HasNoChildren \UnMarked) "." ADP
* LIST (\HasNoChildren \UnMarked) "." "3rd Gen Inc"
* LIST (\HasNoChildren \Sent) "." "Sent Messages"
* LIST (\HasNoChildren \UnMarked \Trash) "." "Deleted Messages"
* LIST (\HasNoChildren \UnMarked \Junk) "." Junk
* LIST (\HasNoChildren \Drafts) "." Drafts
* LIST (\HasChildren \UnMarked) "." alucas@aplucasaccounting_com
* LIST (\HasNoChildren \UnMarked) "." alucas@aplucasaccounting_com.INBOX
* LIST (\HasChildren \UnMarked) "." alucas@aplucasaccounting_com.[Gmail]
* LIST (\HasNoChildren \UnMarked) "." "alucas@aplucasaccounting_com.[Gmail].All Mail"
* LIST (\HasNoChildren \UnMarked) "." alucas@aplucasaccounting_com.[Gmail].Trash
* LIST (\HasNoChildren \UnMarked) "." alucas@aplucasaccounting_com.[Gmail].Starred
* LIST (\HasNoChildren \UnMarked) "." alucas@aplucasaccounting_com.[Gmail].Spam
* LIST (\HasNoChildren \UnMarked) "." "alucas@aplucasaccounting_com.[Gmail].Sent Mail"
* LIST (\HasNoChildren \UnMarked) "." alucas@aplucasaccounting_com.[Gmail].Important
* LIST (\HasNoChildren \UnMarked) "." alucas@aplucasaccounting_com.Boomerang-Returned
* LIST (\HasNoChildren \UnMarked) "." "INBOX.APLucas Inbox"
* LIST (\HasChildren) "." INBOX
a OK List completed (0.003 + 0.000 + 0.002 secs).

I suspect go-imap library is struggling to parse this line of response

* LIST (\HasChildren \UnMarked) "." alucas@aplucasaccounting_com.[Gmail]

[ and ] are special characters, and they are not surrounded by quotation marks. Maybe this is causing the error? If so, how can I fix it?

quzhi1 commented 2 months ago

I guess this is a TODO item? https://github.com/emersion/go-imap/blob/v2/internal/imapwire/decoder.go#L402

quzhi1 commented 2 months ago

I submitted a pull request here: https://github.com/emersion/go-imap/pull/640 Can you take a look? 🙏

quzhi1 commented 2 months ago

Hi @emersion , can you take a look at the pull request above? I am not sure if my fix is correct... Thank you and hope you are doing good ❤️