summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-12-11 18:57:45 -0500
committerUnknwon <u@gogs.io>2015-12-11 18:57:45 -0500
commit76bdbcc969acd0e91cd3e10f5fdbfae3273df45b (patch)
treede64a92e96b84e7a636228c9e7a4fcad285b8189
parent477b4d3b50ec58998b3b078fadbef01eaf1fbeeb (diff)
downloadgitea-76bdbcc969acd0e91cd3e10f5fdbfae3273df45b.tar.gz
gitea-76bdbcc969acd0e91cd3e10f5fdbfae3273df45b.zip
#2152 fix SMTP authentication makes invalid assumption on protocol
-rw-r--r--models/login.go7
1 files changed, 6 insertions, 1 deletions
diff --git a/models/login.go b/models/login.go
index 1f248b4860..e36171a342 100644
--- a/models/login.go
+++ b/models/login.go
@@ -10,6 +10,7 @@ import (
"errors"
"fmt"
"net/smtp"
+ "net/textproto"
"strings"
"time"
@@ -371,7 +372,11 @@ func LoginUserSMTPSource(u *User, name, passwd string, sourceID int64, cfg *SMTP
}
if err := SMTPAuth(auth, cfg); err != nil {
- if strings.Contains(err.Error(), "Username and Password not accepted") {
+ // Check standard error format first,
+ // then fallback to worse case.
+ tperr, ok := err.(*textproto.Error)
+ if (ok && tperr.Code == 535) ||
+ strings.Contains(err.Error(), "Username and Password not accepted") {
return nil, ErrUserNotExist{0, name}
}
return nil, err