Attempt to address the broken SMTP sending (untested as of yet)

This commit is contained in:
Tracker-Friendly 2024-12-12 21:08:40 +00:00
parent 9f015b99c1
commit 1a1cc2a683
1 changed files with 24 additions and 9 deletions

33
smtp.go
View File

@ -214,7 +214,6 @@ func (fr *Receiver) handleConnection(conn net.Conn) {
for { for {
line, err := textProto.ReadLine() line, err := textProto.ReadLine()
fmt.Println(line)
if err != nil { if err != nil {
_ = textProto.PrintfLine("421 4.7.0 Temporary server error") _ = textProto.PrintfLine("421 4.7.0 Temporary server error")
_ = conn.Close() _ = conn.Close()
@ -296,8 +295,6 @@ func (fr *Receiver) handleConnection(conn net.Conn) {
} }
} }
case strings.HasPrefix(line, "AUTH"): case strings.HasPrefix(line, "AUTH"):
fmt.Println("It's about time")
if !isSubmission { if !isSubmission {
err = textProto.PrintfLine("503 5.5.1 AUTH only allowed on submission port") err = textProto.PrintfLine("503 5.5.1 AUTH only allowed on submission port")
if err != nil { if err != nil {
@ -329,7 +326,7 @@ func (fr *Receiver) handleConnection(conn net.Conn) {
} else { } else {
checkAddress, err := fr.auth.Authenticate(strings.TrimPrefix(line, "AUTH "), textProto) checkAddress, err := fr.auth.Authenticate(strings.TrimPrefix(line, "AUTH "), textProto)
if err != nil { if err != nil {
_ = textProto.PrintfLine("421 4.7.0 Temporary server error") _ = textProto.PrintfLine(err.Error())
_ = conn.Close() _ = conn.Close()
return return
} }
@ -593,7 +590,6 @@ func (fr *Receiver) handleConnection(conn net.Conn) {
Host: strings.Split(conn.RemoteAddr().String(), ":")[0], Host: strings.Split(conn.RemoteAddr().String(), ":")[0],
} }
go sendEmail(SenderArgs{ go sendEmail(SenderArgs{
Hostname: fr.hostname,
EnforceTLS: fr.enforceTLS, EnforceTLS: fr.enforceTLS,
}, mail, fr.database, queueID) }, mail, fr.database, queueID)
@ -622,13 +618,32 @@ func (fr *Receiver) handleConnection(conn net.Conn) {
// SenderArgs is a struct that represents the arguments for the Sender // SenderArgs is a struct that represents the arguments for the Sender
type SenderArgs struct { type SenderArgs struct {
Hostname string
EnforceTLS bool EnforceTLS bool
} }
type DebugRWC struct {
net.Conn
}
func (d DebugRWC) Write(p []byte) (n int, err error) {
fmt.Println("Write: ", string(p))
return d.Conn.Write(p)
}
func (d DebugRWC) Read(p []byte) (n int, err error) {
n, err = d.Conn.Read(p)
fmt.Println("Read: ", string(p))
return
}
func (d DebugRWC) Close() error {
fmt.Println("Close")
return d.Conn.Close()
}
// Send sends an email to another server // Send sends an email to another server
func Send(args SenderArgs, mail *Mail, conn net.Conn, mxHost string) (err error) { func Send(args SenderArgs, mail *Mail, conn net.Conn, mxHost string) (err error) {
textConn := textproto.NewConn(conn) textConn := textproto.NewConn(DebugRWC{conn})
err = textConn.PrintfLine("RSET") err = textConn.PrintfLine("RSET")
if err != nil { if err != nil {
@ -653,7 +668,7 @@ func Send(args SenderArgs, mail *Mail, conn net.Conn, mxHost string) (err error)
return errors.New("unexpected greeting - " + line) return errors.New("unexpected greeting - " + line)
} }
err = textConn.PrintfLine("EHLO %s", args.Hostname) err = textConn.PrintfLine("EHLO %s", mxHost)
if err != nil { if err != nil {
return err return err
} }
@ -696,7 +711,7 @@ func Send(args SenderArgs, mail *Mail, conn net.Conn, mxHost string) (err error)
// Just use HELO, no point using EHLO when we already have all the capabilities // Just use HELO, no point using EHLO when we already have all the capabilities
// This also gets us out of using readMultilineCodeResponse // This also gets us out of using readMultilineCodeResponse
err = textConn.PrintfLine("HELO %s", args.Hostname) err = textConn.PrintfLine("HELO %s", mxHost)
if err != nil { if err != nil {
return err return err
} }