Documentation

Overview

    Package server provides an IMAP server.

    Index

    Constants

    View Source
    const MinAutoLogout = 30 * time.Minute

      The minimum autologout duration defined in RFC 3501 section 5.4.

      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.

              Deprecated: Use imap.ErrStatusResp{nil} instead

              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.

                Deprecated: Use imap.ErrStatusResp{res} instead.

                To disable the default status response, use imap.ErrStatusResp{nil} 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
                
                	// Server returns this connection's server.
                	Server() *Server
                	// Context returns this connection's context.
                	Context() *Context
                	// Capabilities returns a list of capabilities enabled for this connection.
                	Capabilities() []string
                	// WriteResp writes 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 upgrades a connection, e.g. wrap an unencrypted connection with an
                	// encrypted tunnel.
                	Upgrade(upgrader imap.ConnUpgrader) error
                	// Close closes this connection.
                	Close() error
                	WaitReady()
                
                	Info() *imap.ConnInfo
                	// contains filtered or unexported methods
                }

                  Conn is a connection to a client.

                  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
                    	// Responses to send to the client.
                    	Responses chan<- imap.WriterTo
                    	// Closed when the client is logged out.
                    	LoggedOut <-chan struct{}
                    }

                      Context stores a connection's metadata.

                      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.
                      	Capabilities(c Conn) []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 imap.ErrStatusResp.
                        	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 backend.Update
                              	// Automatically logout clients after a duration. To do not logout users
                              	// automatically, set this to zero. The duration MUST be at least
                              	// MinAutoLogout (as stated in RFC 3501 section 5.4).
                              	AutoLogout time.Duration
                              	// Allow authentication over unencrypted connections.
                              	AllowInsecureAuth bool
                              	// An io.Writer to which all network activity will be mirrored.
                              	Debug io.Writer
                              	// 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 imap.Logger
                              	// The maximum literal size, in bytes. Literals exceeding this size will be
                              	// rejected. A value of zero disables the limit (this is the default).
                              	MaxLiteralSize uint32
                              	// 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) Close

                                  func (s *Server) Close() error

                                    Stops listening and closes all current connections.

                                    func (*Server) Command

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

                                      Command gets 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. Wiki entry: https://github.com/emersion/go-imap/wiki/Using-extensions

                                        func (*Server) EnableAuth

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

                                          Enable an authentication mechanism on this server. Wiki entry: https://github.com/emersion/go-imap/wiki/Using-authentication-mechanisms

                                          func (*Server) ForEachConn

                                          func (s *Server) ForEachConn(f func(Conn))

                                            ForEachConn iterates through all opened connections.

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