From 05b758f6283c8307c99ea82a2a5f4291f3e75a41 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Tue, 15 Jan 2019 22:54:53 +0700 Subject: lib/smtp: export the field ServerInfo in Client struct The non nil ServerInfo indicate that client has been called EHLO or HELO before, which required for client to check whether server support AUTH extension or not. --- lib/smtp/client.go | 17 ++++++++++------- lib/smtp/client_test.go | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/smtp/client.go b/lib/smtp/client.go index a3bb520a..694ba35c 100644 --- a/lib/smtp/client.go +++ b/lib/smtp/client.go @@ -22,11 +22,14 @@ import ( // Client for SMTP. // type Client struct { - data []byte - buf bytes.Buffer - raddr *net.TCPAddr - conn net.Conn - serverInfo *ServerInfo + // ServerInfo contains the server information, from the response of + // EHLO command. + ServerInfo *ServerInfo + + data []byte + buf bytes.Buffer + raddr *net.TCPAddr + conn net.Conn } // @@ -128,7 +131,7 @@ func (cl *Client) Ehlo(domAddr string) (res *Response, err error) { } if res.Code == StatusOK { - cl.serverInfo = NewServerInfo(res) + cl.ServerInfo = NewServerInfo(res) return res, nil } @@ -197,7 +200,7 @@ func (cl *Client) MailTx(mail *MailTx) (res *Response, err error) { if len(mail.Recipients) == 0 { return nil, errors.New("SendMailTx: empty mail 'Recipients' parameter") } - if cl.serverInfo == nil { + if cl.ServerInfo == nil { res, err = cl.Ehlo("localhost") if err != nil { return nil, err diff --git a/lib/smtp/client_test.go b/lib/smtp/client_test.go index 1c04bfce..43e03f5c 100644 --- a/lib/smtp/client_test.go +++ b/lib/smtp/client_test.go @@ -64,7 +64,7 @@ func TestEhlo(t *testing.T) { test.Assert(t, "Ehlo", c.exp, got, true) test.Assert(t, "ServerInfo", c.expServerInfo, - testClient.serverInfo, true) + testClient.ServerInfo, true) } } -- cgit v1.3