Documentation ¶
Overview ¶
An IMAP4rev1 (RFC 3501) library written in Go. It can be used to build a client and/or a server and supports UTF-7.
Index ¶
- Constants
- func FormatAddressList(addrs []*Address) (fields []interface{})
- func FormatDate(t time.Time) string
- func FormatDateTime(t time.Time) string
- func FormatParamList(params map[string]string) []interface{}
- func FormatStringList(list []string) (fields []interface{})
- func IsParseError(err error) bool
- func ParseDate(f interface{}) (t time.Time, err error)
- func ParseDateTime(f interface{}) (t time.Time, err error)
- func ParseNumber(f interface{}) (uint32, error)
- func ParseParamList(fields []interface{}) (params map[string]string, err error)
- func ParseStringList(fields []interface{}) ([]string, error)
- func ReadResp(r *Reader) (out interface{}, err error)
- type Address
- type BodyPartName
- type BodySectionName
- type BodyStructure
- type Command
- type Commander
- type Conn
- type ConnState
- type ConnUpgrader
- type ContinuationResp
- type Envelope
- type ErrBadSeqSet
- type FlagsOp
- type Literal
- type MailboxInfo
- type MailboxStatus
- type Message
- type Parser
- type Quoted
- type Reader
- func (r *Reader) ReadAtom() (interface{}, error)
- func (r *Reader) ReadCrlf() (err error)
- func (r *Reader) ReadFields() (fields []interface{}, err error)
- func (r *Reader) ReadInfo() (info string, err error)
- func (r *Reader) ReadLine() (fields []interface{}, err error)
- func (r *Reader) ReadList() (fields []interface{}, err error)
- func (r *Reader) ReadLiteral() (literal *Literal, err error)
- func (r *Reader) ReadQuotedString() (str string, err error)
- func (r *Reader) ReadRespCode() (code string, fields []interface{}, err error)
- func (r *Reader) ReadSp() error
- type Resp
- type RespHandler
- type RespHandlerFrom
- type RespHandling
- type Responser
- type SearchCriteria
- type Seq
- type SeqSet
- func (s *SeqSet) Add(set string) error
- func (s *SeqSet) AddNum(q ...uint32)
- func (s *SeqSet) AddRange(Start, Stop uint32)
- func (s *SeqSet) AddSet(t *SeqSet)
- func (s *SeqSet) Clear()
- func (s SeqSet) Contains(q uint32) bool
- func (s SeqSet) Dynamic() bool
- func (s SeqSet) Empty() bool
- func (s SeqSet) String() string
- type StatusResp
- type StatusRespType
- type StringReader
- type Writer
- type WriterTo
Constants ¶
const ( Capability string = "CAPABILITY" Noop = "NOOP" Logout = "LOGOUT" StartTLS = "STARTTLS" Authenticate = "AUTHENTICATE" Login = "LOGIN" Select = "SELECT" Examine = "EXAMINE" Create = "CREATE" Delete = "DELETE" Rename = "RENAME" Subscribe = "SUBSCRIBE" Unsubscribe = "UNSUBSCRIBE" List = "LIST" Lsub = "LSUB" Status = "STATUS" Append = "APPEND" Check = "CHECK" Close = "CLOSE" Expunge = "EXPUNGE" Search = "SEARCH" Fetch = "FETCH" Store = "STORE" Copy = "COPY" Uid = "UID" )
IMAP4rev1 commands.
const ( // In the not authenticated state, the client MUST supply // authentication credentials before most commands will be // permitted. This state is entered when a connection starts // unless the connection has been pre-authenticated. NotAuthenticatedState ConnState = 1 // In the authenticated state, the client is authenticated and MUST // select a mailbox to access before commands that affect messages // will be permitted. This state is entered when a // pre-authenticated connection starts, when acceptable // authentication credentials have been provided, after an error in // selecting a mailbox, or after a successful CLOSE command. AuthenticatedState = 1 << 1 // In a selected state, a mailbox has been selected to access. // This state is entered when a mailbox has been successfully // selected. SelectedState = AuthenticatedState + 1<<2 // In the logout state, the connection is being terminated. This // state can be entered as a result of a client request (via the // LOGOUT command) or by unilateral action on the part of either // the client or server. LogoutState = 0 // ConnectedState is any state except LogoutState. ConnectedState = NotAuthenticatedState | AuthenticatedState | SelectedState )
const ( // Replace existing flags by new ones SetFlags FlagsOp = "FLAGS" // Add new flags AddFlags = "+FLAGS" // Remove existing flags RemoveFlags = "-FLAGS" )
const ( // It is not possible for any child levels of hierarchy to exist under this\ // name; no child levels exist now and none can be created in the future. NoInferiorsAttr = "\\Noinferiors" // It is not possible to use this name as a selectable mailbox. NoSelectAttr = "\\Noselect" // The mailbox has been marked "interesting" by the server; the mailbox // probably contains messages that have been added since the last time the // mailbox was selected. MarkedAttr = "\\Marked" // The mailbox does not contain any additional messages since the last time // the mailbox was selected. UnmarkedAttr = "\\Unmarked" )
Mailbox attributes definied in RFC 3501 section 7.2.2.
const ( MailboxFlags = "FLAGS" MailboxPermanentFlags = "PERMANENTFLAGS" MailboxMessages = "MESSAGES" MailboxRecent = "RECENT" MailboxUnseen = "UNSEEN" MailboxUidNext = "UIDNEXT" MailboxUidValidity = "UIDVALIDITY" )
Mailbox status items.
const ( SeenFlag = "\\Seen" AnsweredFlag = "\\Answered" FlaggedFlag = "\\Flagged" DeletedFlag = "\\Deleted" DraftFlag = "\\Draft" RecentFlag = "\\Recent" )
Message flags, defined in RFC 3501 section 2.3.2.
const ( // Refers to the entire part, including headers. EntireSpecifier = "" // Refers to the header of the part. Must include the final CRLF delimiting // the header and the body. HeaderSpecifier = "HEADER" // Refers to the text body of the part, omitting the header. TextSpecifier = "TEXT" // Refers to the MIME Internet Message Body header. Must include the final // CRLF delimiting the header and the body. MimeSpecifier = "MIME" )
Part specifiers described in RFC 3501 page 55.
const ( // The OK response indicates an information message from the server. When // tagged, it indicates successful completion of the associated command. // The untagged form indicates an information-only message. StatusOk StatusRespType = "OK" // The NO response indicates an operational error message from the // server. When tagged, it indicates unsuccessful completion of the // associated command. The untagged form indicates a warning; the // command can still complete successfully. StatusNo = "NO" // The BAD response indicates an error message from the server. When // tagged, it reports a protocol-level error in the client's command; // the tag indicates the command that caused the error. The untagged // form indicates a protocol-level error for which the associated // command can not be determined; it can also indicate an internal // server failure. StatusBad = "BAD" // The PREAUTH response is always untagged, and is one of three // possible greetings at connection startup. It indicates that the // connection has already been authenticated by external means; thus // no LOGIN command is needed. StatusPreauth = "PREAUTH" // The BYE response is always untagged, and indicates that the server // is about to close the connection. StatusBye = "BYE" )
Status response types defined in RFC 3501 section 7.1.
const ( CodeAlert = "ALERT" CodeBadCharset = "BADCHARSET" CodeCapability = "CAPABILITY" CodeParse = "PARSE" CodePermanentFlags = "PERMANENTFLAGS" CodeReadOnly = "READ-ONLY" CodeReadWrite = "READ-WRITE" CodeTryCreate = "TRYCREATE" CodeUidNext = "UIDNEXT" CodeUidValidity = "UIDVALIDITY" CodeUnseen = "UNSEEN" )
Status response codes defined in RFC 3501 section 7.1.
const SilentOp = ".SILENT"
Variables ¶
This section is empty.
Functions ¶
func FormatAddressList ¶
func FormatAddressList(addrs []*Address) (fields []interface{})
Format an address list to fields.
func FormatDate ¶
func FormatDateTime ¶
func FormatParamList ¶
func FormatStringList ¶
func FormatStringList(list []string) (fields []interface{})
Convert a string list to a field list.
func IsParseError ¶
IsParseError returns true if the provided error is a parse error produced by Reader.
func ParseDateTime ¶
func ParseParamList ¶
func ParseStringList ¶
Convert a field list to a string list.
Types ¶
type Address ¶
type Address struct { // The personal name. PersonalName string // The SMTP at-domain-list (source route). AtDomainList string // The mailbox name. MailboxName string // The host name. HostName string }
An address.
func ParseAddressList ¶
func ParseAddressList(fields []interface{}) (addrs []*Address)
Parse an address list from fields.
type BodyPartName ¶
type BodyPartName struct { // The specifier of the requested part. Specifier string // The part path. Parts indexes start at 1. Path []int // If Specifier is HEADER, contains header fields that will/won't be returned, // depending of the value of NotFields. Fields []string // If set to true, Fields is a blacklist of fields instead of a whitelist. NotFields bool }
A body part name.
func (*BodyPartName) String ¶
func (part *BodyPartName) String() (s string)
type BodySectionName ¶
type BodySectionName struct { *BodyPartName // If set to true, do not implicitely set the \Seen flag. Peek bool // The substring of the section requested. The first value is the position of // the first desired octet and the second value is the maximum number of // octets desired. Partial []int // contains filtered or unexported fields }
A body section name. See RFC 3501 page 55.
func NewBodySectionName ¶
func NewBodySectionName(s string) (section *BodySectionName, err error)
Parse a body section name.
func (*BodySectionName) ExtractPartial ¶
func (section *BodySectionName) ExtractPartial(b []byte) []byte
Returns a subset of the specified bytes matching the partial requested in the section name.
func (*BodySectionName) String ¶
func (section *BodySectionName) String() (s string)
type BodyStructure ¶
type BodyStructure struct { // The MIME type. MimeType string // The MIME subtype. MimeSubType string // The MIME parameters. Params map[string]string // The Content-Id header. Id string // The Content-Description header. Description string // The Content-Encoding header. Encoding string // The Content-Length header. Size uint32 // The children parts, if multipart. Parts []*BodyStructure // The envelope, if message/rfc822. Envelope *Envelope // The body structure, if message/rfc822. BodyStructure *BodyStructure // The number of lines, if text or message/rfc822. Lines uint32 // True if the body structure contains extension data. Extended bool // The Content-Disposition header. Disposition string // The Content-Language header, if multipart. Language []string // The content URI, if multipart. Location []string // The MD5 checksum. Md5 string }
A body structure. See RFC 3501 page 74.
func (*BodyStructure) Format ¶
func (bs *BodyStructure) Format() (fields []interface{})
func (*BodyStructure) Parse ¶
func (bs *BodyStructure) Parse(fields []interface{}) error
type Command ¶
type Command struct { // The command tag. It acts as a unique identifier for this command. If empty, // the command is untagged. Tag string // The command name. Name string // The command arguments. Arguments []interface{} }
A command.
type Commander ¶
type Commander interface {
Command() *Command
}
A value that can be converted to a command.
type Conn ¶
An IMAP connection.
func (*Conn) Upgrade ¶
func (c *Conn) Upgrade(upgrader ConnUpgrader) error
Upgrade a connection, e.g. wrap an unencrypted connection with an encrypted tunnel.
type ConnUpgrader ¶
A function that upgrades a connection.
This should only be used by libraries implementing an IMAP extension (e.g. COMPRESS).
type ContinuationResp ¶
type ContinuationResp struct { // The info message sent with the continuation request. Info string }
A continuation request.
func (*ContinuationResp) WriteTo ¶
func (r *ContinuationResp) WriteTo(w Writer) error
type Envelope ¶
type Envelope struct { // The message date. Date time.Time // The message subject. Subject string // The From header addresses. From []*Address // The message senders. Sender []*Address // The Reply-To header addresses. ReplyTo []*Address // The To header addresses. To []*Address // The Cc header addresses. Cc []*Address // The Bcc header addresses. Bcc []*Address // The In-Reply-To header. Contains the parent Message-Id. InReplyTo string // The Message-Id header. MessageId string }
A message envelope, ie. message metadata from its headers. See RFC 3501 page 77.
type ErrBadSeqSet ¶
type ErrBadSeqSet string
ErrBadSeqSet is used to report problems with the format of a sequence set value.
func (ErrBadSeqSet) Error ¶
func (err ErrBadSeqSet) Error() string
type MailboxInfo ¶
type MailboxInfo struct { // The mailbox attributes. Attributes []string // The server's path separator. Delimiter string // The mailbox name. Name string }
Basic mailbox info.
func (*MailboxInfo) Format ¶
func (info *MailboxInfo) Format() []interface{}
Format mailbox info to fields.
func (*MailboxInfo) Parse ¶
func (info *MailboxInfo) Parse(fields []interface{}) error
Parse mailbox info from fields.
type MailboxStatus ¶
type MailboxStatus struct { // The mailbox name. Name string // True if the mailbox is open in read-only mode. ReadOnly bool // The mailbox items that are currently filled in. Items []string // The mailbox flags. Flags []string // The mailbox permanent flags. PermanentFlags []string // The number of messages in this mailbox. Messages uint32 // The number of messages not seen since the last time the mailbox was opened. Recent uint32 // The number of unread messages. Unseen uint32 // The next UID. UidNext uint32 // Together with a UID, it is a unique identifier for a message. // Must be greater than or equal to 1. UidValidity uint32 }
A mailbox status.
type Message ¶
type Message struct { // The message sequence number. It must be greater than or equal to 1. SeqNum uint32 // The message items that are currently filled in. Items []string // The message body sections. Body map[*BodySectionName]*Literal // The message envelope. Envelope *Envelope // The message body structure (either BODYSTRUCTURE or BODY). BodyStructure *BodyStructure // The message flags. Flags []string // The date the message was received by th server. InternalDate time.Time // The message size. Size uint32 // The message unique identifier. It must be greater than or equal to 1. Uid uint32 }
A message.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
An IMAP reader.
func NewServerReader ¶
func (*Reader) ReadFields ¶
func (*Reader) ReadLiteral ¶
func (*Reader) ReadQuotedString ¶
func (*Reader) ReadRespCode ¶
type Resp ¶
type Resp struct { // The response tag. Can be either "" for untagged responses, "+" for continuation // requests or a previous command's tag. Tag string // The parsed response fields. Fields []interface{} }
A response. See RFC 3501 section 2.2.2
func NewUntaggedResp ¶
func NewUntaggedResp(fields []interface{}) *Resp
Create a new untagged response.
type RespHandlerFrom ¶
type RespHandlerFrom interface {
HandleFrom(hdlr RespHandler) error
}
Handles responses from a handler.
type RespHandling ¶
type RespHandling struct { Resp interface{} Accepts chan bool }
A response that can be either accepted or rejected by a handler.
func (*RespHandling) Accept ¶
func (h *RespHandling) Accept()
Accept this response. This means that the handler will process it.
func (*RespHandling) AcceptNamedResp ¶
func (h *RespHandling) AcceptNamedResp(name string) (fields []interface{}, accepted bool)
Accept this response if it has the specified name. If not, reject it.
func (*RespHandling) Reject ¶
func (h *RespHandling) Reject()
Reject this response. The handler cannot process it.
type Responser ¶
type Responser interface {
Response() *Resp
}
A value that can be converted to a Resp.
type SearchCriteria ¶
type SearchCriteria struct { SeqSet *SeqSet Answered bool Bcc string Before time.Time Body string Cc string Deleted bool Draft bool Flagged bool From string Header [2]string Keyword string Larger uint32 New bool Not *SearchCriteria Old bool On time.Time Or [2]*SearchCriteria Recent bool Seen bool SentBefore time.Time SentOn time.Time SentSince time.Time Since time.Time Smaller uint32 Subject string Text string To string Uid *SeqSet Unanswered bool Undeleted bool Undraft bool Unflagged bool Unkeyword string Unseen bool }
A search criteria. See RFC 3501 section 6.4.4 for a description of each field.
func (*SearchCriteria) Format ¶
func (c *SearchCriteria) Format() (fields []interface{})
Format search criteria to fields.
func (*SearchCriteria) Parse ¶
func (c *SearchCriteria) Parse(fields []interface{}) error
Parse search criteria from fields.
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 ¶
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.
type SeqSet ¶
type SeqSet struct {
Set []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 (*SeqSet) Add ¶
Add inserts new sequence values into the set. The string format is described by RFC 3501 sequence-set ABNF rule. If an error is encountered, all values inserted successfully prior to the error remain in the set.
func (*SeqSet) AddNum ¶
AddNum inserts new sequence numbers into the set. The value 0 represents "*".
func (SeqSet) Contains ¶
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).
type StatusResp ¶
type StatusResp struct { // The response tag. If empty, it defaults to *. Tag string // The status type. Type StatusRespType // The status code. // See https://www.iana.org/assignments/imap-response-codes/imap-response-codes.xhtml Code string // Arguments provided with the status code. Arguments []interface{} // The status info. Info string }
A status response. See RFC 3501 section 7.1
func (*StatusResp) Err ¶
func (r *StatusResp) Err() error
If this status is NO or BAD, returns an error with the status info. Otherwise, returns nil.
func (*StatusResp) WriteTo ¶
func (r *StatusResp) WriteTo(w Writer) error
type StringReader ¶
type StringReader interface { // ReadString reads until the first occurrence of delim in the input, // returning a string containing the data up to and including the delimiter. // See https://golang.org/pkg/bufio/#Reader.ReadString ReadString(delim byte) (line string, err error) }
A string reader.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
IMAP server backend interface.
|
IMAP server backend interface. |
memory
A memory backend.
|
A memory backend. |
An IMAP client.
|
An IMAP client. |
IMAP commands defined in RFC 3501.
|
IMAP commands defined in RFC 3501. |
IMAP responses defined in RFC 3501.
|
IMAP responses defined in RFC 3501. |
An IMAP server.
|
An IMAP server. |
Modified UTF-7 encoding defined in RFC 3501 section 5.1.3
|
Modified UTF-7 encoding defined in RFC 3501 section 5.1.3 |