gluon

package module
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2023 License: MIT Imports: 28 Imported by: 0

README

Gluon

An IMAP4rev1 library focusing on correctness, stability and performance.

CI Status GoDoc Go Report Card License

Demo

The demo server can be started with:

$ GLUON_LOG_LEVEL=trace go run demo/demo.go
DEBU[0000] Applying update                               update="MailboxCreated: Mailbox.ID = 0, Mailbox.Name = INBOX" user-id=ac8970c5-cdb7-4043-ad85-ad9b9defcfb8
DEBU[0000] Applying update                               update="MessagesCreated: MessageCount=0 Messages=[]" user-id=ac8970c5-cdb7-4043-ad85-ad9b9defcfb8
INFO[0000] User added to server                          userID=ac8970c5-cdb7-4043-ad85-ad9b9defcfb8
DEBU[0000] Applying update                               update="MailboxCreated: Mailbox.ID = 0, Mailbox.Name = INBOX" user-id=a51fad46-9bde-462a-a467-6c30f9a40a63
DEBU[0000] Applying update                               update="MessagesCreated: MessageCount=0 Messages=[]" user-id=a51fad46-9bde-462a-a467-6c30f9a40a63
INFO[0000] User added to server                          userID=a51fad46-9bde-462a-a467-6c30f9a40a63
INFO[0000] Server is listening on 127.0.0.1:1143

By default, the demo server includes two demo users, both with password pass. The first has addresses user1@example.com and alias1@example.com. The second has addresses user2@example.com and alias2@example.com.

Once started, connect to the demo server with an email client (e.g. thunderbird) or via telnet:

$ telnet 127.0.0.1 1143
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
* OK [CAPABILITY IDLE IMAP4rev1 MOVE UIDPLUS UNSELECT]  00.00.00 - gluon session ID 2
tag login user1@example.com pass
tag OK [CAPABILITY IDLE IMAP4rev1 MOVE UIDPLUS UNSELECT] Logged in
tag append inbox (\Seen) {14}
+ Ready
To: user@pm.me
tag OK [APPENDUID 1 1] APPEND
tag select inbox
* FLAGS (\Answered \Deleted \Flagged \Seen)
* 1 EXISTS
* 1 RECENT
* OK [PERMANENTFLAGS (\Answered \Deleted \Flagged \Seen)] Flags permitted
* OK [UIDNEXT 2] Predicted next UID
* OK [UIDVALIDITY 1] UIDs valid
tag OK [READ-WRITE] SELECT
tag fetch 1:* (UID BODY.PEEK[])
* 1 FETCH (UID 1 BODY[] {32}
X-Pm-Gluon-Id: 1
To: user@pm.me)
tag OK command completed in 1.030958ms

Changing DB schema

Do not forget to re-generate ent code after changing the DB schema in ./internal/db/ent/schema.

pushd ./internal/db/ent && go generate . && popd

Documentation

Overview

Package gluon implements an IMAP4rev1 (+ extensions) mailserver.

Package gluon implements an IMAP4rev1 (+ extensions) mailserver.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNoSuchMailbox added in v0.15.0

func IsNoSuchMailbox(err error) bool

IsNoSuchMailbox returns true if the error is ErrNoSuchMailbox.

func IsNoSuchMessage added in v0.15.0

func IsNoSuchMessage(err error) bool

IsNoSuchMessage returns true if the error is ErrNoSuchMessage.

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option represents a type that can be used to configure the server.

func WithCmdProfiler added in v0.9.0

func WithCmdProfiler(builder profiling.CmdProfilerBuilder) Option

WithCmdProfiler allows a specific CmdProfilerBuilder to be set for the server's execution.

func WithDBClient added in v0.17.0

func WithDBClient(ci db.ClientInterface) Option

func WithDataDir added in v0.10.0

func WithDataDir(path string) Option

func WithDatabaseDir added in v0.15.0

func WithDatabaseDir(path string) Option

func WithDelimiter

func WithDelimiter(delimiter string) Option

WithDelimiter instructs the server to use the given path delimiter instead of the default ('/').

func WithDisableParallelism added in v0.12.0

func WithDisableParallelism() Option

func WithIMAPLimits added in v0.15.0

func WithIMAPLimits(limits limits2.IMAP) Option

func WithIdleBulkTime added in v0.12.0

func WithIdleBulkTime(idleBulkTime time.Duration) Option

WithIdleBulkTime instructs the server to use the given IDLE bulk time.

func WithLogger

func WithLogger(in, out io.Writer) Option

WithLogger instructs the server to write incoming and outgoing IMAP communication to the given io.Writers.

func WithLoginJailTime added in v0.12.0

func WithLoginJailTime(loginJailTime time.Duration) Option

WithLoginJailTime instructs the server to use the given login jail time.

func WithPanicHandler added in v0.16.0

func WithPanicHandler(panicHandler async.PanicHandler) Option

func WithReporter added in v0.12.0

func WithReporter(reporter reporter.Reporter) Option

func WithStoreBuilder added in v0.9.0

func WithStoreBuilder(builder store.Builder) Option

func WithTLS

func WithTLS(cfg *tls.Config) Option

WithTLS instructs the server to use the given TLS config.

func WithUIDValidityGenerator added in v0.15.0

func WithUIDValidityGenerator(generator imap.UIDValidityGenerator) Option

func WithVersionInfo added in v0.8.0

func WithVersionInfo(
	vmajor, vminor, vpatch int,
	name, vendor, supportURL string,
) Option

type Server

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

Server is the gluon IMAP server.

func New

func New(withOpt ...Option) (*Server, error)

New creates a new server with the given options.

func (*Server) AddUser

func (s *Server) AddUser(ctx context.Context, conn connector.Connector, passphrase []byte) (string, error)

AddUser creates a new user and generates new unique ID for this user. If the user already exists, an error is returned (use LoadUser instead).

func (*Server) AddWatcher

func (s *Server) AddWatcher(ofType ...events.Event) <-chan events.Event

AddWatcher adds a new watcher which watches events of the given types. If no types are specified, the watcher watches all events.

func (*Server) Close

func (s *Server) Close(ctx context.Context) error

Close closes the server.

func (*Server) GetDataPath added in v0.9.0

func (s *Server) GetDataPath() string

GetDataPath returns the path in which gluon stores its data.

func (*Server) GetDatabasePath added in v0.15.0

func (s *Server) GetDatabasePath() string

GetDatabasePath returns the path in which gluon stores its data.

func (*Server) GetErrorCh added in v0.12.0

func (s *Server) GetErrorCh() <-chan error

GetErrorCh returns the error channel.

func (*Server) GetVersionInfo added in v0.8.0

func (s *Server) GetVersionInfo() version.Info

GetVersionInfo returns the version info.

func (*Server) LoadUser added in v0.9.0

func (s *Server) LoadUser(ctx context.Context, conn connector.Connector, userID string, passphrase []byte) (bool, error)

LoadUser adds an existing user using a previously crated unique user ID. It returns true if the user was newly created, false if it already existed.

func (*Server) RemoveUser added in v0.5.0

func (s *Server) RemoveUser(ctx context.Context, userID string, removeFiles bool) error

RemoveUser removes a user from gluon.

func (*Server) Serve

func (s *Server) Serve(ctx context.Context, l net.Listener) error

Serve serves connections accepted from the given listener. It stops serving when the context is canceled, the listener is closed, or the server is closed.

Directories

Path Synopsis
benchmarks
Package connector defines the type that connects the server to a remote.
Package connector defines the type that connects the server to a remote.
mock_connector
Package mock_connector is a generated GoMock package.
Package mock_connector is a generated GoMock package.
internal
ids
response
Package response implements types used when sending IMAP responses back to clients.
Package response implements types used when sending IMAP responses back to clients.
session
Package session handles IMAP commands received from clients within a single IMAP session (one client connection).
Package session handles IMAP commands received from clients within a single IMAP session (one client connection).
Package liner handles reading lines from clients that may or may not require continuation.
Package liner handles reading lines from clients that may or may not require continuation.
mock_reporter
Package mock_reporter is a generated GoMock package.
Package mock_reporter is a generated GoMock package.
Package rfc822 implements methods for handling RFC822 messages.
Package rfc822 implements methods for handling RFC822 messages.
package store implements types that store message literals.
package store implements types that store message literals.
mock_store
Package mock_store is a generated GoMock package.
Package mock_store is a generated GoMock package.
tools

Jump to

Keyboard shortcuts

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