2023-01-30 16:27:06 +03:00
|
|
|
package smtpserver
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/mjl-/mox/smtp"
|
|
|
|
)
|
|
|
|
|
|
|
|
func xcheckf(err error, format string, args ...any) {
|
|
|
|
if err != nil {
|
2023-03-10 13:32:34 +03:00
|
|
|
err := fmt.Errorf("%s: %w", fmt.Sprintf(format, args...), err)
|
|
|
|
panic(smtpError{smtp.C451LocalErr, smtp.SeSys3Other0, err.Error(), err, true, false})
|
2023-01-30 16:27:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type smtpError struct {
|
|
|
|
code int
|
|
|
|
secode string
|
2023-03-10 13:32:34 +03:00
|
|
|
errmsg string // Sent in response.
|
|
|
|
err error // If set, used in logging. Typically has same information as errmsg.
|
2023-01-30 16:27:06 +03:00
|
|
|
printStack bool
|
|
|
|
userError bool // If this is an error on the user side, which causes logging at a lower level.
|
|
|
|
}
|
|
|
|
|
2023-03-10 13:32:34 +03:00
|
|
|
func (e smtpError) Error() string { return e.errmsg }
|
2023-01-30 16:27:06 +03:00
|
|
|
func (e smtpError) Unwrap() error { return e.err }
|
|
|
|
|
|
|
|
func xsmtpErrorf(code int, secode string, userError bool, format string, args ...any) {
|
2023-03-10 13:32:34 +03:00
|
|
|
err := fmt.Errorf(format, args...)
|
|
|
|
panic(smtpError{code, secode, err.Error(), err, false, userError})
|
2023-01-30 16:27:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func xsmtpServerErrorf(codes codes, format string, args ...any) {
|
|
|
|
xsmtpErrorf(codes.code, codes.secode, false, format, args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func xsmtpUserErrorf(code int, secode string, format string, args ...any) {
|
|
|
|
xsmtpErrorf(code, secode, true, format, args...)
|
|
|
|
}
|