imap

package module
v2.0.0-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2023 License: MIT Imports: 3 Imported by: 56

README

go-imap

builds.sr.ht status

An IMAP4rev2 library for Go.

License

MIT

Documentation

Overview

Package IMAP implements IMAP4rev2.

IMAP4rev2 is defined in RFC 9051.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cap

type Cap string

Cap represents an IMAP capability.

const (
	CapIMAP4rev1 Cap = "IMAP4rev1" // RFC 3501
	CapIMAP4rev2 Cap = "IMAP4rev2" // RFC 9051

	CapAuthPlain Cap = "AUTH=PLAIN"

	CapStartTLS      Cap = "STARTTLS"
	CapLoginDisabled Cap = "LOGINDISABLED"

	// Folded in IMAP4rev2
	CapNamespace    Cap = "NAMESPACE"     // RFC 2342
	CapUnselect     Cap = "UNSELECT"      // RFC 3691
	CapUIDPlus      Cap = "UIDPLUS"       // RFC 4315
	CapESearch      Cap = "ESEARCH"       // RFC 4731
	CapSearchRes    Cap = "SEARCHRES"     // RFC 5182
	CapEnable       Cap = "ENABLE"        // RFC 5161
	CapIdle         Cap = "IDLE"          // RFC 2177
	CapSASLIR       Cap = "SASL-IR"       // RFC 4959
	CapListExtended Cap = "LIST-EXTENDED" // RFC 5258
	CapListStatus   Cap = "LIST-STATUS"   // RFC 5819
	CapMove         Cap = "MOVE"          // RFC 6851
	CapLiteralMinus Cap = "LITERAL-"      // RFC 7888
	CapStatusSize   Cap = "STATUS=SIZE"   // RFC 8438

	CapACL              Cap = "ACL"                // RFC 4314
	CapAppendLimit      Cap = "APPENDLIMIT"        // RFC 7889
	CapBinary           Cap = "BINARY"             // RFC 3516
	CapCatenate         Cap = "CATENATE"           // RFC 4469
	CapChildren         Cap = "CHILDREN"           // RFC 3348
	CapCondStore        Cap = "CONDSTORE"          // RFC 7162
	CapConvert          Cap = "CONVERT"            // RFC 5259
	CapCreateSpecialUse Cap = "CREATE-SPECIAL-USE" // RFC 6154
	CapESort            Cap = "ESORT"              // RFC 5267
	CapFilters          Cap = "FILTERS"            // RFC 5466
	CapID               Cap = "ID"                 // RFC 2971
	CapLanguage         Cap = "LANGUAGE"           // RFC 5255
	CapListMyRights     Cap = "LIST-MYRIGHTS"      // RFC 8440
	CapLiteralPlus      Cap = "LITERAL+"           // RFC 7888
	CapLoginReferrals   Cap = "LOGIN-REFERRALS"    // RFC 2221
	CapMailboxReferrals Cap = "MAILBOX-REFERRALS"  // RFC 2193
	CapMetadata         Cap = "METADATA"           // RFC 5464
	CapMetadataServer   Cap = "METADATA-SERVER"    // RFC 5464
	CapMultiAppend      Cap = "MULTIAPPEND"        // RFC 3502
	CapMultiSearch      Cap = "MULTISEARCH"        // RFC 7377
	CapNotify           Cap = "NOTIFY"             // RFC 5465
	CapObjectID         Cap = "OBJECTID"           // RFC 8474
	CapPreview          Cap = "PREVIEW"            // RFC 8970
	CapQResync          Cap = "QRESYNC"            // RFC 7162
	CapQuota            Cap = "QUOTA"              // RFC 9208
	CapQuotaSet         Cap = "QUOTASET"           // RFC 9208
	CapReplace          Cap = "REPLACE"            // RFC 8508
	CapSaveDate         Cap = "SAVEDATE"           // RFC 8514
	CapSearchFuzzy      Cap = "SEARCH=FUZZY"       // RFC 6203
	CapSort             Cap = "SORT"               // RFC 5256
	CapSortDisplay      Cap = "SORT=DISPLAY"       // RFC 5957
	CapSpecialUse       Cap = "SPECIAL-USE"        // RFC 6154
	CapThread           Cap = "THREAD"             // RFC 5256
	CapUnauthenticate   Cap = "UNAUTHENTICATE"     // RFC 8437
	CapURLPartial       Cap = "URL-PARTIAL"        // RFC 5550
	CapURLAuth          Cap = "URLAUTH"            // RFC 4467
	CapWithin           Cap = "WITHIN"             // RFC 5032
)

Registered capabilities.

See: https://www.iana.org/assignments/imap-capabilities/

type CapSet

type CapSet map[Cap]struct{}

CapSet is a set of capabilities.

func (CapSet) AppendLimit

func (set CapSet) AppendLimit() (limit *uint32, ok bool)

AppendLimit checks the APPENDLIMIT capability.

If the server supports APPENDLIMIT, ok is true. If the server doesn't have the same upload limit for all mailboxes, limit is nil and per-mailbox limits must be queried via STATUS.

func (CapSet) Has

func (set CapSet) Has(c Cap) bool

Has checks whether a capability is supported.

Some capabilities are implied by others, as such Has may return true even if the capability is not in the map.

type Error

type Error StatusResponse

Error is an IMAP error caused by a status response.

func (*Error) Error

func (err *Error) Error() string

Error implements the error interface.

type Flag

type Flag string

Flag is a message flag.

Message flags are defined in RFC 9051 section 2.3.2.

const (
	// System flags
	FlagSeen     Flag = "\\Seen"
	FlagAnswered Flag = "\\Answered"
	FlagFlagged  Flag = "\\Flagged"
	FlagDeleted  Flag = "\\Deleted"
	FlagDraft    Flag = "\\Draft"

	// Widely used flags
	FlagForwarded Flag = "$Forwarded"
	FlagMDNSent   Flag = "$MDNSent" // Message Disposition Notification sent
	FlagJunk      Flag = "$Junk"
	FlagNotJunk   Flag = "$NotJunk"
	FlagPhishing  Flag = "$Phishing"
	FlagImportant Flag = "$Important" // RFC 8457

	// Permanent flags
	FlagWildcard Flag = "\\*"
)

type MailboxAttr

type MailboxAttr string

MailboxAttr is a mailbox attribute.

Mailbox attributes are defined in RFC 9051 section 7.3.1.

const (
	// Base attributes
	MailboxAttrNonExistent   MailboxAttr = "\\NonExistent"
	MailboxAttrNoInferiors   MailboxAttr = "\\Noinferiors"
	MailboxAttrNoSelect      MailboxAttr = "\\Noselect"
	MailboxAttrHasChildren   MailboxAttr = "\\HasChildren"
	MailboxAttrHasNoChildren MailboxAttr = "\\HasNoChildren"
	MailboxAttrMarked        MailboxAttr = "\\Marked"
	MailboxAttrUnmarked      MailboxAttr = "\\Unmarked"
	MailboxAttrSubscribed    MailboxAttr = "\\Subscribed"
	MailboxAttrRemote        MailboxAttr = "\\Remote"

	// Role (aka. "special-use") attributes
	MailboxAttrAll     MailboxAttr = "\\All"
	MailboxAttrArchive MailboxAttr = "\\Archive"
	MailboxAttrDrafts  MailboxAttr = "\\Drafts"
	MailboxAttrFlagged MailboxAttr = "\\Flagged"
	MailboxAttrJunk    MailboxAttr = "\\Junk"
	MailboxAttrSent    MailboxAttr = "\\Sent"
	MailboxAttrTrash   MailboxAttr = "\\Trash"
)

type ResponseCode

type ResponseCode string

ResponseCode is a response code.

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"
)

type Seq

type Seq struct {
	Start, Stop uint32
}

Seq represents a single seq-number or seq-range value (RFC 3501 ABNF). Values may be static (e.g. "1", "2:4") or dynamic (e.g. "*", "1:*"). A seq-number is represented by setting Start = Stop. Zero is used to represent "*", which is safe because seq-number uses nz-number rule. The order of values is always Start <= Stop, except when representing "n:*", where Start = n and Stop = 0.

func (Seq) Contains

func (s Seq) Contains(q uint32) bool

Contains returns true if the seq-number q is contained in sequence value s. The dynamic value "*" contains only other "*" values, the dynamic range "n:*" contains "*" and all numbers >= n.

func (Seq) Less

func (s Seq) Less(q uint32) bool

Less returns true if s precedes and does not contain seq-number q.

func (Seq) Merge

func (s Seq) Merge(t Seq) (union Seq, ok bool)

Merge combines sequence values s and t into a single union if the two intersect or one is a superset of the other. The order of s and t does not matter. If the values cannot be merged, s is returned unmodified and ok is set to false.

func (Seq) String

func (s Seq) String() string

String returns sequence value s as a seq-number or seq-range string.

type SeqSet

type SeqSet []Seq

SeqSet is used to represent a set of message sequence numbers or UIDs (see sequence-set ABNF rule). The zero value is an empty set.

func ParseSeqSet

func ParseSeqSet(set string) (SeqSet, error)

ParseSeqSet returns a new SeqSet after parsing the set string.

func SeqSetNum

func SeqSetNum(q ...uint32) SeqSet

SeqSetNum returns a new SeqSet containing the sequence numbers.

func SeqSetRange

func SeqSetRange(start, stop uint32) SeqSet

SeqSetRange returns a new SeqSet containing the sequence range.

func (*SeqSet) AddNum

func (s *SeqSet) AddNum(q ...uint32)

AddNum inserts new sequence numbers into the set. The value 0 represents "*".

func (*SeqSet) AddRange

func (s *SeqSet) AddRange(start, stop uint32)

AddRange inserts a new sequence range into the set.

func (*SeqSet) AddSet

func (s *SeqSet) AddSet(t SeqSet)

AddSet inserts all values from t into s.

func (SeqSet) Contains

func (s SeqSet) Contains(q uint32) bool

Contains returns true if the non-zero sequence number or UID q is contained in the set. The dynamic range "n:*" contains all q >= n. It is the caller's responsibility to handle the special case where q is the maximum UID in the mailbox and q < n (i.e. the set cannot match UIDs against "*:n" or "*" since it doesn't know what the maximum value is).

func (SeqSet) Dynamic

func (s SeqSet) Dynamic() bool

Dynamic returns true if the set contains "*" or "n:*" values.

func (SeqSet) Nums

func (s SeqSet) Nums() (nums []uint32, ok bool)

Nums returns a slice of all numbers contained in the sequence set.

func (SeqSet) String

func (s SeqSet) String() string

String returns a sorted representation of all contained sequence values.

type StatusResponse

type StatusResponse struct {
	Type StatusResponseType
	Code ResponseCode
	Text string
}

StatusResponse is a generic status response.

See RFC 9051 section 7.1.

type StatusResponseType

type StatusResponseType string

StatusResponseType is a generic status response type.

const (
	StatusResponseTypeOK      StatusResponseType = "OK"
	StatusResponseTypeNo      StatusResponseType = "NO"
	StatusResponseTypeBad     StatusResponseType = "BAD"
	StatusResponseTypePreAuth StatusResponseType = "PREAUTH"
	StatusResponseTypeBye     StatusResponseType = "BYE"
)

Directories

Path Synopsis
internal
imapwire
Package imapwire implements the IMAP wire protocol.
Package imapwire implements the IMAP wire protocol.
utf7
Package utf7 implements modified UTF-7 encoding defined in RFC 3501 section 5.1.3
Package utf7 implements modified UTF-7 encoding defined in RFC 3501 section 5.1.3

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL