go-imap
go-imap copied to clipboard
Getting raw responses
HI.
I want to get raw responses for logging. For example i want to log raw responses from Login()
and Authenticate()
even if it is ok. How can i get them. And the same question for Execute()
, can i get raw response in my handler ?
You can probably use Client.SetDebug
for this.
sometimes Client.SetDebug provides incomplete data
For example a small program with only Client.Login()
and Client.Logout()
has output
C- W4T8Sg LOGIN [email protected] 123123 C- pXeHOg LOGOUT S- * BYE IMAP4rev1 Server logging out
when the real tcp exchange looks like
S- * OK
IMAP4rev1 at imap.host.com:993 ready to talk with ::ffff:185.6.245.226:57620, 2018-Feb-20 15:59:20, KxODiS0qd8d1 C- W4T8Sg LOGIN [email protected] 123123 S- * CAPABILITY IMAP4rev1 CHILDREN UNSELECT LITERAL+ NAMESPACE XLIST BINARY UIDPLUS ENABLE ID IDLE MOVE S- W4T8Sg OK LOGIN Completed. C- pXeHOg LOGOUT S- * BYE IMAP4rev1 Server logging out S- pXeHOg OK LOGOUT completed
Found a strange behavior. As described before. The example bellow won't let you see anything like "123456 OK LOGIN Completed." or any other response from server.
c , _ := client.New(conn)
c.SetDebug(os.Stdout)
c.Login(user,pswd)
BUT.
If you add c.debug = os.Stdout
here
So the debug behaviour gets initialised before the first read from connection, everything works fine. And Stdout provides complete log.
I propose to add a function into "client" package. It might looks like this:
func NewWithDebug(conn net.Conn, debug io.Writer) (*Client, error){...}
This provides debug setup before Client initialisation.
However this "bug" looks strange. If i am doing something wrong, please tell me)
Fixed in v2.