unpeu

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

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

Go to latest
Published: Apr 1, 2016 License: BSD-3-Clause Imports: 25 Imported by: 0

README

Stories in Ready

Imapsrv

This is an IMAP server written in Go. It is a work in progress.

Demo

In the demo subdirectory there are several implementation examples available.

$ go run ./demo/basic/main.go

You can connect to this server using telnet or netcat. For example:

$ nc -C localhost 1193
* OK IMAP4rev1 Service Ready
10 LOGIN test anypassword
10 OK LOGIN completed
20 CAPABILITY
* CAPABILITY IMAP4rev1
20 OK CAPABILITY completed
30 SELECT inbox
* 8 EXISTS
* 4 RECENT
* OK [UNSEEN 4] Message 4 is first unseen
* OK [UIDVALIDITY 1] UIDs valid
* OK [UIDNEXT 9] Predicted next UID
30 OK SELECT completed
40 LOGOUT
* BYE IMAP4rev1 Server logging out
40 OK LOGOUT completed

Developing

The server is not fully operational on its own. It requires a mailstore and an authentication mechanism.

It defines an interface in mailstore.go which describes the service it needs from a Mailstore. For example a Mailstore could serve its data from: database, filesystem, maildir, etc... At the moment only one mailstore can be used at the same time.

To add a new IMAP command the usual steps are:

  1. Add the command to parser.go
  2. Add the command and its client interaction to commands.go
  3. Put the main functionality in session.go.

Current state

IMAP (RFC 3501)
Client Commands - Any state
  • CAPABILITY command - in progress
  • NOOP command
  • LOGOUT command
Client Commands - Not-Authenticated State
  • STARTTLS command
  • AUTHENTICATE command
  • LOGIN command
Client Commands - Authenticated State
  • SELECT command
  • EXAMINE command
  • CREATE command
  • DELETE command
  • RENAME command
  • SUBSCRIBE command
  • UNSUBSCRIBE command
  • LIST command
  • LSUB command
  • STATUS command
  • APPEND command
Client Commands - Selected State
  • CHECK command
  • CLOSE command
  • EXPUNGE command
  • SEARCH command
  • FETCH command - in progress
  • STORE command
  • COPY command
  • UID command
Server responses
  • OK response
  • NO response
  • BAD response
  • PREAUTH response
  • BYE response

License

3-clause BSD

Documentation

Overview

An IMAP server

Index

Constants

View Source
const (
	SET flagMode = iota
	ADD
	REMOVE
)
View Source
const (
	// Noinferiors indicates it is not possible for any child levels of hierarchy to exist
	// under this name; no child levels exist now and none can be
	// created in the future.
	Noinferiors = 1 << iota

	// Noselect indicates it is not possible to use this name as a selectable mailbox.
	Noselect

	// Marked indicates that the mailbox has been marked "interesting" by the server;
	// the mailbox probably contains messages that have been added since
	// the last time the mailbox was selected
	Marked

	// Unmarked indicates the mailbox does not contain any additional messages since the
	// last time the mailbox was selected.
	Unmarked
)

Mailbox flags

View Source
const DefaultListener = "0.0.0.0:143"

DefaultListener is the listener that is used if no listener is specified

Variables

This section is empty.

Functions

This section is empty.

Types

type Id

type Id string

type Mailbox

type Mailbox struct {
	Name        string   // The name of the mailbox
	Path        []string // Full mailbox path
	Id          Id       // Mailbox id
	UidValidity uint32   // Mailbox uidvalidity
	Flags       uint8    // Mailbox flags
}

Mailbox represents an IMAP mailbox

type Mailstore

type Mailstore interface {
	// GetMailbox gets IMAP mailbox information
	// Returns nil if the mailbox does not exist
	GetMailbox(path []string) (*Mailbox, error)
	// GetMailboxes gets a list of mailboxes at the given path
	GetMailboxes(path []string) ([]*Mailbox, error)
	// FirstUnseen gets the sequence number of the first unseen message in an IMAP mailbox
	FirstUnseen(mbox Id) (int64, error)
	// TotalMessages gets the total number of messages in an IMAP mailbox
	TotalMessages(mbox Id) (int64, error)
	// RecentMessages gets the total number of unread messages in an IMAP mailbox
	RecentMessages(mbox Id) (int64, error)
	// NextUid gets the next available uid in an IMAP mailbox
	NextUid(mbox Id) (int64, error)
	// CountUnseen counts the number of unseen messages in an IMAP mailbox
	CountUnseen(mbox Id) (int64, error)
	// AppendMessage appends the message to an IMAP mailbox
	AppendMessage(mailbox string, flags []string, dateTime time.Time, message string) error
	// Search searches messages in an IMAP mailbox
	// The output ids are sorted by date
	Search(mbox Id, args []searchArgument, returnUid, returnThreads bool) (ids []threadMember, err error)
	// Fetch fetches information on the selected messages in the given
	// mailbox.
	// The output is a list of list. The first level has one element by
	// message, the second level has one element per desired field in the message
	Fetch(mailbox Id, sequenceSet string, args []fetchArgument, returnUid bool) ([]messageFetchResponse, error)
	// Flag adds, sets or removes flags to the given set of messages.
	// It returns a list of struct that each contain the message sequence
	// id and its new set of flags for each message that was modified by
	// the command
	Flag(mode flagMode, mbox Id, sequenceSet string, useUids bool, flags []string) ([]messageFetchResponse, error)
}

Mailstore is a service responsible for I/O with the actual e-mails

type Message

type Message struct {
	Id           string        `json:"id"`
	DateRelative string        `json:"date_relative"`
	Tags         []string      `json:"tags"`
	Header       MessageHeader `json:"headers"`

	// This one is used internally, it doesn't exist as is in the notmuch
	// data model
	Children []Message
}

A message as retrieved from notmuch See the devel/schemata file in notmuch source http://git.notmuchmail.org/git/notmuch/blob/HEAD:/devel/schemata

type MessageHeader

type MessageHeader struct {
	Subject string `json:"subject"`
	From    string `json:"from"`
	To      string `json:"to"`
	Cc      string `json:"cc"`
	Bcc     string `json:"bcc"`
	ReplyTo string `json:"reply-to"`

	// Format is "Mon, 2 Jan 2006 15:04:05 -0700"
	Date string `json:"date"`
}

type NotmuchMailstore

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

func NewNotmuchMailstore

func NewNotmuchMailstore() *NotmuchMailstore

func (*NotmuchMailstore) AppendMessage

func (nm *NotmuchMailstore) AppendMessage(mailbox string, flags []string, dateTime time.Time, message string) error

func (*NotmuchMailstore) CountUnseen

func (nm *NotmuchMailstore) CountUnseen(mbox Id) (int64, error)

func (*NotmuchMailstore) Fetch

func (nm *NotmuchMailstore) Fetch(mailbox Id, sequenceSet string, args []fetchArgument, useUids bool) ([]messageFetchResponse, error)

func (*NotmuchMailstore) FirstUnseen

func (nm *NotmuchMailstore) FirstUnseen(mbox Id) (int64, error)

func (*NotmuchMailstore) Flag

func (nm *NotmuchMailstore) Flag(mode flagMode, mbox Id, sequenceSet string, useUids bool, flags []string) ([]messageFetchResponse, error)

func (*NotmuchMailstore) GetMailbox

func (nm *NotmuchMailstore) GetMailbox(path []string) (*Mailbox, error)

func (*NotmuchMailstore) GetMailboxes

func (nm *NotmuchMailstore) GetMailboxes(path []string) ([]*Mailbox, error)

func (*NotmuchMailstore) NextUid

func (nm *NotmuchMailstore) NextUid(mbox Id) (int64, error)

func (*NotmuchMailstore) RecentMessages

func (nm *NotmuchMailstore) RecentMessages(mbox Id) (int64, error)

func (*NotmuchMailstore) Search

func (nm *NotmuchMailstore) Search(mailbox Id, args []searchArgument, returnUid, returnThreads bool) (threadMembers []threadMember, err error)

func (*NotmuchMailstore) TotalMessages

func (nm *NotmuchMailstore) TotalMessages(mbox Id) (int64, error)

type Option

type Option func(*Server) error

func AuthStoreOption

func AuthStoreOption(a auth.AuthStore) Option

AuthStoreOption adds an authenticaton backend

func ListenOption

func ListenOption(Addr string) Option

ListenOption adds an interface to listen to

func ListenSTARTTLSOption

func ListenSTARTTLSOption(Addr, certFile, keyFile string) Option

ListenSTARTTLSOption enables STARTTLS with the given certificate and keyfile

func MaxClientsOption

func MaxClientsOption(max uint) Option

MaxClientsOption sets the MaxClients config

func StoreOption

func StoreOption(m Mailstore) Option

Add a mailstore to the config StoreOption add a mailstore to the config

type Server

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

Server is an IMAP Server

func NewServer

func NewServer(options ...Option) *Server

NewServer creates a new server with the given options

func (*Server) Start

func (s *Server) Start() error

Start an IMAP server

func (*Server) Stop

func (s *Server) Stop()

Directories

Path Synopsis
boltstore
Package boltstore holds an implementation of github.com/alienscience/imapsrv/auth - AuthStore, using github.com/boltdb/bolt - DB.
Package boltstore holds an implementation of github.com/alienscience/imapsrv/auth - AuthStore, using github.com/boltdb/bolt - DB.
mysqlstore
Package mysqlstore holds an implementation of github.com/alienscience/imapsrv/auth - AuthStore, using MySQL
Package mysqlstore holds an implementation of github.com/alienscience/imapsrv/auth - AuthStore, using MySQL
demo

Jump to

Keyboard shortcuts

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