1package smtpserver
2
3import (
4 "fmt"
5
6 "github.com/mjl-/mox/smtp"
7)
8
9func xcheckf(err error, format string, args ...any) {
10 if err != nil {
11 err := fmt.Errorf("%s: %w", fmt.Sprintf(format, args...), err)
12 panic(smtpError{smtp.C451LocalErr, smtp.SeSys3Other0, err.Error(), err, true, false})
13 }
14}
15
16type smtpError struct {
17 code int
18 secode string
19 errmsg string // Sent in response.
20 err error // If set, used in logging. Typically has same information as errmsg.
21 printStack bool
22 userError bool // If this is an error on the user side, which causes logging at a lower level.
23}
24
25func (e smtpError) Error() string { return e.errmsg }
26func (e smtpError) Unwrap() error { return e.err }
27
28func xsmtpErrorf(code int, secode string, userError bool, format string, args ...any) {
29 err := fmt.Errorf(format, args...)
30 panic(smtpError{code, secode, err.Error(), err, false, userError})
31}
32
33func xsmtpServerErrorf(codes codes, format string, args ...any) {
34 xsmtpErrorf(codes.code, codes.secode, false, format, args...)
35}
36
37func xsmtpUserErrorf(code int, secode string, format string, args ...any) {
38 xsmtpErrorf(code, secode, true, format, args...)
39}
40