mirror of
https://github.com/mjl-/mox.git
synced 2025-06-28 01:08:15 +03:00

Once clients enable this extension, commands can no longer refer to "message sequence numbers" (MSNs), but can only refer to messages with UIDs. This means both sides no longer have to carefully keep their sequence numbers in sync (error-prone), and don't have to keep track of a mapping of sequence numbers to UIDs (saves resources). With UIDONLY enabled, all FETCH responses are replaced with UIDFETCH response.
66 lines
1.7 KiB
Go
66 lines
1.7 KiB
Go
package imapserver
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
)
|
|
|
|
func xcheckf(err error, format string, args ...any) {
|
|
if err != nil {
|
|
xserverErrorf("%s: %w", fmt.Sprintf(format, args...), err)
|
|
}
|
|
}
|
|
|
|
type userError struct {
|
|
code string // Optional response code in brackets.
|
|
err error
|
|
}
|
|
|
|
func (e userError) Error() string { return e.err.Error() }
|
|
func (e userError) Unwrap() error { return e.err }
|
|
|
|
func xuserErrorf(format string, args ...any) {
|
|
panic(userError{err: fmt.Errorf(format, args...)})
|
|
}
|
|
|
|
func xusercodeErrorf(code, format string, args ...any) {
|
|
panic(userError{code: code, err: fmt.Errorf(format, args...)})
|
|
}
|
|
|
|
type serverError struct{ err error }
|
|
|
|
func (e serverError) Error() string { return e.err.Error() }
|
|
func (e serverError) Unwrap() error { return e.err }
|
|
|
|
func xserverErrorf(format string, args ...any) {
|
|
panic(serverError{fmt.Errorf(format, args...)})
|
|
}
|
|
|
|
type syntaxError struct {
|
|
line string // Optional line to write before BAD result. For untagged response. CRLF will be added.
|
|
code string // Optional result code (between []) to write in BAD result.
|
|
errmsg string // BAD response message.
|
|
err error // Typically with same info as errmsg, but sometimes more.
|
|
}
|
|
|
|
func (e syntaxError) Error() string {
|
|
s := "bad syntax: " + e.errmsg
|
|
if e.code != "" {
|
|
s += " [" + e.code + "]"
|
|
}
|
|
return s
|
|
}
|
|
func (e syntaxError) Unwrap() error { return e.err }
|
|
|
|
func xsyntaxErrorf(format string, args ...any) {
|
|
errmsg := fmt.Sprintf(format, args...)
|
|
err := errors.New(errmsg)
|
|
panic(syntaxError{"", "", errmsg, err})
|
|
}
|
|
|
|
func xsyntaxCodeErrorf(code, format string, args ...any) {
|
|
errmsg := fmt.Sprintf(format, args...)
|
|
err := errors.New(errmsg)
|
|
panic(syntaxError{"", code, errmsg, err})
|
|
}
|