From 1a1cc2a6839213db0749060d142c1afe9d3237f2 Mon Sep 17 00:00:00 2001 From: arzumify Date: Thu, 12 Dec 2024 21:08:40 +0000 Subject: [PATCH] Attempt to address the broken SMTP sending (untested as of yet) --- smtp.go | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/smtp.go b/smtp.go index 1421a88..9a889e2 100644 --- a/smtp.go +++ b/smtp.go @@ -214,7 +214,6 @@ func (fr *Receiver) handleConnection(conn net.Conn) { for { line, err := textProto.ReadLine() - fmt.Println(line) if err != nil { _ = textProto.PrintfLine("421 4.7.0 Temporary server error") _ = conn.Close() @@ -296,8 +295,6 @@ func (fr *Receiver) handleConnection(conn net.Conn) { } } case strings.HasPrefix(line, "AUTH"): - fmt.Println("It's about time") - if !isSubmission { err = textProto.PrintfLine("503 5.5.1 AUTH only allowed on submission port") if err != nil { @@ -329,7 +326,7 @@ func (fr *Receiver) handleConnection(conn net.Conn) { } else { checkAddress, err := fr.auth.Authenticate(strings.TrimPrefix(line, "AUTH "), textProto) if err != nil { - _ = textProto.PrintfLine("421 4.7.0 Temporary server error") + _ = textProto.PrintfLine(err.Error()) _ = conn.Close() return } @@ -593,7 +590,6 @@ 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) @@ -622,13 +618,32 @@ 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 } +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 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") 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) } - err = textConn.PrintfLine("EHLO %s", args.Hostname) + err = textConn.PrintfLine("EHLO %s", mxHost) if err != nil { 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 // This also gets us out of using readMultilineCodeResponse - err = textConn.PrintfLine("HELO %s", args.Hostname) + err = textConn.PrintfLine("HELO %s", mxHost) if err != nil { return err }