imap

package module
v0.0.0-...-643b3d3 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2015 License: MIT Imports: 9 Imported by: 0

README

go-imap

Build Status

go-imap is a server-side IMAP parser.

IMAP's wire protocol is gnarly. go-imap does the parsing for you, so you can focus on the server logic itself. (It doesn't implement the IMAP commands itself, that's up to you.)

Caveats

go-imap is reasonably complete, and I am using it actively, but it is not production-ready yet. In particular:

  • The majority of the library lacks test coverage
  • BODYSTRUCTURE marshaling is not implemented
  • Robustness to errors and edge cases varies

Installation

go get github.com/paulrosania/go-imap

Documentation

Full API documentation is available here:

https://godoc.org/github.com/paulrosania/go-imap

Contributing

  1. Fork the project
  2. Make your changes
  3. Run tests (go test)
  4. Send a pull request!

If you’re making a big change, please open an issue first, so we can discuss.

License

MIT

Documentation

Index

Constants

View Source
const (
	FetchAll             bodyFetchMode = ""
	FetchText                          = "TEXT"
	FetchHeader                        = "HEADER"
	FetchHeaderFields                  = "HEADER.FIELDS"
	FetchHeaderFieldsNot               = "HEADER.FIELDS.NOT"
)
View Source
const (
	FlagAnswered Flag = `\Answered`
	FlagFlagged       = `\Flagged`
	FlagDeleted       = `\Trashed`
	FlagSeen          = `\Seen`
	FlagDraft         = `\Draft`
	FlagRecent        = `\Recent`

	KeywordMDNSent       Flag = `$MDNSent`
	KeywordForwarded          = `$Forwarded`
	KeywordSubmitPending      = `$SubmitPending`
	KeywordSubmitted          = `$Submitted`
)
View Source
const (
	FromField Field = "From"
	ToField         = "To"
	CcField         = "Cc"
	BccField        = "Bcc"

	SubjectField = "Subject"
	TextField    = "Text"
	BodyField    = "Body"

	MSNField          = "MSN"
	UIDField          = "UID"
	SizeField         = "Size"
	DateField         = "Date"
	InternalDateField = "InternalDate"
)
View Source
const Star = -1

Sentinel for IMAP '*'

Variables

View Source
var (
	EnvelopeFetchAttribute     = BasicFetchAttribute{"ENVELOPE", MarshalEnvelope}
	FlagsFetchAttribute        = BasicFetchAttribute{"FLAGS", MarshalFlags}
	InternalDateFetchAttribute = BasicFetchAttribute{"INTERNALDATE", MarshalInternalDate}
	RFC822FetchAttribute       = BasicFetchAttribute{"RFC822", MarshalRFC822}
	RFC822HeaderFetchAttribute = BasicFetchAttribute{"RFC822.HEADER", MarshalRFC822Header}
	RFC822SizeFetchAttribute   = BasicFetchAttribute{"RFC822.SIZE", MarshalRFC822Size}
	RFC822TextFetchAttribute   = BasicFetchAttribute{"RFC822.TEXT", MarshalRFC822Text}
	UIDFetchAttribute          = BasicFetchAttribute{"UID", MarshalUID}
)
View Source
var (
	ErrTooLong          = ProtocolError("token too long")
	ErrLineTooShort     = ProtocolError("line too short")
	ErrNegativeAdvance  = ProtocolError("negative advance count")
	ErrAdvanceTooFar    = ProtocolError("advance count beyond input")
	ErrSeqNoOutOfBounds = ProtocolError("sequence number out of bounds")
)

Functions

func MarshalEnvelope

func MarshalEnvelope(m *Message) string

func MarshalFlags

func MarshalFlags(m *Message) string

func MarshalInternalDate

func MarshalInternalDate(m *Message) string

func MarshalRFC822

func MarshalRFC822(m *Message) string

func MarshalRFC822Header

func MarshalRFC822Header(m *Message) string

func MarshalRFC822Size

func MarshalRFC822Size(m *Message) string

func MarshalRFC822Text

func MarshalRFC822Text(m *Message) string

func MarshalUID

func MarshalUID(m *Message) string

Types

type AllTerm

type AllTerm struct{}

func (*AllTerm) Accept

func (t *AllTerm) Accept(v TermVisitor)

type BasicFetchAttribute

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

func (BasicFetchAttribute) Marshal

func (fa BasicFetchAttribute) Marshal(m *Message) string

func (BasicFetchAttribute) Name

func (fa BasicFetchAttribute) Name() string

type BodyFetchAttribute

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

func (BodyFetchAttribute) Marshal

func (fa BodyFetchAttribute) Marshal(msg *Message) string

func (BodyFetchAttribute) Name

func (fa BodyFetchAttribute) Name() string

type BodystructureFetchAttribute

type BodystructureFetchAttribute bool

func (BodystructureFetchAttribute) Marshal

func (includeExtensions BodystructureFetchAttribute) Marshal(msg *Message) string

func (BodystructureFetchAttribute) Name

func (includeExtensions BodystructureFetchAttribute) Name() string

type BooleanTerm

type BooleanTerm struct {
	Op    Op
	Terms []Term
}

func (*BooleanTerm) Accept

func (t *BooleanTerm) Accept(v TermVisitor)

type Conn

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

func NewConn

func NewConn(rwc io.ReadWriteCloser) *Conn

func (*Conn) Bad

func (c *Conn) Bad(r *Request, err error)

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) Continuation

func (c *Conn) Continuation(msg string)

func (*Conn) DiscardLine

func (c *Conn) DiscardLine()

func (*Conn) No

func (c *Conn) No(r *Request, err error)

func (*Conn) Ok

func (c *Conn) Ok(r *Request)

func (*Conn) OkWithCode

func (c *Conn) OkWithCode(r *Request, responseCode string)

func (*Conn) ReadRequest

func (c *Conn) ReadRequest() (*Request, error)

func (*Conn) Splat

func (c *Conn) Splat(msg string)

func (*Conn) Write

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

type DateTerm

type DateTerm struct {
	Op    Op
	Field Field
	Date  time.Time
}

func (*DateTerm) Accept

func (t *DateTerm) Accept(v TermVisitor)

type FetchAttribute

type FetchAttribute interface {
	Name() string
	Marshal(*Message) string
}

type Field

type Field string

type Flag

type Flag string

func (Flag) String

func (f Flag) String() string

type FlagTerm

type FlagTerm struct {
	Flag    Flag
	Present bool
}

func (*FlagTerm) Accept

func (t *FlagTerm) Accept(v TermVisitor)

type IntTerm

type IntTerm struct {
	Op    Op
	Field Field
	Int   int
}

func (*IntTerm) Accept

func (t *IntTerm) Accept(v TermVisitor)

type Message

type Message struct {
	mail.Message

	UID        int
	Flags      []Flag
	ReceivedAt time.Time
}

type Op

type Op int
const (
	OpAnd Op = iota
	OpOr
	OpNot

	OpEquals
	OpLT
	OpGTE

	// Strings
	OpContains

	// Sets
	OpIn
)

type Parser

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

func NewParser

func NewParser(c *Conn) *Parser

func (*Parser) DiscardLine

func (p *Parser) DiscardLine()

func (*Parser) Err

func (p *Parser) Err() error

func (*Parser) Expect

func (p *Parser) Expect(s string)

func (*Parser) Peek

func (p *Parser) Peek() byte

func (*Parser) ReadAstring

func (p *Parser) ReadAstring() string

func (*Parser) ReadAtom

func (p *Parser) ReadAtom() string

func (*Parser) ReadAtomList

func (p *Parser) ReadAtomList() []string

func (*Parser) ReadAtomWithExtra

func (p *Parser) ReadAtomWithExtra(extra map[byte]bool) string

func (*Parser) ReadBodyAttribute

func (p *Parser) ReadBodyAttribute() *BodyFetchAttribute

func (*Parser) ReadDate

func (p *Parser) ReadDate() time.Time

func (*Parser) ReadDateTime

func (p *Parser) ReadDateTime() time.Time

func (*Parser) ReadEOL

func (p *Parser) ReadEOL()

func (*Parser) ReadFetchAttribute

func (p *Parser) ReadFetchAttribute() FetchAttribute

func (*Parser) ReadFetchAttributeList

func (p *Parser) ReadFetchAttributeList() []FetchAttribute

NOTE: It's usually an error for the client to send a zero-item list. This method doesn't treat that as an error, but maybe should.

func (*Parser) ReadFetchAttributes

func (p *Parser) ReadFetchAttributes() []FetchAttribute

func (*Parser) ReadFlagList

func (p *Parser) ReadFlagList() []Flag

func (*Parser) ReadInt

func (p *Parser) ReadInt() int

Private since it doesn't validate the ending delimiter

func (*Parser) ReadList

func (p *Parser) ReadList(tokenReader func() string) []string

NOTE: It's usually an error for the client to send a zero-item list. This method doesn't treat that as an error, but maybe should.

func (*Parser) ReadListEnd

func (p *Parser) ReadListEnd()

func (*Parser) ReadListMailbox

func (p *Parser) ReadListMailbox() string

func (*Parser) ReadListStart

func (p *Parser) ReadListStart()

func (*Parser) ReadLiteral

func (p *Parser) ReadLiteral() string

func (*Parser) ReadLiteralPrefix

func (p *Parser) ReadLiteralPrefix() (size int, sync bool)

func (*Parser) ReadLiteralStream

func (p *Parser) ReadLiteralStream() io.Reader

func (*Parser) ReadQuotedString

func (p *Parser) ReadQuotedString() string

func (*Parser) ReadSearch

func (p *Parser) ReadSearch() (charset string, query Term)

func (*Parser) ReadSearchKey

func (p *Parser) ReadSearchKey() Term

Deviates from RFC3501 somewhat: * BODY and TEXT both perform general text searches * Handling of "ALL" is not super strict

func (*Parser) ReadSequenceSet

func (p *Parser) ReadSequenceSet() *SequenceSet

func (*Parser) ReadSpace

func (p *Parser) ReadSpace()

func (*Parser) ReadString

func (p *Parser) ReadString() string

func (*Parser) ReadStringWithExtra

func (p *Parser) ReadStringWithExtra(extra map[byte]bool) string

func (*Parser) String

func (p *Parser) String() string

func (*Parser) Tail

func (p *Parser) Tail() string

func (*Parser) Valid

func (p *Parser) Valid() bool

type ProtocolError

type ProtocolError string

func InvalidTokenError

func InvalidTokenError(tokenType string, determinant byte, context string) ProtocolError

func ProtocolErrorf

func ProtocolErrorf(format string, a ...interface{}) ProtocolError

func TypeMismatchError

func TypeMismatchError(expected string, context string) ProtocolError

func (ProtocolError) Error

func (e ProtocolError) Error() string

type Reader

type Reader interface {
	io.Reader
}

type Request

type Request struct {
	*Parser
	Tag     string
	Command string
}

type SequenceRange

type SequenceRange [2]int

func (*SequenceRange) Len

func (r *SequenceRange) Len() int

func (*SequenceRange) Max

func (r *SequenceRange) Max() int

func (*SequenceRange) Min

func (r *SequenceRange) Min() int

func (*SequenceRange) String

func (r *SequenceRange) String() string

type SequenceSet

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

func NewSequenceSetWithRange

func NewSequenceSetWithRange(rng SequenceRange) *SequenceSet

func (*SequenceSet) Append

func (s *SequenceSet) Append(rng SequenceRange)

func (*SequenceSet) Foreach

func (s *SequenceSet) Foreach(max int, callback func(int) error) error

func (*SequenceSet) Len

func (s *SequenceSet) Len() int

func (*SequenceSet) Max

func (s *SequenceSet) Max() int

func (*SequenceSet) String

func (s *SequenceSet) String() string

type SetTerm

type SetTerm struct {
	Op    Op
	Field Field
	Set   *SequenceSet
}

func (*SetTerm) Accept

func (t *SetTerm) Accept(v TermVisitor)

type StringTerm

type StringTerm struct {
	Op     Op
	Field  Field
	String string
}

func (*StringTerm) Accept

func (t *StringTerm) Accept(v TermVisitor)

type Term

type Term interface {
	Accept(TermVisitor)
}

type TermVisitor

type TermVisitor interface {
	VisitAllTerm(*AllTerm)
	VisitBooleanTerm(*BooleanTerm)
	VisitDateTerm(*DateTerm)
	VisitFlagTerm(*FlagTerm)
	VisitIntTerm(*IntTerm)
	VisitSetTerm(*SetTerm)
	VisitStringTerm(*StringTerm)
	VisitUnaryTerm(*UnaryTerm)
}

type UnaryTerm

type UnaryTerm struct {
	Op   Op
	Term Term
}

func (*UnaryTerm) Accept

func (t *UnaryTerm) Accept(v TermVisitor)

type Writer

type Writer interface {
	io.Writer

	Splat(msg string)
	Continuation(msg string)
	Ok(r *Request)
	OkWithCode(r *Request, responseCode string)
	No(r *Request, err error)
	Bad(r *Request, err error)
}

Jump to

Keyboard shortcuts

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