server

package
Version: v0.0.0-...-ff2b39c Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2016 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

An IMAP server.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyAuthenticated = errors.New("Already authenticated")
	ErrAuthDisabled         = errors.New("Authentication disabled")
)

imap errors in Not Authenticated state.

View Source
var (
	ErrNoMailboxSelected = errors.New("No mailbox selected")
	ErrMailboxReadOnly   = errors.New("Mailbox opened in read-only mode")
)

imap errors in Selected state.

View Source
var (
	ErrNotAuthenticated = errors.New("Not authenticated")
)

imap errors in Authenticated state.

Functions

func ErrNoStatusResp

func ErrNoStatusResp() error

ErrNoStatusResp can be returned by a Handler to prevent the default status response from being sent.

func ErrStatusResp

func ErrStatusResp(res *imap.StatusResp) error

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

To disable the default status response, use ErrNoStatusResp instead.

Types

type Append

type Append struct {
	commands.Append
}

func (*Append) Handle

func (cmd *Append) Handle(conn Conn) error

type Authenticate

type Authenticate struct {
	commands.Authenticate
}

func (*Authenticate) Handle

func (cmd *Authenticate) Handle(conn Conn) error

type Capability

type Capability struct {
	commands.Capability
}

func (*Capability) Handle

func (cmd *Capability) Handle(conn Conn) error

type Check

type Check struct {
	commands.Check
}

func (*Check) Handle

func (cmd *Check) Handle(conn Conn) error

type Close

type Close struct {
	commands.Close
}

func (*Close) Handle

func (cmd *Close) Handle(conn Conn) error

type Conn

type Conn interface {
	io.Reader

	// Get this connection's server.
	Server() *Server
	// Get this connection's context.
	Context() *Context
	// Get a list of capabilities enabled for this connection.
	Capabilities() []string
	// Write a response to this connection.
	WriteResp(res imap.WriterTo) error
	// IsTLS returns true if TLS is enabled.
	IsTLS() bool
	// TLSState returns the TLS connection state if TLS is enabled, nil otherwise.
	TLSState() *tls.ConnectionState
	// Upgrade a connection, e.g. wrap an unencrypted connection with an encrypted
	// tunnel.
	Upgrade(upgrader imap.ConnUpgrader) error
	// Close this connection.
	Close() error
	// contains filtered or unexported methods
}

A connection.

type ConnExtension

type ConnExtension interface {
	Extension

	// This function will be called when a client connects to the server. It can
	// be used to add new features to the default Conn interface by implementing
	// new methods.
	NewConn(c Conn) Conn
}

An extension that provides additional features to each connection.

type Context

type Context struct {
	// This connection's current state.
	State imap.ConnState
	// If the client is logged in, the user.
	User backend.User
	// If the client has selected a mailbox, the mailbox.
	Mailbox backend.Mailbox
	// True if the currently selected mailbox has been opened in read-only mode.
	MailboxReadOnly bool
}

A connection's context.

type Copy

type Copy struct {
	commands.Copy
}

func (*Copy) Handle

func (cmd *Copy) Handle(conn Conn) error

func (*Copy) UidHandle

func (cmd *Copy) UidHandle(conn Conn) error

type Create

type Create struct {
	commands.Create
}

func (*Create) Handle

func (cmd *Create) Handle(conn Conn) error

type Delete

type Delete struct {
	commands.Delete
}

func (*Delete) Handle

func (cmd *Delete) Handle(conn Conn) error

type Expunge

type Expunge struct {
	commands.Expunge
}

func (*Expunge) Handle

func (cmd *Expunge) Handle(conn Conn) error

type Extension

type Extension interface {
	// Get capabilities provided by this extension for a given connection state.
	Capabilities(state imap.ConnState) []string
	// Get the command handler factory for the provided command name.
	Command(name string) HandlerFactory
}

An IMAP extension.

type Fetch

type Fetch struct {
	commands.Fetch
}

func (*Fetch) Handle

func (cmd *Fetch) Handle(conn Conn) error

func (*Fetch) UidHandle

func (cmd *Fetch) UidHandle(conn Conn) error

type Handler

type Handler interface {
	imap.Parser

	// Handle this command for a given connection.
	//
	// By default, after this function has returned a status response is sent. To
	// prevent this behavior handlers can use ErrStatusResp or ErrNoStatusResp.
	Handle(conn Conn) error
}

A command handler.

type HandlerFactory

type HandlerFactory func() Handler

A function that creates handlers.

type List

type List struct {
	commands.List
}

func (*List) Handle

func (cmd *List) Handle(conn Conn) error

type Login

type Login struct {
	commands.Login
}

func (*Login) Handle

func (cmd *Login) Handle(conn Conn) error

type Logout

type Logout struct {
	commands.Logout
}

func (*Logout) Handle

func (cmd *Logout) Handle(conn Conn) error

type Noop

type Noop struct {
	commands.Noop
}

func (*Noop) Handle

func (cmd *Noop) Handle(conn Conn) error

type Rename

type Rename struct {
	commands.Rename
}

func (*Rename) Handle

func (cmd *Rename) Handle(conn Conn) error

type SaslServerFactory

type SaslServerFactory func(conn Conn) sasl.Server

A function that creates SASL servers.

type Search struct {
	commands.Search
}

func (*Search) Handle

func (cmd *Search) Handle(conn Conn) error

func (*Search) UidHandle

func (cmd *Search) UidHandle(conn Conn) error

type Select

type Select struct {
	commands.Select
}

func (*Select) Handle

func (cmd *Select) Handle(conn Conn) error

type Server

type Server struct {

	// TCP address to listen on.
	Addr string
	// This server's TLS configuration.
	TLSConfig *tls.Config
	// This server's backend.
	Backend backend.Backend
	// Backend updates that will be sent to connected clients.
	Updates <-chan interface{}
	// Allow authentication over unencrypted connections.
	AllowInsecureAuth bool
	// Print all network activity to STDOUT.
	Debug bool
	// ErrorLog specifies an optional logger for errors accepting
	// connections and unexpected behavior from handlers.
	// If nil, logging goes to os.Stderr via the log package's
	// standard logger.
	ErrorLog *log.Logger
	// contains filtered or unexported fields
}

An IMAP server.

func New

func New(bkd backend.Backend) *Server

Create a new IMAP server from an existing listener.

func (*Server) Capabilities

func (s *Server) Capabilities(state imap.ConnState) (caps []string)

Get this server's capabilities for the provided connection state.

func (*Server) Close

func (s *Server) Close() error

Stops listening and closes all current connections.

func (*Server) Command

func (s *Server) Command(name string) HandlerFactory

Get a command handler factory for the provided command name.

func (*Server) Enable

func (s *Server) Enable(extensions ...Extension)

Enable some IMAP extensions on this server.

This function should not be called directly, it must only be used by libraries implementing extensions of the IMAP protocol.

func (*Server) EnableAuth

func (s *Server) EnableAuth(name string, f SaslServerFactory)

Enable an authentication mechanism on this server.

This function should not be called directly, it must only be used by libraries implementing extensions of the IMAP protocol.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe listens on the TCP network address s.Addr and then calls Serve to handle requests on incoming connections.

If s.Addr is blank, ":imap" is used.

func (*Server) ListenAndServeTLS

func (s *Server) ListenAndServeTLS() error

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

If s.Addr is blank, ":imaps" is used.

func (*Server) Serve

func (s *Server) Serve(l net.Listener) error

Serve accepts incoming connections on the Listener l.

type StartTLS

type StartTLS struct {
	commands.StartTLS
}

func (*StartTLS) Handle

func (cmd *StartTLS) Handle(conn Conn) error

func (*StartTLS) Upgrade

func (cmd *StartTLS) Upgrade(conn Conn) error

type Status

type Status struct {
	commands.Status
}

func (*Status) Handle

func (cmd *Status) Handle(conn Conn) error

type Store

type Store struct {
	commands.Store
}

func (*Store) Handle

func (cmd *Store) Handle(conn Conn) error

func (*Store) UidHandle

func (cmd *Store) UidHandle(conn Conn) error

type Subscribe

type Subscribe struct {
	commands.Subscribe
}

func (*Subscribe) Handle

func (cmd *Subscribe) Handle(conn Conn) error

type Uid

type Uid struct {
	commands.Uid
}

func (*Uid) Handle

func (cmd *Uid) Handle(conn Conn) error

type UidHandler

type UidHandler interface {
	Handler

	// Handle this command using UIDs for a given connection.
	UidHandle(conn Conn) error
}

A command handler that supports UIDs.

type Unsubscribe

type Unsubscribe struct {
	commands.Unsubscribe
}

func (*Unsubscribe) Handle

func (cmd *Unsubscribe) Handle(conn Conn) error

type Upgrader

type Upgrader interface {
	// Upgrade the connection. This method should call conn.Upgrade().
	Upgrade(conn Conn) error
}

A connection upgrader. If a Handler is also an Upgrader, the connection will be upgraded after the Handler succeeds.

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL