popgun

package module
v0.0.0-...-2c5552e Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2017 License: MIT Imports: 8 Imported by: 1

README

POPgun

Build Status Coverage Status Go Report Card

POPgun is a lightweight POP3 server implementation in Go. POPgun meets RFC1939 and was mainly created for develmail.com.

Getting Started

POPgun is meant to be used as a package and you need to create your own implementations of Authorizator and Backend interfaces.

1. Import the POPgun package
import (
    "github.com/DevelHell/popgun"
)
2. Implement Authorizator and Backend interfaces

Authorizator is used for user authorization and there's only one function Authorize(user, pass string). Be aware that single instance is shared across all client connections.

Backend is used for mail storage access, e.g. database storage. Single Backend instance is shared across all client connections connections as well.

Example dummy implementations can be found in backend package, see comments in these files for more information. When your're done, create an instance of both of them:

backend := backends.DummyBackend{}
authorizator := backends.DummyAuthorizator{}
3. Configure and run the server

There is only one configuration field for now - ListenInterface, which defines interface (ip address) and port to listen on. Server is started in separate go routine, so be sure to keep the server busy, e.g. using wait groups:

cfg := popgun.Config{
    ListenInterface: "localhost:1100",
}

var wg sync.WaitGroup
wg.Add(1)

server := NewServer(cfg, authorizator, backend)
err := server.Start()
if err != nil {
    log.Fatal(err)
    return
}
wg.Wait()

Server is logging to stderr using log package.

License and Contribution

POPgun is released under MIT license. Feel free to fork, redistribute or contribute!

Documentation

Index

Constants

View Source
const (
	STATE_AUTHORIZATION = iota + 1
	STATE_TRANSACTION
	STATE_UPDATE
)

Variables

View Source
var (
	ErrInvalidState = fmt.Errorf("Invalid state")
)

Functions

This section is empty.

Types

type Authorizator

type Authorizator interface {
	Authorize(user, pass string) bool
}

type Backend

type Backend interface {
	Stat(user string) (messages, octets int, err error)
	List(user string) (octets []int, err error)
	ListMessage(user string, msgId int) (exists bool, octets int, err error)
	Retr(user string, msgId int) (message string, err error)
	Dele(user string, msgId int) error
	Rset(user string) error
	Uidl(user string) (uids []string, err error)
	UidlMessage(user string, msgId int) (exists bool, uid string, err error)
	Update(user string) error
	Lock(user string) error
	Unlock(user string) error
}

type CapaCommand

type CapaCommand struct{}

func (CapaCommand) Run

func (cmd CapaCommand) Run(c *Client, args []string) (int, error)

type Client

type Client struct {
	// contains filtered or unexported fields
}

type Config

type Config struct {
	ListenInterface string `json:"listen_interface"`
}

type DeleCommand

type DeleCommand struct{}

func (DeleCommand) Run

func (cmd DeleCommand) Run(c *Client, args []string) (int, error)

type Executable

type Executable interface {
	Run(c *Client, args []string) (int, error)
}

type ListCommand

type ListCommand struct{}

func (ListCommand) Run

func (cmd ListCommand) Run(c *Client, args []string) (int, error)

type NoopCommand

type NoopCommand struct{}

func (NoopCommand) Run

func (cmd NoopCommand) Run(c *Client, args []string) (int, error)

type PassCommand

type PassCommand struct{}

func (PassCommand) Run

func (cmd PassCommand) Run(c *Client, args []string) (int, error)

type Printer

type Printer struct {
	// contains filtered or unexported fields
}

func NewPrinter

func NewPrinter(conn net.Conn) *Printer

func (Printer) Err

func (p Printer) Err(msg string, a ...interface{})

func (Printer) MultiLine

func (p Printer) MultiLine(msgs []string)

func (Printer) Ok

func (p Printer) Ok(msg string, a ...interface{})

func (Printer) Welcome

func (p Printer) Welcome()

type QuitCommand

type QuitCommand struct{}

func (QuitCommand) Run

func (cmd QuitCommand) Run(c *Client, args []string) (int, error)

type RetrCommand

type RetrCommand struct{}

func (RetrCommand) Run

func (cmd RetrCommand) Run(c *Client, args []string) (int, error)

type RsetCommand

type RsetCommand struct{}

func (RsetCommand) Run

func (cmd RsetCommand) Run(c *Client, args []string) (int, error)

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(cfg Config, auth Authorizator, backend Backend) *Server

func (Server) Start

func (s Server) Start() error

type StatCommand

type StatCommand struct{}

func (StatCommand) Run

func (cmd StatCommand) Run(c *Client, args []string) (int, error)

type UidlCommand

type UidlCommand struct{}

func (UidlCommand) Run

func (cmd UidlCommand) Run(c *Client, args []string) (int, error)

type UserCommand

type UserCommand struct{}

func (UserCommand) Run

func (cmd UserCommand) Run(c *Client, args []string) (int, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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