summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
author无闻 <u@gogs.io>2015-08-20 16:32:13 +0800
committer无闻 <u@gogs.io>2015-08-20 16:32:13 +0800
commit9b01a3501b8c1897a9c02bf82dcc169a20b9a51f (patch)
treee0f01fa44ed1c0b1fc725a867a44847a49a74d4c
parent9b42f53aa833a6ca54dd48ca0e3cdaff984aa793 (diff)
parentd720c92d995131c19a5cb2bb55f54b804fda4cc4 (diff)
downloadgitea-9b01a3501b8c1897a9c02bf82dcc169a20b9a51f.tar.gz
gitea-9b01a3501b8c1897a9c02bf82dcc169a20b9a51f.zip
Merge pull request #1517 from haoyixin/master
Added supported of 'AUTH LOGIN'
-rw-r--r--modules/mailer/mailer.go32
1 files changed, 31 insertions, 1 deletions
diff --git a/modules/mailer/mailer.go b/modules/mailer/mailer.go
index 9dafa93f91..4fbacf2912 100644
--- a/modules/mailer/mailer.go
+++ b/modules/mailer/mailer.go
@@ -12,11 +12,38 @@ import (
"net/smtp"
"os"
"strings"
-
+ "errors"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/setting"
)
+type loginAuth struct {
+ username, password string
+}
+
+//SMTP AUTH LOGIN Auth Handler
+func LoginAuth(username, password string) smtp.Auth {
+ return &loginAuth{username, password}
+}
+
+func (a *loginAuth) Start(server *smtp.ServerInfo) (string, []byte, error) {
+ return "LOGIN", []byte{}, nil
+}
+
+func (a *loginAuth) Next(fromServer []byte, more bool) ([]byte, error) {
+ if more {
+ switch string(fromServer) {
+ case "Username:":
+ return []byte(a.username), nil
+ case "Password:":
+ return []byte(a.password), nil
+ default:
+ return nil, errors.New("Unkown fromServer")
+ }
+ }
+ return nil, nil
+}
+
type Message struct {
To []string
From string
@@ -135,6 +162,9 @@ func sendMail(settings *setting.Mailer, recipients []string, msgContent []byte)
auth = smtp.CRAMMD5Auth(settings.User, settings.Passwd)
} else if strings.Contains(options, "PLAIN") {
auth = smtp.PlainAuth("", settings.User, settings.Passwd, host)
+ //Patch for AUTH LOGIN
+ } else if strings.Contains(options, "LOGIN") {
+ auth = LoginAuth(settings.User, settings.Passwd)
}
if auth != nil {