mirror of
https://github.com/mjl-/mox.git
synced 2025-07-14 03:34:37 +03:00
for imap/smtp syntax errors, only echo the remaining buffer if the connection is authenticated
This commit is contained in:
@ -8,23 +8,26 @@ import (
|
||||
|
||||
func xcheckf(err error, format string, args ...any) {
|
||||
if err != nil {
|
||||
panic(smtpError{smtp.C451LocalErr, smtp.SeSys3Other0, fmt.Errorf("%s: %w", fmt.Sprintf(format, args...), err), true, false})
|
||||
err := fmt.Errorf("%s: %w", fmt.Sprintf(format, args...), err)
|
||||
panic(smtpError{smtp.C451LocalErr, smtp.SeSys3Other0, err.Error(), err, true, false})
|
||||
}
|
||||
}
|
||||
|
||||
type smtpError struct {
|
||||
code int
|
||||
secode string
|
||||
err error
|
||||
errmsg string // Sent in response.
|
||||
err error // If set, used in logging. Typically has same information as errmsg.
|
||||
printStack bool
|
||||
userError bool // If this is an error on the user side, which causes logging at a lower level.
|
||||
}
|
||||
|
||||
func (e smtpError) Error() string { return e.err.Error() }
|
||||
func (e smtpError) Error() string { return e.errmsg }
|
||||
func (e smtpError) Unwrap() error { return e.err }
|
||||
|
||||
func xsmtpErrorf(code int, secode string, userError bool, format string, args ...any) {
|
||||
panic(smtpError{code, secode, fmt.Errorf(format, args...), false, userError})
|
||||
err := fmt.Errorf(format, args...)
|
||||
panic(smtpError{code, secode, err.Error(), err, false, userError})
|
||||
}
|
||||
|
||||
func xsmtpServerErrorf(codes codes, format string, args ...any) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package smtpserver
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
@ -40,8 +41,19 @@ func newParser(s string, smtputf8 bool, conn *conn) *parser {
|
||||
}
|
||||
|
||||
func (p *parser) xerrorf(format string, args ...any) {
|
||||
// For submission, send the remaining unparsed line. Otherwise, only log it.
|
||||
var err error
|
||||
errmsg := "bad syntax: " + fmt.Sprintf(format, args...)
|
||||
remaining := fmt.Sprintf(" (remaining %q)", p.orig[p.o:])
|
||||
if p.conn.account != nil {
|
||||
errmsg += remaining
|
||||
err = errors.New(errmsg)
|
||||
} else {
|
||||
err = errors.New(errmsg + remaining)
|
||||
}
|
||||
|
||||
// ../rfc/5321:2377
|
||||
xsmtpUserErrorf(smtp.C501BadParamSyntax, smtp.SeProto5Syntax2, "%s (remaining: %q)", fmt.Sprintf(format, args...), p.orig[p.o:])
|
||||
panic(smtpError{smtp.C501BadParamSyntax, smtp.SeProto5Syntax2, errmsg, err, false, true})
|
||||
}
|
||||
|
||||
func (p *parser) xutf8localparterrorf() {
|
||||
|
@ -669,7 +669,7 @@ func command(c *conn) {
|
||||
|
||||
var serr smtpError
|
||||
if errors.As(err, &serr) {
|
||||
c.writecodeline(serr.code, serr.secode, fmt.Sprintf("%s (%s)", serr.err, mox.ReceivedID(c.cid)), serr.err)
|
||||
c.writecodeline(serr.code, serr.secode, fmt.Sprintf("%s (%s)", serr.errmsg, mox.ReceivedID(c.cid)), serr.err)
|
||||
if serr.printStack {
|
||||
debug.PrintStack()
|
||||
}
|
||||
|
Reference in New Issue
Block a user