imapwire

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package imapwire implements the IMAP wire protocol.

The IMAP wire protocol is defined in RFC 9051 section 4.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAtomChar

func IsAtomChar(ch byte) bool

IsAtomChar returns true if ch is an ATOM-CHAR.

func ParseSeqSet

func ParseSeqSet(s string) (imap.SeqSet, error)

Types

type ConnSide

type ConnSide int

ConnSide describes the side of a connection: client or server.

const (
	ConnSideClient ConnSide = 1 + iota
	ConnSideServer
)

type ContinuationRequest

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

ContinuationRequest is a continuation request.

The sender must call either Done or Cancel. The receiver must call Wait.

func NewContinuationRequest

func NewContinuationRequest() *ContinuationRequest

func (*ContinuationRequest) Cancel

func (cont *ContinuationRequest) Cancel(err error)

func (*ContinuationRequest) Done

func (cont *ContinuationRequest) Done(text string)

func (*ContinuationRequest) Wait

func (cont *ContinuationRequest) Wait() (string, error)

type Decoder

type Decoder struct {
	// CheckBufferedLiteralFunc is called when a literal is about to be decoded
	// and needs to be fully buffered in memory.
	CheckBufferedLiteralFunc func(size int64, nonSync bool) error
	// contains filtered or unexported fields
}

A Decoder reads IMAP data.

There are multiple families of methods:

  • Methods directly named after IMAP grammar elements attempt to decode said element, and return false if it's another element.
  • "Expect" methods do the same, but set the decoder error (see Err) on failure.

func NewDecoder

func NewDecoder(r *bufio.Reader, side ConnSide) *Decoder

NewDecoder creates a new decoder.

func (*Decoder) Atom

func (dec *Decoder) Atom(ptr *string) bool

func (*Decoder) CRLF

func (dec *Decoder) CRLF() bool

func (*Decoder) DiscardLine

func (dec *Decoder) DiscardLine()

func (*Decoder) DiscardUntilByte

func (dec *Decoder) DiscardUntilByte(untilCh byte)

func (*Decoder) DiscardValue

func (dec *Decoder) DiscardValue() bool

func (*Decoder) EOF

func (dec *Decoder) EOF() bool

EOF returns true if end-of-file is reached.

func (*Decoder) Err

func (dec *Decoder) Err() error

Err returns the decoder error, if any.

func (*Decoder) Expect

func (dec *Decoder) Expect(ok bool, name string) bool

Expect sets the decoder error if ok is false.

func (*Decoder) ExpectAString

func (dec *Decoder) ExpectAString(ptr *string) bool

func (*Decoder) ExpectAtom

func (dec *Decoder) ExpectAtom(ptr *string) bool

func (*Decoder) ExpectBodyFldOctets

func (dec *Decoder) ExpectBodyFldOctets(ptr *uint32) bool

func (*Decoder) ExpectCRLF

func (dec *Decoder) ExpectCRLF() bool

func (*Decoder) ExpectList

func (dec *Decoder) ExpectList(f func() error) error

func (*Decoder) ExpectLiteralReader

func (dec *Decoder) ExpectLiteralReader() (lit *LiteralReader, nonSync bool, err error)

func (*Decoder) ExpectMailbox

func (dec *Decoder) ExpectMailbox(ptr *string) bool

func (*Decoder) ExpectModSeq

func (dec *Decoder) ExpectModSeq(ptr *uint64) bool

func (*Decoder) ExpectNIL

func (dec *Decoder) ExpectNIL() bool

func (*Decoder) ExpectNList

func (dec *Decoder) ExpectNList(f func() error) error

func (*Decoder) ExpectNString

func (dec *Decoder) ExpectNString(ptr *string) bool

func (*Decoder) ExpectNStringReader

func (dec *Decoder) ExpectNStringReader() (lit *LiteralReader, nonSync, ok bool)

func (*Decoder) ExpectNumSet

func (dec *Decoder) ExpectNumSet(kind NumKind, ptr *imap.NumSet) bool

func (*Decoder) ExpectNumber

func (dec *Decoder) ExpectNumber(ptr *uint32) bool

func (*Decoder) ExpectNumber64

func (dec *Decoder) ExpectNumber64(ptr *int64) bool

func (*Decoder) ExpectSP

func (dec *Decoder) ExpectSP() bool

func (*Decoder) ExpectSpecial

func (dec *Decoder) ExpectSpecial(b byte) bool

func (*Decoder) ExpectString

func (dec *Decoder) ExpectString(ptr *string) bool

func (*Decoder) ExpectText

func (dec *Decoder) ExpectText(ptr *string) bool

func (*Decoder) ExpectUID

func (dec *Decoder) ExpectUID(ptr *imap.UID) bool

func (*Decoder) ExpectUIDSet

func (dec *Decoder) ExpectUIDSet(ptr *imap.UIDSet) bool

func (*Decoder) Func

func (dec *Decoder) Func(ptr *string, valid func(ch byte) bool) bool

func (*Decoder) List

func (dec *Decoder) List(f func() error) (isList bool, err error)

func (*Decoder) Literal

func (dec *Decoder) Literal(ptr *string) bool

func (*Decoder) LiteralReader

func (dec *Decoder) LiteralReader() (lit *LiteralReader, nonSync, ok bool)

func (*Decoder) ModSeq

func (dec *Decoder) ModSeq(ptr *uint64) bool

func (*Decoder) Number

func (dec *Decoder) Number(ptr *uint32) bool

func (*Decoder) Number64

func (dec *Decoder) Number64(ptr *int64) bool

func (*Decoder) Quoted

func (dec *Decoder) Quoted(ptr *string) bool

func (*Decoder) SP

func (dec *Decoder) SP() bool

func (*Decoder) Special

func (dec *Decoder) Special(b byte) bool

func (*Decoder) String

func (dec *Decoder) String(ptr *string) bool

func (*Decoder) Text

func (dec *Decoder) Text(ptr *string) bool

type DecoderExpectError

type DecoderExpectError struct {
	Message string
}

DecoderExpectError is an error due to the Decoder.Expect family of methods.

func (*DecoderExpectError) Error

func (err *DecoderExpectError) Error() string

type Encoder

type Encoder struct {
	// QuotedUTF8 allows non-ASCII strings to be encoded as quoted strings.
	// This requires IMAP4rev2 to be available, or UTF8=ACCEPT to be enabled.
	QuotedUTF8 bool
	// LiteralMinus enables non-synchronizing literals for short payloads.
	// This requires IMAP4rev2 or LITERAL-. This is only meaningful for
	// clients.
	LiteralMinus bool
	// LiteralPlus enables non-synchronizing literals for all payloads. This
	// requires LITERAL+. This is only meaningful for clients.
	LiteralPlus bool
	// NewContinuationRequest creates a new continuation request. This is only
	// meaningful for clients.
	NewContinuationRequest func() *ContinuationRequest
	// contains filtered or unexported fields
}

An Encoder writes IMAP data.

Most methods don't return an error, instead they defer error handling until CRLF is called. These methods return the Encoder so that calls can be chained.

func NewEncoder

func NewEncoder(w *bufio.Writer, side ConnSide) *Encoder

NewEncoder creates a new encoder.

func (*Encoder) Atom

func (enc *Encoder) Atom(s string) *Encoder

func (*Encoder) BeginList

func (enc *Encoder) BeginList() *ListEncoder

func (*Encoder) CRLF

func (enc *Encoder) CRLF() error

CRLF writes a "\r\n" sequence and flushes the buffered writer.

func (*Encoder) Flag

func (enc *Encoder) Flag(flag imap.Flag) *Encoder

func (*Encoder) List

func (enc *Encoder) List(n int, f func(i int)) *Encoder

List writes a parenthesized list.

func (*Encoder) Literal

func (enc *Encoder) Literal(size int64, sync *ContinuationRequest) io.WriteCloser

Literal writes a literal.

The caller must write exactly size bytes to the returned writer.

If sync is non-nil, the literal is synchronizing: the encoder will wait for nil to be sent to the channel before writing the literal data. If an error is sent to the channel, the literal will be cancelled.

func (*Encoder) Mailbox

func (enc *Encoder) Mailbox(name string) *Encoder

func (*Encoder) MailboxAttr

func (enc *Encoder) MailboxAttr(attr imap.MailboxAttr) *Encoder

func (*Encoder) ModSeq

func (enc *Encoder) ModSeq(v uint64) *Encoder

func (*Encoder) NIL

func (enc *Encoder) NIL() *Encoder

func (*Encoder) NumSet

func (enc *Encoder) NumSet(numSet imap.NumSet) *Encoder

func (*Encoder) Number

func (enc *Encoder) Number(v uint32) *Encoder

func (*Encoder) Number64

func (enc *Encoder) Number64(v int64) *Encoder

func (*Encoder) Quoted

func (enc *Encoder) Quoted(s string) *Encoder

func (*Encoder) SP

func (enc *Encoder) SP() *Encoder

func (*Encoder) Special

func (enc *Encoder) Special(ch byte) *Encoder

func (*Encoder) String

func (enc *Encoder) String(s string) *Encoder

func (*Encoder) Text

func (enc *Encoder) Text(s string) *Encoder

func (*Encoder) UID

func (enc *Encoder) UID(uid imap.UID) *Encoder

type ListEncoder

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

func (*ListEncoder) End

func (le *ListEncoder) End()

func (*ListEncoder) Item

func (le *ListEncoder) Item() *Encoder

type LiteralReader

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

func (*LiteralReader) Read

func (lit *LiteralReader) Read(b []byte) (int, error)

func (*LiteralReader) Size

func (lit *LiteralReader) Size() int64

type NumKind

type NumKind int
const (
	NumKindSeq NumKind = iota + 1
	NumKindUID
)

func NumSetKind

func NumSetKind(numSet imap.NumSet) NumKind

Jump to

Keyboard shortcuts

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