Documentation ¶
Overview ¶
Package server provides an IMAP server.
Index ¶
- Constants
- Variables
- func ErrNoStatusResp() errordeprecated
- func ErrStatusResp(res *imap.StatusResp) errordeprecated
- type Append
- type Authenticate
- type Capability
- type Check
- type Close
- type Conn
- type ConnExtension
- type Context
- type Copy
- type Create
- type Delete
- type Expunge
- type Extension
- type Fetch
- type Handler
- type HandlerFactory
- type Idle
- type List
- type Login
- type Logout
- type Move
- type Noop
- type Rename
- type SASLServerFactory
- type Search
- type Select
- type Server
- func (s *Server) Close() error
- func (s *Server) Command(name string) HandlerFactory
- func (s *Server) Enable(extensions ...Extension)
- func (s *Server) EnableAuth(name string, f SASLServerFactory)
- func (s *Server) ForEachConn(f func(Conn))
- func (s *Server) ListenAndServe() error
- func (s *Server) ListenAndServeTLS() error
- func (s *Server) Serve(l net.Listener) error
- type StartTLS
- type Status
- type Store
- type Subscribe
- type Uid
- type UidHandler
- type Unselect
- type Unsubscribe
- type Upgrader
Constants ¶
const MinAutoLogout = 30 * time.Minute
The minimum autologout duration defined in RFC 3501 section 5.4.
Variables ¶
var ( ErrAlreadyAuthenticated = errors.New("Already authenticated") ErrAuthDisabled = errors.New("Authentication disabled") )
IMAP errors in Not Authenticated state.
var ( ErrNoMailboxSelected = errors.New("No mailbox selected") ErrMailboxReadOnly = errors.New("Mailbox opened in read-only mode") )
imap errors in Selected state.
var (
ErrNotAuthenticated = errors.New("Not authenticated")
)
imap errors in Authenticated state.
Functions ¶
func ErrNoStatusResp
deprecated
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
deprecated
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 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 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 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 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 SASLServerFactory ¶
type SASLServerFactory func(conn Conn) sasl.Server
A function that creates SASL servers.
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 (*Server) Command ¶
func (s *Server) Command(name string) HandlerFactory
Command gets a command handler factory for the provided command name.
func (*Server) Enable ¶
Enable some IMAP extensions on this server. Wiki entry: https://github.com/ReverseGame/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/ReverseGame/go-imap/wiki/Using-authentication-mechanisms
func (*Server) ForEachConn ¶
ForEachConn iterates through all opened connections.
func (*Server) ListenAndServe ¶
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 ¶
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.
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).