Documentation
¶
Overview ¶
Example ¶
a := &auth{ m: &memoryMaildrop{ messages: map[string]string{ "foo": "Subject: first", "bar": "Subject: second", "foobar": "Subject: thirdasdasd\n\ndas", }, }, } err := ListenAndServeTLS(":1995", "cert.pem", "key.pem", a) if err != nil { log.Fatalln(err) }
Output:
Index ¶
Examples ¶
Constants ¶
const ( POP3User = "USER" POP3Pass = "PASS" POP3StartTLS = "STLS" POP3Capability = "CAPA" POP3Status = "STAT" POP3List = "LIST" POP3UIDList = "UIDL" POP3Retrieve = "RETR" POP3Delete = "DELE" POP3Noop = "NOOP" POP3Reset = "RSET" POP3Quit = "QUIT" )
Variables ¶
var ( ErrInvalidAuthorizer = errors.New("pop3: Missing authorizer") ErrServerClosed = errors.New("pop3: Server closed") )
Functions ¶
func ListenAndServe ¶
func ListenAndServe(addr string, auth Authorizer) error
ListenAndServe always returns a non-nil error.
func ListenAndServeTLS ¶
func ListenAndServeTLS(addr, certFile, keyFile string, auth Authorizer) error
ListenAndServeTLS acts identically to ListenAndServe, except that it expects POP3S connections. Additionally, files containing a certificate and matching private key for the server must be provided.
Types ¶
type Authorizer ¶
type Authorizer interface {
Auth(user, pass string) (Maildropper, error)
}
Authorizer responds to a POP3 AUTHORIZATION state request.
type Maildropper ¶
type Maildropper interface { List() (size map[string]int, err error) Get(key string, message io.Writer) (err error) Delete(key string) (err error) }
Maildropper responds to a POP3 TRANSACTION state requests.
type Server ¶
type Server struct { Addr string // TCP address to listen on, ":pop3" if empty Auth Authorizer // TLSConfig optionally provides a TLS configuration for use // by ServeTLS and ListenAndServeTLS. Note that this value is // cloned by ServeTLS and ListenAndServeTLS, so it's not // possible to modify the configuration with methods like // tls.Config.SetSessionTicketKeys. To use // SetSessionTicketKeys, use Server.Serve with a TLS Listener // instead. TLSConfig *tls.Config // ErrorLog specifies an optional logger for errors accepting // connections, unexpected behavior from handlers, and // underlying FileSystem errors. // If nil, logging is done via the log package's standard logger. ErrorLog *log.Logger // contains filtered or unexported fields }
A Server defines parameters for running an POP3 server. The zero value for Server is a valid configuration.
func (*Server) Close ¶
Close immediately closes all active net.Listeners and any connections in state StateNew, StateActive, or StateIdle. For a graceful shutdown, use Shutdown.
Close does not attempt to close (and does not even know about) any hijacked connections, such as WebSockets.
Close returns any error returned from closing the Server's underlying Listener(s).
func (*Server) ListenAndServe ¶
ListenAndServe always returns a non-nil error. After Shutdown or Close, the returned error is ErrServerClosed.
func (*Server) ListenAndServeTLS ¶
ListenAndServeTLS listens on the TCP network address srv.Addr and then calls ServeTLS to handle requests on incoming TLS connections. Accepted connections are configured to enable TCP keep-alives.
Filenames containing a certificate and matching private key for the server must be provided if neither the Server's TLSConfig.Certificates nor TLSConfig.GetCertificate are populated. If the certificate is signed by a certificate authority, the certFile should be the concatenation of the server's certificate, any intermediates, and the CA's certificate.
func (*Server) Serve ¶
Serve accepts incoming connections on the Listener l, creating a new service goroutine for each. The service goroutines read requests and then call srv.Handler to reply to them.
Serve always returns a non-nil error and closes l. After Shutdown or Close, the returned error is ErrServerClosed.
func (*Server) ServeTLS ¶
ServeTLS accepts incoming connections on the Listener l, creating a new service goroutine for each. The service goroutines perform TLS setup and then read requests, calling srv.Handler to reply to them.
Files containing a certificate and matching private key for the server must be provided if neither the Server's TLSConfig.Certificates nor TLSConfig.GetCertificate are populated. If the certificate is signed by a certificate authority, the certFile should be the concatenation of the server's certificate, any intermediates, and the CA's certificate.
ServeTLS always returns a non-nil error. After Shutdown or Close, the returned error is ErrServerClosed.