emersion / go-imap

📥 An IMAP library for clients and servers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

v2 DebugWriter breaks LOGIN or any imap command

resolutecake opened this issue · comments

  • if the DebugWriter option is used as an argument to github.com/emersion/go-imap/v2/imapclient.New,
  • any invocation of github.com/emersion/go-imap/v2/imapclient.Client.Login will fail

this is because:

  • github.com/emersion/go-imap/v2/imaplicent.Options.wrapReadwriter
  • wraps net.Conn using io.MultiWriter
  • then that writer is wrapped by *bufio.Writer

Now Flush will always fail meaning the first command is sent out and then "short write" error occurs bufio.Writer.Flush

Multiple buffered wrapping does not work in Go

version: 0196200 12/26/2023

Actually, the root cause was that my debug writer did not update sent bytes, returns n int
This causes the short write.
If the debug writer fails, this error is indistinguishable from a communications failure

This is expected behavior. If the debug writer fails, it's normal for go-imap to return an error.