Compare commits
No commits in common. "main" and "v1.1.0" have entirely different histories.
2 changed files with 28 additions and 11 deletions
|
@ -22,9 +22,10 @@ var DatabaseBackend = smtp.DatabaseBackend{
|
|||
|
||||
// AuthenticationBackend is a smtp.AuthenticationBackend implementation that always returns a fixed address for Authenticate.
|
||||
var AuthenticationBackend = smtp.AuthenticationBackend{
|
||||
Authenticate: func(initial string, conn *textproto.Conn) (smtp.CheckAddress, error) {
|
||||
return func(address *smtp.Address) (bool, error) {
|
||||
return true, nil
|
||||
Authenticate: func(initial string, conn *textproto.Conn) (*smtp.Address, error) {
|
||||
return &smtp.Address{
|
||||
Name: "test",
|
||||
Address: "example.org",
|
||||
}, nil
|
||||
},
|
||||
}
|
||||
|
|
32
smtp.go
32
smtp.go
|
@ -58,8 +58,7 @@ type DatabaseBackend struct {
|
|||
|
||||
// AuthenticationBackend is a struct that represents an authentication backend
|
||||
type AuthenticationBackend struct {
|
||||
Authenticate func(initial string, conn *textproto.Conn) (CheckAddress, error)
|
||||
SupportedMechanisms []string
|
||||
Authenticate func(initial string, conn *textproto.Conn) (CheckAddress, error)
|
||||
}
|
||||
|
||||
type CheckAddress func(*Address) (bool, error)
|
||||
|
@ -212,6 +211,8 @@ func (fr *Receiver) handleConnection(conn net.Conn) {
|
|||
return
|
||||
}
|
||||
|
||||
fmt.Println("Connection from", conn.RemoteAddr().String())
|
||||
|
||||
for {
|
||||
line, err := textProto.ReadLine()
|
||||
if err != nil {
|
||||
|
@ -282,9 +283,6 @@ func (fr *Receiver) handleConnection(conn net.Conn) {
|
|||
if fr.enforceTLS {
|
||||
capabilities = append(capabilities, "250-REQUIRETLS")
|
||||
}
|
||||
if fr.auth.SupportedMechanisms != nil {
|
||||
capabilities = append(capabilities, "250-AUTH "+strings.Join(fr.auth.SupportedMechanisms, " "))
|
||||
}
|
||||
capabilities = append(capabilities, defaultCapabilities...)
|
||||
state.HELO = true
|
||||
err = speakMultiLine(textProto, capabilities)
|
||||
|
@ -326,7 +324,7 @@ func (fr *Receiver) handleConnection(conn net.Conn) {
|
|||
} else {
|
||||
checkAddress, err := fr.auth.Authenticate(strings.TrimPrefix(line, "AUTH "), textProto)
|
||||
if err != nil {
|
||||
_ = textProto.PrintfLine(err.Error())
|
||||
_ = textProto.PrintfLine("421 4.7.0 Temporary server error")
|
||||
_ = conn.Close()
|
||||
return
|
||||
}
|
||||
|
@ -590,6 +588,7 @@ func (fr *Receiver) handleConnection(conn net.Conn) {
|
|||
Host: strings.Split(conn.RemoteAddr().String(), ":")[0],
|
||||
}
|
||||
go sendEmail(SenderArgs{
|
||||
Hostname: fr.hostname,
|
||||
EnforceTLS: fr.enforceTLS,
|
||||
}, mail, fr.database, queueID)
|
||||
|
||||
|
@ -618,6 +617,7 @@ func (fr *Receiver) handleConnection(conn net.Conn) {
|
|||
|
||||
// SenderArgs is a struct that represents the arguments for the Sender
|
||||
type SenderArgs struct {
|
||||
Hostname string
|
||||
EnforceTLS bool
|
||||
}
|
||||
|
||||
|
@ -648,7 +648,7 @@ func Send(args SenderArgs, mail *Mail, conn net.Conn, mxHost string) (err error)
|
|||
return errors.New("unexpected greeting - " + line)
|
||||
}
|
||||
|
||||
err = textConn.PrintfLine("EHLO %s", mxHost)
|
||||
err = textConn.PrintfLine("EHLO %s", args.Hostname)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -682,11 +682,16 @@ func Send(args SenderArgs, mail *Mail, conn net.Conn, mxHost string) (err error)
|
|||
InsecureSkipVerify: false,
|
||||
})
|
||||
|
||||
err = tlsConn.Handshake()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
textConn = textproto.NewConn(tlsConn)
|
||||
|
||||
// Just use HELO, no point using EHLO when we already have all the capabilities
|
||||
// This also gets us out of using readMultilineCodeResponse
|
||||
err = textConn.PrintfLine("HELO %s", mxHost)
|
||||
err = textConn.PrintfLine("HELO %s", args.Hostname)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -709,7 +714,10 @@ func Send(args SenderArgs, mail *Mail, conn net.Conn, mxHost string) (err error)
|
|||
}
|
||||
|
||||
code, line, err = textConn.ReadCodeLine(0)
|
||||
fmt.Println(code, line, err)
|
||||
if err != nil {
|
||||
// For some reason the EHLO stuff ends up here
|
||||
fmt.Println("5")
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -724,7 +732,9 @@ func Send(args SenderArgs, mail *Mail, conn net.Conn, mxHost string) (err error)
|
|||
}
|
||||
|
||||
code, line, err = textConn.ReadCodeLine(0)
|
||||
fmt.Println(code, line, err)
|
||||
if err != nil {
|
||||
fmt.Println("6")
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -739,7 +749,9 @@ func Send(args SenderArgs, mail *Mail, conn net.Conn, mxHost string) (err error)
|
|||
}
|
||||
|
||||
code, line, err = textConn.ReadCodeLine(0)
|
||||
fmt.Println(code, line, err)
|
||||
if err != nil {
|
||||
fmt.Println("7")
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -759,7 +771,9 @@ func Send(args SenderArgs, mail *Mail, conn net.Conn, mxHost string) (err error)
|
|||
}
|
||||
|
||||
code, line, err = textConn.ReadCodeLine(0)
|
||||
fmt.Println(code, line, err)
|
||||
if err != nil {
|
||||
fmt.Println("8")
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -773,7 +787,9 @@ func Send(args SenderArgs, mail *Mail, conn net.Conn, mxHost string) (err error)
|
|||
}
|
||||
|
||||
code, line, err = textConn.ReadCodeLine(0)
|
||||
fmt.Println(code, line, err)
|
||||
if err != nil {
|
||||
fmt.Println("9")
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue