imapserver package - github.com/emersion/go-imap/v2/imapserver - Go Packages (original) (raw)

Package imapserver implements an IMAP server.

ErrAuthFailed is returned by Session.Login on authentication failure.

func ExtractBinarySection(r io.Reader, item *imap.FetchItemBinarySection) []byte

func ExtractBinarySectionSize(r io.Reader, item *imap.FetchItemBinarySectionSize) uint32

func ExtractBodySection

func ExtractBodySection(r io.Reader, item *imap.FetchItemBodySection) []byte

ExtractBodySection extracts a section of a message body.

It can be used by server backends to implement Session.Fetch.

func ExtractBodyStructure

func ExtractBodyStructure(r io.Reader) imap.BodyStructure

ExtractBodyStructure extracts the structure of a message body.

It can be used by server backends to implement Session.Fetch.

ExtractEnvelope returns a message envelope from its header.

It can be used by server backends to implement Session.Fetch.

MatchList checks whether a reference and a pattern matches a mailbox.

A Conn represents an IMAP connection to the server.

Bye terminates the IMAP connection.

func (c *Conn) EnabledCaps() imap.CapSet

NetConn returns the underlying connection that is wrapped by the IMAP connection.

Writing to or reading from this connection directly will corrupt the IMAP session.

type ExpungeWriter struct {

}

ExpungeWriter writes EXPUNGE updates.

WriteExpunge notifies the client that the message with the provided sequence number has been deleted.

type FetchResponseWriter struct {

}

FetchResponseWriter writes a single FETCH response for a message.

Close closes the FETCH message writer.

WriteBinarySection writes a binary section.

The returned io.WriteCloser must be closed before writing any more message data items.

func (w *FetchResponseWriter) WriteBinarySectionSize(section *imap.FetchItemBinarySectionSize, size uint32)

WriteBinarySectionSize writes a binary section size.

func (*FetchResponseWriter) WriteBodySection

WriteBodySection writes a body section.

The returned io.WriteCloser must be closed before writing any more message data items.

func (*FetchResponseWriter) WriteBodyStructure

func (w *FetchResponseWriter) WriteBodyStructure(bs imap.BodyStructure)

WriteBodyStructure writes the message's body structure (either BODYSTRUCTURE or BODY).

func (w *FetchResponseWriter) WriteEnvelope(envelope *imap.Envelope)

WriteEnvelope writes the message's envelope.

func (w *FetchResponseWriter) WriteFlags(flags []imap.Flag)

WriteFlags writes the message's flags.

WriteInternalDate writes the message's internal date.

func (w *FetchResponseWriter) WriteRFC822Size(size int64)

WriteRFC822Size writes the message's full size.

func (w *FetchResponseWriter) WriteUID(uid imap.UID)

WriteUID writes the message's UID.

type FetchWriter struct {

}

FetchWriter writes FETCH responses.

CreateMessage writes a FETCH response for a message.

FetchResponseWriter.Close must be called.

type GreetingData struct { PreAuth bool }

GreetingData is the data associated with an IMAP greeting.

type ListWriter struct {

}

ListWriter writes LIST responses.

func (w *ListWriter) WriteList(data *imap.ListData) error

WriteList writes a single LIST response for a mailbox.

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

Logger is a facility to log error messages.

type MailboxTracker struct {

}

MailboxTracker tracks the state of a mailbox.

A mailbox can have multiple sessions listening for updates. Each session has its own view of the mailbox, because IMAP clients asynchronously receive mailbox updates.

func NewMailboxTracker(numMessages uint32) *MailboxTracker

NewMailboxTracker creates a new mailbox tracker.

func (t *MailboxTracker) NewSession() *SessionTracker

NewSession creates a new session tracker for the mailbox.

The caller must call SessionTracker.Close once they are done with the session.

func (t *MailboxTracker) QueueExpunge(seqNum uint32)

QueueExpunge queues a new EXPUNGE update.

func (t *MailboxTracker) QueueMailboxFlags(flags []imap.Flag)

QueueMailboxFlags queues a new FLAGS update.

func (t *MailboxTracker) QueueMessageFlags(seqNum uint32, uid imap.UID, flags []imap.Flag, source *SessionTracker)

QueueMessageFlags queues a new FETCH FLAGS update.

If source is not nil, the update won't be dispatched to it.

func (t *MailboxTracker) QueueNumMessages(n uint32)

QueueNumMessages queues a new EXISTS update.

type MoveWriter struct {

}

MoveWriter writes responses for the MOVE command.

Servers must first call WriteCopyData once, then call WriteExpunge any number of times.

func (w *MoveWriter) WriteCopyData(data *imap.CopyData) error

WriteCopyData writes the untagged COPYUID response for a MOVE command.

WriteExpunge writes an EXPUNGE response for a MOVE command.

NumKind describes how a number should be interpreted: either as a sequence number, either as a UID.

String implements fmt.Stringer.

Options contains server options.

The only required field is NewSession.

Server is an IMAP server.

func New(options *Options) *Server

New creates a new server.

Close immediately closes all active listeners and connections.

Close returns any error returned from closing the server's underlying listeners.

Once Close has been called on a server, it may not be reused; future calls to methods such as Serve will return an error.

func (*Server) ListenAndServe

ListenAndServe listens on the TCP network address addr and then calls Serve.

If addr is empty, ":143" is used.

func (*Server) ListenAndServeTLS

ListenAndServeTLS listens on the TCP network address addr and then calls Serve to handle incoming TLS connections.

The TLS configuration set in Options.TLSConfig is used. If addr is empty, ":993" is used.

Serve accepts incoming connections on the listener ln.

type Session interface { Close() error

Login(username, password [string](/builtin#string)) [error](/builtin#error)


Select(mailbox [string](/builtin#string), options *imap.SelectOptions) (*imap.SelectData, [error](/builtin#error))
Create(mailbox [string](/builtin#string), options *imap.CreateOptions) [error](/builtin#error)
Delete(mailbox [string](/builtin#string)) [error](/builtin#error)
Rename(mailbox, newName [string](/builtin#string), options *imap.RenameOptions) [error](/builtin#error)
Subscribe(mailbox [string](/builtin#string)) [error](/builtin#error)
Unsubscribe(mailbox [string](/builtin#string)) [error](/builtin#error)
List(w *[ListWriter](#ListWriter), ref [string](/builtin#string), patterns [][string](/builtin#string), options *imap.ListOptions) [error](/builtin#error)
Status(mailbox [string](/builtin#string), options *imap.StatusOptions) (*imap.StatusData, [error](/builtin#error))
Append(mailbox [string](/builtin#string), r imap.LiteralReader, options *imap.AppendOptions) (*imap.AppendData, [error](/builtin#error))
Poll(w *[UpdateWriter](#UpdateWriter), allowExpunge [bool](/builtin#bool)) [error](/builtin#error)
Idle(w *[UpdateWriter](#UpdateWriter), stop <-chan struct{}) [error](/builtin#error)


Unselect() [error](/builtin#error)
Expunge(w *[ExpungeWriter](#ExpungeWriter), uids *imap.UIDSet) [error](/builtin#error)
Search(kind [NumKind](#NumKind), criteria *imap.SearchCriteria, options *imap.SearchOptions) (*imap.SearchData, [error](/builtin#error))
Fetch(w *[FetchWriter](#FetchWriter), numSet imap.NumSet, options *imap.FetchOptions) [error](/builtin#error)
Store(w *[FetchWriter](#FetchWriter), numSet imap.NumSet, flags *imap.StoreFlags, options *imap.StoreOptions) [error](/builtin#error)
Copy(numSet imap.NumSet, dest [string](/builtin#string)) (*imap.CopyData, [error](/builtin#error))

}

Session is an IMAP session.

type SessionIMAP4rev2 interface { Session SessionNamespace SessionMove }

SessionIMAP4rev2 is an IMAP session which supports IMAP4rev2.

type SessionMove interface { Session

Move(w *[MoveWriter](#MoveWriter), numSet imap.NumSet, dest [string](/builtin#string)) [error](/builtin#error)

}

SessionMove is an IMAP session which supports MOVE.

type SessionNamespace interface { Session

Namespace() (*imap.NamespaceData, [error](/builtin#error))

}

SessionNamespace is an IMAP session which supports NAMESPACE.

type SessionSASL interface { Session AuthenticateMechanisms() []string Authenticate(mech string) (sasl.Server, error) }

SessionSASL is an IMAP session which supports its own set of SASL authentication mechanisms.

type SessionTracker struct {

}

SessionTracker tracks the state of a mailbox for an IMAP client.

func (t *SessionTracker) Close()

Close unregisters the session.

DecodeSeqNum converts a message sequence number from the client view to the server view.

Zero is returned if the message doesn't exist from the server point-of-view.

EncodeSeqNum converts a message sequence number from the server view to the client view.

Zero is returned if the message doesn't exist from the client point-of-view.

func (t *SessionTracker) Idle(w *UpdateWriter, stop <-chan struct{}) error

Idle continuously writes mailbox updates.

When the stop channel is closed, it returns.

Idle cannot be invoked concurrently from two separate goroutines.

Poll dequeues pending mailbox updates for this session.

type SessionUnauthenticate interface { Session

Unauthenticate() [error](/builtin#error)

}

SessionUnauthenticate is an IMAP session which supports UNAUTHENTICATE.

type UpdateWriter struct {

}

UpdateWriter writes status updates.

WriteExpunge writes an EXPUNGE response.

func (w *UpdateWriter) WriteMailboxFlags(flags []imap.Flag) error

WriteMailboxFlags writes a FLAGS response.

func (w *UpdateWriter) WriteMessageFlags(seqNum uint32, uid imap.UID, flags []imap.Flag) error

WriteMessageFlags writes a FETCH response with FLAGS.

WriteNumMessages writes an EXISTS response.

WriteNumRecent writes an RECENT response (not used in IMAP4rev2, will be ignored).