diff options
author | Christopher Speller <crspeller@gmail.com> | 2017-08-17 17:19:06 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-17 17:19:06 -0700 |
commit | 96eab1202717e073782ec399a4e0820cae15b1bb (patch) | |
tree | 011012982be971c7e9ef91466f026bc0956ac9a2 /vendor/gopkg.in/gomail.v2/auth.go | |
parent | 2c895ee66eed626721135acfcc48254c6e3f3b29 (diff) | |
download | chat-96eab1202717e073782ec399a4e0820cae15b1bb.tar.gz chat-96eab1202717e073782ec399a4e0820cae15b1bb.tar.bz2 chat-96eab1202717e073782ec399a4e0820cae15b1bb.zip |
Updating server dependancies. (#7246)
Diffstat (limited to 'vendor/gopkg.in/gomail.v2/auth.go')
-rw-r--r-- | vendor/gopkg.in/gomail.v2/auth.go | 52 |
1 files changed, 35 insertions, 17 deletions
diff --git a/vendor/gopkg.in/gomail.v2/auth.go b/vendor/gopkg.in/gomail.v2/auth.go index d28b83ab7..4bcdd0620 100644 --- a/vendor/gopkg.in/gomail.v2/auth.go +++ b/vendor/gopkg.in/gomail.v2/auth.go @@ -7,33 +7,51 @@ import ( "net/smtp" ) -// loginAuth is an smtp.Auth that implements the LOGIN authentication mechanism. -type loginAuth struct { +// plainAuth is an smtp.Auth that implements the PLAIN authentication mechanism. +// It fallbacks to the LOGIN mechanism if it is the only mechanism advertised +// by the server. +type plainAuth struct { username string password string host string + login bool } -func (a *loginAuth) Start(server *smtp.ServerInfo) (string, []byte, error) { - if !server.TLS { - advertised := false - for _, mechanism := range server.Auth { - if mechanism == "LOGIN" { - advertised = true - break - } - } - if !advertised { - return "", nil, errors.New("gomail: unencrypted connection") - } - } +func (a *plainAuth) Start(server *smtp.ServerInfo) (string, []byte, error) { if server.Name != a.host { return "", nil, errors.New("gomail: wrong host name") } - return "LOGIN", nil, nil + + var plain, login bool + for _, a := range server.Auth { + switch a { + case "PLAIN": + plain = true + case "LOGIN": + login = true + } + } + + if !server.TLS && !plain && !login { + return "", nil, errors.New("gomail: unencrypted connection") + } + + if !plain && login { + a.login = true + return "LOGIN", nil, nil + } + + return "PLAIN", []byte("\x00" + a.username + "\x00" + a.password), nil } -func (a *loginAuth) Next(fromServer []byte, more bool) ([]byte, error) { +func (a *plainAuth) Next(fromServer []byte, more bool) ([]byte, error) { + if !a.login { + if more { + return nil, errors.New("gomail: unexpected server challenge") + } + return nil, nil + } + if !more { return nil, nil } |