Skip to content

Commit fb1d319

Browse files
author
Winni Neessen
authored
Merge pull request #95 from wneessen/94-login-auth-next-handler-should-unconditionally-succeed-if-more-is-false
Fix SMTP AUTH LOGIN method for servers with uncommon success messages
2 parents 3b3c1e6 + 39a9949 commit fb1d319

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

auth/auth_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ func TestAuth(t *testing.T) {
2222
authTests := []authTest{
2323
{
2424
LoginAuth("user", "pass", "testserver"),
25-
[]string{"Username:", "Password:", "2.7.0 Authentication successful", "Invalid:"},
25+
[]string{"Username:", "Password:", "Invalid:"},
2626
"LOGIN",
27-
[]string{"", "user", "pass", "", ""},
28-
[]bool{false, false, false, true},
27+
[]string{"", "user", "pass", ""},
28+
[]bool{false, false, true},
2929
},
3030
}
3131

auth/login.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"errors"
1010
"fmt"
1111
"net/smtp"
12-
"strings"
1312
)
1413

1514
type loginAuth struct {
@@ -23,10 +22,6 @@ const (
2322

2423
// ServerRespPassword represents the "Password:" response by the SMTP server
2524
ServerRespPassword = "Password:"
26-
27-
// ServerRespAuthSuccess represents the "Authentication successful:" response that is
28-
// by sent by some SMTP servers
29-
ServerRespAuthSuccess = "Authentication successful"
3025
)
3126

3227
// LoginAuth returns an Auth that implements the LOGIN authentication
@@ -70,10 +65,9 @@ func (a *loginAuth) Next(fromServer []byte, more bool) ([]byte, error) {
7065
return []byte(a.username), nil
7166
case ServerRespPassword:
7267
return []byte(a.password), nil
68+
default:
69+
return nil, fmt.Errorf("unexpected server response: %s", string(fromServer))
7370
}
7471
}
75-
if strings.HasSuffix(string(fromServer), ServerRespAuthSuccess) {
76-
return nil, nil
77-
}
78-
return nil, fmt.Errorf("unexpected server response: %s", string(fromServer))
72+
return nil, nil
7973
}

client_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"fmt"
1212
"net/smtp"
1313
"os"
14+
"strconv"
1415
"strings"
1516
"testing"
1617
"time"
@@ -1087,10 +1088,22 @@ func getTestConnection(auth bool) (*Client, error) {
10871088
if th == "" {
10881089
return nil, fmt.Errorf("no TEST_HOST set")
10891090
}
1090-
c, err := NewClient(th)
1091+
tp := 25
1092+
if tps := os.Getenv("TEST_PORT"); tps != "" {
1093+
tpi, err := strconv.Atoi(tps)
1094+
if err == nil {
1095+
tp = tpi
1096+
}
1097+
}
1098+
sv := false
1099+
if sve := os.Getenv("TEST_TLS_SKIP_VERIFY"); sve != "" {
1100+
sv = true
1101+
}
1102+
c, err := NewClient(th, WithPort(tp))
10911103
if err != nil {
10921104
return c, err
10931105
}
1106+
c.tlsconfig.InsecureSkipVerify = sv
10941107
if auth {
10951108
st := os.Getenv("TEST_SMTPAUTH_TYPE")
10961109
if st != "" {

0 commit comments

Comments
 (0)