pop3

package module
v0.0.0-...-bee104b Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2019 License: MIT Imports: 16 Imported by: 0

README

pop3 (s3-pop3-server) - pop3 server with s3 backend

Overview

s3-pop3-server is a service that takes S3 bucket and presents it as pop3 maildrop. pop3 is a golang library to build pop3 servers. Both are written in pure go. API documentation for pop3 can be found in GoDoc.

Installation

$ go get -u github.com/dzeromsk/pop3/...

This will make the s3-pop3-server tool available in ${GOPATH}/bin, which by default means ~/go/bin.

Usage of the binary (s3-pop3-server)

s3-pop3-server starts pop3 server on port 995 with s3 bucket used as a storage.

Usage of s3-pop3-server:
  -addr string
        Address to listen to (default ":995")
  -bucket string
        AWS S3 bucket name (default "emails")
  -cert string
        TLS Certificate used by server (default "cert.pem")
  -key string
        TLS Private key used by server (default "key.pem")
  -region string
        AWS S3 bucket region (default "eu-west-1")

Usage of the library (pop3)

API documentation for pop3 can be found in GoDoc.

import "github.com/dzeromsk/pop3"
...
err := pop3.ListenAndServeTLS(*address, *cert, *key, &s3auth{
  bucket: *bucket,
  region: *region,
})
if err != nil {
  log.Fatalln(err)
}

Features

  • Simple.
  • No config files.
  • Minimal pop3 server feature set.

Downsides

  • All of the files are served from s3.
  • Does not support all pop3 commands.

Philosophy

Sometimes you just want S3 bucket to be accessible via pop3 protocol. For example when receiving Email with Amazon SES and storing them in S3. There are ways to make it work with existing pop3 servers. But you don't need all that. You want something similar to proxy.

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

View Source
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

View Source
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

func (srv *Server) Close() error

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

func (srv *Server) ListenAndServe() error

ListenAndServe always returns a non-nil error. After Shutdown or Close, the returned error is ErrServerClosed.

func (*Server) ListenAndServeTLS

func (srv *Server) ListenAndServeTLS(certFile, keyFile string) error

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

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

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

func (srv *Server) ServeTLS(l net.Listener, certFile, keyFile string) error

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.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL