]> source.dussan.org Git - gitea.git/commitdiff
Revert unrelated changes for SMTP auth (#21767) (#21768)
authorwxiaoguang <wxiaoguang@gmail.com>
Thu, 10 Nov 2022 21:11:56 +0000 (05:11 +0800)
committerGitHub <noreply@github.com>
Thu, 10 Nov 2022 21:11:56 +0000 (16:11 -0500)
Backport #21767

The purpose of #18982 is to improve the SMTP mailer, but there were some
unrelated changes made to the SMTP auth in
https://github.com/go-gitea/gitea/pull/18982/commits/d60c43869420f5fc43ad19b454c9ae50dad65964

This PR reverts these unrelated changes, fix #21744

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
cmd/admin.go
routers/web/admin/auths.go
services/auth/source/smtp/auth.go
services/auth/source/smtp/source.go
services/auth/source/smtp/source_authenticate.go
services/forms/auth_form.go

index 525bc2cfcdbef4cefc1e8dd17816c87a9fe896e4..d33d17a53ddf099f4cea4ca62f1ef61d93e3a608 100644 (file)
@@ -413,9 +413,9 @@ var (
                        Usage: "SMTP Authentication Type (PLAIN/LOGIN/CRAM-MD5) default PLAIN",
                },
                cli.StringFlag{
-                       Name:  "addr",
+                       Name:  "host",
                        Value: "",
-                       Usage: "SMTP Addr",
+                       Usage: "SMTP Host",
                },
                cli.IntFlag{
                        Name:  "port",
@@ -955,8 +955,8 @@ func parseSMTPConfig(c *cli.Context, conf *smtp.Source) error {
                }
                conf.Auth = c.String("auth-type")
        }
-       if c.IsSet("addr") {
-               conf.Addr = c.String("addr")
+       if c.IsSet("host") {
+               conf.Host = c.String("host")
        }
        if c.IsSet("port") {
                conf.Port = c.Int("port")
index b79b317555966e912e93c62e807078cdfc81cde1..7ea8a52809e60f35e0901ead4f716fb9ec9e8a1a 100644 (file)
@@ -159,7 +159,7 @@ func parseLDAPConfig(form forms.AuthenticationForm) *ldap.Source {
 func parseSMTPConfig(form forms.AuthenticationForm) *smtp.Source {
        return &smtp.Source{
                Auth:           form.SMTPAuth,
-               Addr:           form.SMTPAddr,
+               Host:           form.SMTPHost,
                Port:           form.SMTPPort,
                AllowedDomains: form.AllowedDomains,
                ForceSMTPS:     form.ForceSMTPS,
index 487c049722e377f996208097289b2b867b86ce61..e8453fde69051672ca647f44aa588cb6831396e7 100644 (file)
@@ -58,10 +58,10 @@ var ErrUnsupportedLoginType = errors.New("Login source is unknown")
 func Authenticate(a smtp.Auth, source *Source) error {
        tlsConfig := &tls.Config{
                InsecureSkipVerify: source.SkipVerify,
-               ServerName:         source.Addr,
+               ServerName:         source.Host,
        }
 
-       conn, err := net.Dial("tcp", net.JoinHostPort(source.Addr, strconv.Itoa(source.Port)))
+       conn, err := net.Dial("tcp", net.JoinHostPort(source.Host, strconv.Itoa(source.Port)))
        if err != nil {
                return err
        }
@@ -71,7 +71,7 @@ func Authenticate(a smtp.Auth, source *Source) error {
                conn = tls.Client(conn, tlsConfig)
        }
 
-       client, err := smtp.NewClient(conn, source.Addr)
+       client, err := smtp.NewClient(conn, source.Host)
        if err != nil {
                return fmt.Errorf("failed to create NewClient: %w", err)
        }
index b2286d42a0ff7ad13d95571e5cbee976705b9eea..5e69f912da35bee109b7ca27a732a7a6166dac85 100644 (file)
@@ -19,7 +19,7 @@ import (
 // Source holds configuration for the SMTP login source.
 type Source struct {
        Auth           string
-       Addr           string
+       Host           string
        Port           int
        AllowedDomains string `xorm:"TEXT"`
        ForceSMTPS     bool
index 63fd3e55110b7eb5ef036c3c9529a7f3e6ab4c02..dff24d494ee0f6543c8c06854cfb44ba5babfa4c 100644 (file)
@@ -32,7 +32,7 @@ func (source *Source) Authenticate(user *user_model.User, userName, password str
        var auth smtp.Auth
        switch source.Auth {
        case PlainAuthentication:
-               auth = smtp.PlainAuth("", userName, password, source.Addr)
+               auth = smtp.PlainAuth("", userName, password, source.Host)
        case LoginAuthentication:
                auth = &loginAuthenticator{userName, password}
        case CRAMMD5Authentication:
index 9064be2cca38e14f666ddbd6bb9016624574c317..7e7c75675299be552a9d2a9f83e92e2b6592561b 100644 (file)
@@ -45,7 +45,7 @@ type AuthenticationForm struct {
        IsActive                      bool
        IsSyncEnabled                 bool
        SMTPAuth                      string
-       SMTPAddr                      string
+       SMTPHost                      string
        SMTPPort                      int
        AllowedDomains                string
        SecurityProtocol              int `binding:"Range(0,2)"`