go-imap: github.com/emersion/go-imap Index | Files | Directories

package imap

import "github.com/emersion/go-imap"

Package imap implements IMAP4rev1 (RFC 3501).

Index

Package Files

command.go conn.go date.go imap.go literal.go logger.go mailbox.go message.go read.go response.go search.go seqset.go status.go write.go

Constants

const (
    // In the connecting state, the server has not yet sent a greeting and no
    // command can be issued.
    ConnectingState = 0

    // 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 << 0

    // 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 = 1 << 3

    // ConnectedState is either NotAuthenticatedState, AuthenticatedState or
    // SelectedState.
    ConnectedState = NotAuthenticatedState | AuthenticatedState | SelectedState
)
const (
    // Defined in RFC 3501 as date-text on page 83.
    DateLayout = "_2-Jan-2006"
    // Defined in RFC 3501 as date-time on page 83.
    DateTimeLayout = "_2-Jan-2006 15:04:05 -0700"
)

Date and time layouts. Dovecot adds a leading zero to dates:

https://github.com/dovecot/core/blob/4fbd5c5e113078e72f29465ccc96d44955ceadc2/src/lib-imap/imap-date.c#L166

Cyrus adds a leading space to dates:

https://github.com/cyrusimap/cyrus-imapd/blob/1cb805a3bffbdf829df0964f3b802cdc917e76db/lib/times.c#L543

GMail doesn't support leading spaces in dates used in SEARCH commands.

const (
    // SetFlags replaces existing flags by new ones.
    SetFlags FlagsOp = "FLAGS"
    // AddFlags adds new flags.
    AddFlags = "+FLAGS"
    // RemoveFlags removes 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 (
    SeenFlag     = "\\Seen"
    AnsweredFlag = "\\Answered"
    FlaggedFlag  = "\\Flagged"
    DeletedFlag  = "\\Deleted"
    DraftFlag    = "\\Draft"
    RecentFlag   = "\\Recent"
)

System message flags, defined in RFC 3501 section 2.3.2.

const (
    // Refers to the entire part, including headers.
    EntireSpecifier PartSpecifier = ""
    // 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 InboxName = "INBOX"

The primary mailbox, as defined in RFC 3501 section 5.1.

const TryCreateFlag = "\\*"

TryCreateFlag is a special flag in MailboxStatus.PermanentFlags indicating that it is possible to create new keywords by attempting to store those flags in the mailbox.

Variables

var CharsetReader func(charset string, r io.Reader) (io.Reader, error)

CharsetReader, if non-nil, defines a function to generate charset-conversion readers, converting from the provided charset into UTF-8. Charsets are always lower-case. utf-8 and us-ascii charsets are handled by default. One of the the CharsetReader's result values must be non-nil.

func CanonicalFlag Uses

func CanonicalFlag(flag string) string

CanonicalFlag returns the canonical form of a flag. Flags are case-insensitive.

If the flag is defined in RFC 3501, it returns the flag with the case of the RFC. Otherwise, it returns the lowercase version of the flag.

func CanonicalMailboxName Uses

func CanonicalMailboxName(name string) string

CanonicalMailboxName returns the canonical form of a mailbox name. Mailbox names can be case-sensitive or case-insensitive depending on the backend implementation. The special INBOX mailbox is case-insensitive.

func FormatAddressList Uses

func FormatAddressList(addrs []*Address) (fields []interface{})

Format an address list to fields.

func FormatMailboxName Uses

func FormatMailboxName(name string) interface{}

func FormatParamList Uses

func FormatParamList(params map[string]string) []interface{}

func FormatStringList Uses

func FormatStringList(list []string) (fields []interface{})

Convert a string list to a field list.

func IsParseError Uses

func IsParseError(err error) bool

IsParseError returns true if the provided error is a parse error produced by Reader.

func NewDebugWriter Uses

func NewDebugWriter(local, remote io.Writer) io.Writer

NewDebugWriter creates a new io.Writer that will write local network activity to local and remote network activity to remote.

func NewLockedWriter Uses

func NewLockedWriter(w io.Writer) io.Writer

NewLockedWriter - goroutine safe writer.

func ParseNamedResp Uses

func ParseNamedResp(resp Resp) (name string, fields []interface{}, ok bool)

ParseNamedResp attempts to parse a named data response.

func ParseNumber Uses

func ParseNumber(f interface{}) (uint32, error)

ParseNumber parses a number.

func ParseParamList Uses

func ParseParamList(fields []interface{}) (map[string]string, error)

func ParseString Uses

func ParseString(f interface{}) (string, error)

ParseString parses a string, which is either a literal, a quoted string or an atom.

func ParseStringList Uses

func ParseStringList(f interface{}) ([]string, error)

Convert a field list to a string list.

type Address Uses

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 Uses

func ParseAddressList(fields []interface{}) (addrs []*Address)

Parse an address list from fields.

func (*Address) Address Uses

func (addr *Address) Address() string

Address returns the mailbox address (e.g. "foo@example.org").

func (*Address) Format Uses

func (addr *Address) Format() []interface{}

Format an address to fields.

func (*Address) Parse Uses

func (addr *Address) Parse(fields []interface{}) error

Parse an address from fields.

type BodyPartName Uses

type BodyPartName struct {
    // The specifier of the requested part.
    Specifier PartSpecifier
    // 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) Equal Uses

func (part *BodyPartName) Equal(other *BodyPartName) bool

Equal checks whether two body part names are equal.

type BodySectionName Uses

type BodySectionName struct {
    BodyPartName

    // If set to true, do not implicitly 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 ParseBodySectionName Uses

func ParseBodySectionName(s FetchItem) (*BodySectionName, error)

ParseBodySectionName parses a body section name.

func (*BodySectionName) Equal Uses

func (section *BodySectionName) Equal(other *BodySectionName) bool

Equal checks whether two sections are equal.

func (*BodySectionName) ExtractPartial Uses

func (section *BodySectionName) ExtractPartial(b []byte) []byte

ExtractPartial returns a subset of the specified bytes matching the partial requested in the section name.

func (*BodySectionName) FetchItem Uses

func (section *BodySectionName) FetchItem() FetchItem

type BodyStructure Uses

type BodyStructure struct {

    // The MIME type (e.g. "text", "image")
    MIMEType string
    // The MIME subtype (e.g. "plain", "png")
    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 field value.
    Disposition string
    // The Content-Disposition header field parameters.
    DispositionParams map[string]string
    // The Content-Language header field, 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) Filename Uses

func (bs *BodyStructure) Filename() (string, error)

Filename parses the body structure's filename, if it's an attachment. An empty string is returned if the filename isn't specified. An error is returned if and only if a charset error occurs, in which case the undecoded filename is returned too.

func (*BodyStructure) Format Uses

func (bs *BodyStructure) Format() (fields []interface{})

func (*BodyStructure) Parse Uses

func (bs *BodyStructure) Parse(fields []interface{}) error

func (*BodyStructure) Walk Uses

func (bs *BodyStructure) Walk(f BodyStructureWalkFunc)

Walk walks the body structure tree, calling f for each part in the tree, including bs itself. The parts are visited in DFS pre-order.

type BodyStructureWalkFunc Uses

type BodyStructureWalkFunc func(path []int, part *BodyStructure) (walkChildren bool)

BodyStructureWalkFunc is the type of the function called for each body structure visited by BodyStructure.Walk. The path argument contains the IMAP part path (see BodyPartName).

The function should return true to visit all of the part's children or false to skip them.

type Command Uses

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.

func (*Command) Command Uses

func (cmd *Command) Command() *Command

Implements the Commander interface.

func (*Command) Parse Uses

func (cmd *Command) Parse(fields []interface{}) error

Parse a command from fields.

func (*Command) WriteTo Uses

func (cmd *Command) WriteTo(w *Writer) error

type Commander Uses

type Commander interface {
    Command() *Command
}

A value that can be converted to a command.

type Conn Uses

type Conn struct {
    net.Conn
    *Reader
    *Writer
    // contains filtered or unexported fields
}

An IMAP connection.

func NewConn Uses

func NewConn(conn net.Conn, r *Reader, w *Writer) *Conn

NewConn creates a new IMAP connection.

func (*Conn) Flush Uses

func (c *Conn) Flush() error

Flush writes any buffered data to the underlying connection.

func (*Conn) Info Uses

func (c *Conn) Info() *ConnInfo

func (*Conn) SetDebug Uses

func (c *Conn) SetDebug(w io.Writer)

SetDebug defines an io.Writer to which all network activity will be logged. If nil is provided, network activity will not be logged.

func (*Conn) Upgrade Uses

func (c *Conn) Upgrade(upgrader ConnUpgrader) error

Upgrade a connection, e.g. wrap an unencrypted connection with an encrypted tunnel.

func (*Conn) Wait Uses

func (c *Conn) Wait()

Called by reader/writer goroutines to wait for Upgrade to finish

func (*Conn) WaitReady Uses

func (c *Conn) WaitReady()

Called by Upgrader to wait for reader/writer goroutines to be ready for upgrade.

func (*Conn) Write Uses

func (c *Conn) Write(b []byte) (n int, err error)

Write implements io.Writer.

type ConnInfo Uses

type ConnInfo struct {
    RemoteAddr net.Addr
    LocalAddr  net.Addr

    // nil if connection is not using TLS.
    TLS *tls.ConnectionState
}

Underlying connection state information.

type ConnState Uses

type ConnState int

A connection state. See RFC 3501 section 3.

type ConnUpgrader Uses

type ConnUpgrader func(conn net.Conn) (net.Conn, error)

A function that upgrades a connection.

This should only be used by libraries implementing an IMAP extension (e.g. COMPRESS).

type ContinuationReq Uses

type ContinuationReq struct {
    // The info message sent with the continuation request.
    Info string
}

ContinuationReq is a continuation request response.

func (*ContinuationReq) WriteTo Uses

func (r *ContinuationReq) WriteTo(w *Writer) error

type DataResp Uses

type DataResp 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{}
}

DataResp is an IMAP response containing data.

func NewUntaggedResp Uses

func NewUntaggedResp(fields []interface{}) *DataResp

NewUntaggedResp creates a new untagged response.

func (*DataResp) WriteTo Uses

func (r *DataResp) WriteTo(w *Writer) error

type Date Uses

type Date time.Time

time.Time with a specific layout.

type DateTime Uses

type DateTime time.Time

time.Time with a specific layout.

type Envelope Uses

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.

func (*Envelope) Format Uses

func (e *Envelope) Format() (fields []interface{})

Format an envelope to fields.

func (*Envelope) Parse Uses

func (e *Envelope) Parse(fields []interface{}) error

Parse an envelope from fields.

type ErrBadSeqSet Uses

type ErrBadSeqSet string

ErrBadSeqSet is used to report problems with the format of a sequence set value.

func (ErrBadSeqSet) Error Uses

func (err ErrBadSeqSet) Error() string

type ErrStatusResp Uses

type ErrStatusResp struct {
    // Response to send instead of default.
    Resp *StatusResp
}

ErrStatusResp can be returned by a server.Handler to replace the default status response. The response tag must be empty.

To suppress default response, Resp should be set to nil.

func (*ErrStatusResp) Error Uses

func (err *ErrStatusResp) Error() string

type FetchItem Uses

type FetchItem string

A FetchItem is a message data item that can be fetched.

const (
    // Macros
    FetchAll  FetchItem = "ALL"
    FetchFast FetchItem = "FAST"
    FetchFull FetchItem = "FULL"

    // Items
    FetchBody          FetchItem = "BODY"
    FetchBodyStructure FetchItem = "BODYSTRUCTURE"
    FetchEnvelope      FetchItem = "ENVELOPE"
    FetchFlags         FetchItem = "FLAGS"
    FetchInternalDate  FetchItem = "INTERNALDATE"
    FetchRFC822        FetchItem = "RFC822"
    FetchRFC822Header  FetchItem = "RFC822.HEADER"
    FetchRFC822Size    FetchItem = "RFC822.SIZE"
    FetchRFC822Text    FetchItem = "RFC822.TEXT"
    FetchUid           FetchItem = "UID"
)

List of items that can be fetched.

func (FetchItem) Expand Uses

func (item FetchItem) Expand() []FetchItem

Expand expands the item if it's a macro.

type FlagsOp Uses

type FlagsOp string

FlagsOp is an operation that will be applied on message flags.

func ParseFlagsOp Uses

func ParseFlagsOp(item StoreItem) (op FlagsOp, silent bool, err error)

ParseFlagsOp parses a flags operation from StoreItem.

type Literal Uses

type Literal interface {
    io.Reader

    // Len returns the number of bytes of the literal.
    Len() int
}

A literal, as defined in RFC 3501 section 4.3.

type LiteralLengthErr Uses

type LiteralLengthErr struct {
    Actual   int
    Expected int
}

LiteralLengthErr is returned when the Len() of the Literal object does not match the actual length of the byte stream.

func (LiteralLengthErr) Error Uses

func (e LiteralLengthErr) Error() string

type LockedWriter Uses

type LockedWriter struct {
    // contains filtered or unexported fields
}

func (*LockedWriter) Write Uses

func (w *LockedWriter) Write(b []byte) (int, error)

type Logger Uses

type Logger interface {
    Printf(format string, v ...interface{})
    Println(v ...interface{})
}

Logger is the behaviour used by server/client to report errors for accepting connections and unexpected behavior from handlers.

type MailboxInfo Uses

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 Uses

func (info *MailboxInfo) Format() []interface{}

Format mailbox info to fields.

func (*MailboxInfo) Match Uses

func (info *MailboxInfo) Match(reference, pattern string) bool

Match checks if a reference and a pattern matches this mailbox name, as defined in RFC 3501 section 6.3.8.

func (*MailboxInfo) Parse Uses

func (info *MailboxInfo) Parse(fields []interface{}) error

Parse mailbox info from fields.

type MailboxStatus Uses

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. This map's values
    // should not be used directly, they must only be used by libraries
    // implementing extensions of the IMAP protocol.
    Items map[StatusItem]interface{}

    // The Items map may be accessed in different goroutines. Protect
    // concurrent writes.
    ItemsLocker sync.Mutex

    // The mailbox flags.
    Flags []string
    // The mailbox permanent flags.
    PermanentFlags []string
    // The sequence number of the first unseen message in the mailbox.
    UnseenSeqNum uint32

    // 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.

func NewMailboxStatus Uses

func NewMailboxStatus(name string, items []StatusItem) *MailboxStatus

Create a new mailbox status that will contain the specified items.

func (*MailboxStatus) Format Uses

func (status *MailboxStatus) Format() []interface{}

func (*MailboxStatus) Parse Uses

func (status *MailboxStatus) Parse(fields []interface{}) error

type Message Uses

type Message struct {
    // The message sequence number. It must be greater than or equal to 1.
    SeqNum uint32
    // The mailbox items that are currently filled in. This map's values
    // should not be used directly, they must only be used by libraries
    // implementing extensions of the IMAP protocol.
    Items map[FetchItem]interface{}

    // 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 the server.
    InternalDate time.Time
    // The message size.
    Size uint32
    // The message unique identifier. It must be greater than or equal to 1.
    Uid uint32
    // The message body sections.
    Body map[*BodySectionName]Literal
    // contains filtered or unexported fields
}

A message.

func NewMessage Uses

func NewMessage(seqNum uint32, items []FetchItem) *Message

Create a new empty message that will contain the specified items.

func (*Message) Format Uses

func (m *Message) Format() []interface{}

func (*Message) GetBody Uses

func (m *Message) GetBody(section *BodySectionName) Literal

GetBody gets the body section with the specified name. Returns nil if it's not found.

func (*Message) Parse Uses

func (m *Message) Parse(fields []interface{}) error

Parse a message from fields.

type Parser Uses

type Parser interface {
    Parse(fields []interface{}) error
}

type PartSpecifier Uses

type PartSpecifier string

A PartSpecifier specifies which parts of the MIME entity should be returned.

type RawString Uses

type RawString string

A raw string.

type Reader Uses

type Reader struct {
    MaxLiteralSize uint32 // The maximum literal size.
    // contains filtered or unexported fields
}

An IMAP reader.

func NewReader Uses

func NewReader(r reader) *Reader

func NewServerReader Uses

func NewServerReader(r reader, continues chan<- bool) *Reader

func (*Reader) ReadAtom Uses

func (r *Reader) ReadAtom() (interface{}, error)

func (*Reader) ReadCrlf Uses

func (r *Reader) ReadCrlf() (err error)

func (*Reader) ReadFields Uses

func (r *Reader) ReadFields() (fields []interface{}, err error)

func (*Reader) ReadInfo Uses

func (r *Reader) ReadInfo() (info string, err error)

func (*Reader) ReadLine Uses

func (r *Reader) ReadLine() (fields []interface{}, err error)

func (*Reader) ReadList Uses

func (r *Reader) ReadList() (fields []interface{}, err error)

func (*Reader) ReadLiteral Uses

func (r *Reader) ReadLiteral() (Literal, error)

func (*Reader) ReadQuotedString Uses

func (r *Reader) ReadQuotedString() (string, error)

func (*Reader) ReadRespCode Uses

func (r *Reader) ReadRespCode() (code StatusRespCode, fields []interface{}, err error)

func (*Reader) ReadSp Uses

func (r *Reader) ReadSp() error

type Resp Uses

type Resp interface {
    // contains filtered or unexported methods
}

Resp is an IMAP response. It is either a *DataResp, a *ContinuationReq or a *StatusResp.

func ReadResp Uses

func ReadResp(r *Reader) (Resp, error)

ReadResp reads a single response from a Reader.

type SearchCriteria Uses

type SearchCriteria struct {
    SeqNum *SeqSet // Sequence number is in sequence set
    Uid    *SeqSet // UID is in sequence set

    // Time and timezone are ignored
    Since      time.Time // Internal date is since this date
    Before     time.Time // Internal date is before this date
    SentSince  time.Time // Date header field is since this date
    SentBefore time.Time // Date header field is before this date

    Header textproto.MIMEHeader // Each header field value is present
    Body   []string             // Each string is in the body
    Text   []string             // Each string is in the text (header + body)

    WithFlags    []string // Each flag is present
    WithoutFlags []string // Each flag is not present

    Larger  uint32 // Size is larger than this number
    Smaller uint32 // Size is smaller than this number

    Not []*SearchCriteria    // Each criteria doesn't match
    Or  [][2]*SearchCriteria // Each criteria pair has at least one match of two
}

SearchCriteria is a search criteria. A message matches the criteria if and only if it matches each one of its fields.

func NewSearchCriteria Uses

func NewSearchCriteria() *SearchCriteria

NewSearchCriteria creates a new search criteria.

func (*SearchCriteria) Format Uses

func (c *SearchCriteria) Format() []interface{}

Format formats search criteria to fields. UTF-8 is used.

func (*SearchCriteria) ParseWithCharset Uses

func (c *SearchCriteria) ParseWithCharset(fields []interface{}, charsetReader func(io.Reader) io.Reader) error

ParseWithCharset parses a search criteria from the provided fields. charsetReader is an optional function that converts from the fields charset to UTF-8.

type Seq Uses

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 Uses

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 Uses

func (s Seq) Less(q uint32) bool

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

func (Seq) Merge Uses

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 Uses

func (s Seq) String() string

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

type SeqSet Uses

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 ParseSeqSet Uses

func ParseSeqSet(set string) (s *SeqSet, err error)

ParseSeqSet returns a new SeqSet instance after parsing the set string.

func (*SeqSet) Add Uses

func (s *SeqSet) Add(set string) error

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 Uses

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

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

func (*SeqSet) AddRange Uses

func (s *SeqSet) AddRange(Start, Stop uint32)

AddRange inserts a new sequence range into the set.

func (*SeqSet) AddSet Uses

func (s *SeqSet) AddSet(t *SeqSet)

AddSet inserts all values from t into s.

func (*SeqSet) Clear Uses

func (s *SeqSet) Clear()

Clear removes all values from the set.

func (SeqSet) Contains Uses

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 Uses

func (s SeqSet) Dynamic() bool

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

func (SeqSet) Empty Uses

func (s SeqSet) Empty() bool

Empty returns true if the sequence set does not contain any values.

func (SeqSet) String Uses

func (s SeqSet) String() string

String returns a sorted representation of all contained sequence values.

type StatusItem Uses

type StatusItem string

A StatusItem is a mailbox status data item that can be retrieved with a STATUS command. See RFC 3501 section 6.3.10.

const (
    StatusMessages    StatusItem = "MESSAGES"
    StatusRecent      StatusItem = "RECENT"
    StatusUidNext     StatusItem = "UIDNEXT"
    StatusUidValidity StatusItem = "UIDVALIDITY"
    StatusUnseen      StatusItem = "UNSEEN"
)

type StatusResp Uses

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 StatusRespCode
    // 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 Uses

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 Uses

func (r *StatusResp) WriteTo(w *Writer) error

type StatusRespCode Uses

type StatusRespCode string
const (
    CodeAlert          StatusRespCode = "ALERT"
    CodeBadCharset     StatusRespCode = "BADCHARSET"
    CodeCapability     StatusRespCode = "CAPABILITY"
    CodeParse          StatusRespCode = "PARSE"
    CodePermanentFlags StatusRespCode = "PERMANENTFLAGS"
    CodeReadOnly       StatusRespCode = "READ-ONLY"
    CodeReadWrite      StatusRespCode = "READ-WRITE"
    CodeTryCreate      StatusRespCode = "TRYCREATE"
    CodeUidNext        StatusRespCode = "UIDNEXT"
    CodeUidValidity    StatusRespCode = "UIDVALIDITY"
    CodeUnseen         StatusRespCode = "UNSEEN"
)

Status response codes defined in RFC 3501 section 7.1.

type StatusRespType Uses

type StatusRespType string

A status response type.

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.
    StatusRespOk 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.
    StatusRespNo StatusRespType = "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.
    StatusRespBad StatusRespType = "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.
    StatusRespPreauth StatusRespType = "PREAUTH"

    // The BYE response is always untagged, and indicates that the server
    // is about to close the connection.
    StatusRespBye StatusRespType = "BYE"
)

Status response types defined in RFC 3501 section 7.1.

type StoreItem Uses

type StoreItem string

A StoreItem is a message data item that can be updated.

func FormatFlagsOp Uses

func FormatFlagsOp(op FlagsOp, silent bool) StoreItem

FormatFlagsOp returns the StoreItem that executes the flags operation op.

type StringReader Uses

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.

type Waiter Uses

type Waiter struct {
    // contains filtered or unexported fields
}

func NewWaiter Uses

func NewWaiter() *Waiter

func (*Waiter) Close Uses

func (w *Waiter) Close()

func (*Waiter) Wait Uses

func (w *Waiter) Wait()

func (*Waiter) WaitReady Uses

func (w *Waiter) WaitReady()

type Writer Uses

type Writer struct {
    io.Writer

    AllowAsyncLiterals bool
    // contains filtered or unexported fields
}

An IMAP writer.

func NewClientWriter Uses

func NewClientWriter(w io.Writer, continues <-chan bool) *Writer

func NewWriter Uses

func NewWriter(w io.Writer) *Writer

func (*Writer) Flush Uses

func (w *Writer) Flush() error

type WriterTo Uses

type WriterTo interface {
    WriteTo(w *Writer) error
}

Directories

PathSynopsis
backendPackage backend defines an IMAP server backend interface.
backend/backendutilPackage backendutil provides utility functions to implement IMAP backends.
backend/memoryA memory backend.
clientPackage client provides an IMAP client.
commandsPackage commands implements IMAP commands defined in RFC 3501.
internal
responsesIMAP responses defined in RFC 3501.
serverPackage server provides an IMAP server.
utf7Modified UTF-7 encoding defined in RFC 3501 section 5.1.3

Package imap imports 17 packages (graph) and is imported by 159 packages. Updated 2020-05-13. Refresh now. Tools for package owners.