mailhost

package
v0.1.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package mailhost manages hosted email (domains and mailboxes) on a Stalwart mail server through its JMAP management API (Stalwart 0.16+: urn:stalwart:jmap, x:Domain / x:Account).

Index

Constants

This section is empty.

Variables

View Source
var ErrExists = errors.New("already exists on the mail server")

ErrExists is returned when the mail server already has the domain or address.

Functions

func ParseZoneFile

func ParseZoneFile(zone string) []dns.RRSet

ParseZoneFile reads the BIND-style records Stalwart suggests (one per line, TXT values possibly split over parenthesised lines) into canonical record sets.

func ValidLocal

func ValidLocal(l string) bool

ValidLocal checks the part of an address before the @.

Types

type MailboxUpdate

type MailboxUpdate struct {
	Password *string
	QuotaMB  *int
	Aliases  *[]string // local parts on the mailbox's domain
	DomainID string    // needed with Aliases
}

MailboxUpdate changes the fields that are not nil.

type Server

type Server interface {
	CreateDomain(ctx context.Context, name string) (id string, err error)
	// DeleteDomain removes the domain with its DKIM keys (mailboxes must be deleted first).
	DeleteDomain(ctx context.Context, id string) error
	// DomainRecords are the DNS records the domain needs (MX, SPF, DKIM, DMARC, SRV, ...).
	DomainRecords(ctx context.Context, id string) ([]dns.RRSet, error)
	CreateMailbox(ctx context.Context, domainID, local, password string, quotaMB int, aliases []string) (id string, err error)
	UpdateMailbox(ctx context.Context, id string, u MailboxUpdate) error
	DeleteMailbox(ctx context.Context, id string) error
	// Usage returns the used storage (bytes) per mailbox ID.
	Usage(ctx context.Context, ids []string) (map[string]int64, error)
}

Server is a mail server the panel manages.

type Settings

type Settings struct {
	URL          string `json:"url"` // Stalwart HTTP endpoint; empty = email hosting off
	Username     string `json:"username"`
	Password     string `json:"password"`
	IMAPHost     string `json:"imap_host"` // shown to customers, e.g. mail.example.com
	SMTPHost     string `json:"smtp_host"`
	WebmailURL   string `json:"webmail_url"`
	MaxMailboxes int    `json:"max_mailboxes"` // default per new domain
	MaxQuotaMB   int    `json:"max_quota_mb"`  // default per mailbox
}

Settings configure hosted email (stored as JSON under the "mail_hosting" key; "mail" is the panel's own SMTP).

func Defaults

func Defaults() Settings

Defaults until an admin saves settings.

func (Settings) Enabled

func (s Settings) Enabled() bool

Enabled reports whether a mail server is configured.

func (*Settings) Validate

func (s *Settings) Validate() error

Validate normalises and checks settings.

type Stalwart

type Stalwart struct {
	URL      string // e.g. https://mail.example.com (the HTTP listener with /jmap)
	Username string // an administrator, e.g. admin@example.com
	Password string
	Client   *http.Client
}

Stalwart is the JMAP management client.

func (*Stalwart) CreateDomain

func (s *Stalwart) CreateDomain(ctx context.Context, name string) (string, error)

func (*Stalwart) CreateMailbox

func (s *Stalwart) CreateMailbox(ctx context.Context, domainID, local, password string, quotaMB int, aliases []string) (string, error)

func (*Stalwart) DeleteDomain

func (s *Stalwart) DeleteDomain(ctx context.Context, id string) error

func (*Stalwart) DeleteMailbox

func (s *Stalwart) DeleteMailbox(ctx context.Context, id string) error

func (*Stalwart) DomainRecords

func (s *Stalwart) DomainRecords(ctx context.Context, id string) ([]dns.RRSet, error)

func (*Stalwart) UpdateMailbox

func (s *Stalwart) UpdateMailbox(ctx context.Context, id string, u MailboxUpdate) error

func (*Stalwart) Usage

func (s *Stalwart) Usage(ctx context.Context, ids []string) (map[string]int64, error)

Jump to

Keyboard shortcuts

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