backend

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package backend defines the Provider interface for multi-protocol email support.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotSupported = errors.New("operation not supported by this provider")

ErrNotSupported is returned when a provider does not support an operation.

Functions

func RegisterBackend

func RegisterBackend(protocol string, fn NewFunc)

RegisterBackend registers a backend constructor for a protocol name.

Types

type Attachment

type Attachment struct {
	Filename         string
	PartID           string
	Data             []byte
	Encoding         string
	MIMEType         string
	ContentID        string
	Inline           bool
	IsSMIMESignature bool
	SMIMEVerified    bool
	IsSMIMEEncrypted bool
}

Attachment holds data for an email attachment.

type Capabilities

type Capabilities struct {
	CanSend         bool
	CanMove         bool
	CanArchive      bool
	CanPush         bool
	CanSearchServer bool
	CanFetchFolders bool
	SupportsSMIME   bool
}

Capabilities describes what a backend supports.

type CapabilityProvider

type CapabilityProvider interface {
	Capabilities() Capabilities
}

CapabilityProvider optionally reports what a backend can do.

type Email

type Email struct {
	UID         uint32
	From        string
	To          []string
	Subject     string
	Body        string
	Date        time.Time
	IsRead      bool
	MessageID   string
	References  []string
	Attachments []Attachment
	AccountID   string
}

Email represents a single email message.

type EmailReader

type EmailReader interface {
	FetchEmails(ctx context.Context, folder string, limit, offset uint32) ([]Email, error)
	FetchEmailBody(ctx context.Context, folder string, uid uint32) (string, []Attachment, error)
	FetchAttachment(ctx context.Context, folder string, uid uint32, partID, encoding string) ([]byte, error)
}

EmailReader fetches emails and their content.

type EmailSender

type EmailSender interface {
	SendEmail(ctx context.Context, msg *OutgoingEmail) error
}

EmailSender sends outgoing email.

type EmailWriter

type EmailWriter interface {
	MarkAsRead(ctx context.Context, folder string, uid uint32) error
	DeleteEmail(ctx context.Context, folder string, uid uint32) error
	ArchiveEmail(ctx context.Context, folder string, uid uint32) error
	MoveEmail(ctx context.Context, uid uint32, srcFolder, dstFolder string) error
}

EmailWriter modifies email state.

type Folder

type Folder struct {
	Name       string
	Delimiter  string
	Attributes []string
}

Folder represents a mailbox/folder.

type FolderManager

type FolderManager interface {
	FetchFolders(ctx context.Context) ([]Folder, error)
}

FolderManager lists folders/mailboxes.

type NewFunc

type NewFunc func(account *config.Account) (Provider, error)

NewFunc is the constructor signature for backend providers.

type Notifier

type Notifier interface {
	Watch(ctx context.Context, folder string) (<-chan NotifyEvent, func(), error)
}

Notifier provides real-time notifications for new email.

type NotifyEvent

type NotifyEvent struct {
	Type      NotifyType
	Folder    string
	AccountID string
}

NotifyEvent is emitted by Watch() when something changes in a mailbox.

type NotifyType

type NotifyType int

NotifyType indicates the kind of notification event.

const (
	NotifyNewEmail NotifyType = iota
	NotifyExpunge
	NotifyFlagChange
)

type OutgoingEmail

type OutgoingEmail struct {
	To           []string
	Cc           []string
	Bcc          []string
	Subject      string
	PlainBody    string
	HTMLBody     string
	Images       map[string][]byte
	Attachments  map[string][]byte
	InReplyTo    string
	References   []string
	SignSMIME    bool
	EncryptSMIME bool
}

OutgoingEmail contains everything needed to send an email.

type Provider

type Provider interface {
	EmailReader
	EmailWriter
	EmailSender
	FolderManager
	Notifier
	Close() error
}

Provider is the unified interface that all email backends must implement.

func New

func New(account *config.Account) (Provider, error)

New creates a Provider for the given account based on its Protocol field. An empty protocol defaults to "imap".

Directories

Path Synopsis
Package imap implements the backend.Provider interface by delegating to the existing fetcher and sender packages.
Package imap implements the backend.Provider interface by delegating to the existing fetcher and sender packages.
Package jmap implements the backend.Provider interface using the JMAP protocol (RFC 8620 Core + RFC 8621 Mail).
Package jmap implements the backend.Provider interface using the JMAP protocol (RFC 8620 Core + RFC 8621 Mail).
Package pop3 implements the backend.Provider interface using POP3 for reading email and SMTP for sending.
Package pop3 implements the backend.Provider interface using POP3 for reading email and SMTP for sending.

Jump to

Keyboard shortcuts

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