-
Notifications
You must be signed in to change notification settings - Fork 303
/
response.go
81 lines (70 loc) · 2.56 KB
/
response.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package imap
import (
"fmt"
"strings"
)
// StatusResponseType is a generic status response type.
type StatusResponseType string
const (
StatusResponseTypeOK StatusResponseType = "OK"
StatusResponseTypeNo StatusResponseType = "NO"
StatusResponseTypeBad StatusResponseType = "BAD"
StatusResponseTypePreAuth StatusResponseType = "PREAUTH"
StatusResponseTypeBye StatusResponseType = "BYE"
)
// ResponseCode is a response code.
type ResponseCode string
const (
ResponseCodeAlert ResponseCode = "ALERT"
ResponseCodeAlreadyExists ResponseCode = "ALREADYEXISTS"
ResponseCodeAuthenticationFailed ResponseCode = "AUTHENTICATIONFAILED"
ResponseCodeAuthorizationFailed ResponseCode = "AUTHORIZATIONFAILED"
ResponseCodeBadCharset ResponseCode = "BADCHARSET"
ResponseCodeCannot ResponseCode = "CANNOT"
ResponseCodeClientBug ResponseCode = "CLIENTBUG"
ResponseCodeContactAdmin ResponseCode = "CONTACTADMIN"
ResponseCodeCorruption ResponseCode = "CORRUPTION"
ResponseCodeExpired ResponseCode = "EXPIRED"
ResponseCodeHasChildren ResponseCode = "HASCHILDREN"
ResponseCodeInUse ResponseCode = "INUSE"
ResponseCodeLimit ResponseCode = "LIMIT"
ResponseCodeNonExistent ResponseCode = "NONEXISTENT"
ResponseCodeNoPerm ResponseCode = "NOPERM"
ResponseCodeOverQuota ResponseCode = "OVERQUOTA"
ResponseCodeParse ResponseCode = "PARSE"
ResponseCodePrivacyRequired ResponseCode = "PRIVACYREQUIRED"
ResponseCodeServerBug ResponseCode = "SERVERBUG"
ResponseCodeTryCreate ResponseCode = "TRYCREATE"
ResponseCodeUnavailable ResponseCode = "UNAVAILABLE"
ResponseCodeUnknownCTE ResponseCode = "UNKNOWN-CTE"
// METADATA
ResponseCodeTooMany ResponseCode = "TOOMANY"
ResponseCodeNoPrivate ResponseCode = "NOPRIVATE"
// APPENDLIMIT
ResponseCodeTooBig ResponseCode = "TOOBIG"
)
// StatusResponse is a generic status response.
//
// See RFC 9051 section 7.1.
type StatusResponse struct {
Type StatusResponseType
Code ResponseCode
Text string
}
// Error is an IMAP error caused by a status response.
type Error StatusResponse
var _ error = (*Error)(nil)
// Error implements the error interface.
func (err *Error) Error() string {
var sb strings.Builder
fmt.Fprintf(&sb, "imap: %v", err.Type)
if err.Code != "" {
fmt.Fprintf(&sb, " [%v]", err.Code)
}
text := err.Text
if text == "" {
text = "<unknown>"
}
fmt.Fprintf(&sb, " %v", text)
return sb.String()
}