db

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MailboxesLoginAttemptsTable string = "audit.mailboxes_login_attempts"
)

Variables

View Source
var (
	ErrAffectedRowsMismatch = errors.New("affected rows do not match expectation")
)

Functions

func Connect

func Connect() (*sql.DB, error)

func Exec

func Exec(db sq.BaseRunner, q sq.Sqlizer, expectAffectedRows int64) error

func PostfixCanonicalMaps

func PostfixCanonicalMaps(r sq.BaseRunner, email utils.EmailAddress) (string, error)

func PostfixRelayDomains

func PostfixRelayDomains(r sq.BaseRunner, fqdn string) (string, error)

func PostfixRelayRecipientMaps

func PostfixRelayRecipientMaps(r sq.BaseRunner, email utils.EmailAddress) (string, error)

func PostfixSMTPDSenderLoginMapsMailboxes

func PostfixSMTPDSenderLoginMapsMailboxes(r sq.BaseRunner, email utils.EmailAddress, limit uint32) ([]string, error)

func PostfixSMTPDSenderLoginMapsRemotes

func PostfixSMTPDSenderLoginMapsRemotes(r sq.BaseRunner, email utils.EmailAddress) ([]string, error)

func PostfixTransportMaps

func PostfixTransportMaps(r sq.BaseRunner, email utils.EmailAddress) (string, error)

func PostfixVirtualAliasDomains

func PostfixVirtualAliasDomains(r sq.BaseRunner, fqdn string) (string, error)

func PostfixVirtualAliasMaps

func PostfixVirtualAliasMaps(r sq.BaseRunner, email utils.EmailAddress, limit uint32) ([]string, error)

func PostfixVirtualMailboxDomains

func PostfixVirtualMailboxDomains(r sq.BaseRunner, fqdn string) (string, error)

func PostfixVirtualMailboxMaps

func PostfixVirtualMailboxMaps(r sq.BaseRunner, email utils.EmailAddress) (string, error)

Types

type Alias

type Alias struct {
	DomainFQDN    string     `json:"domainFQDN"`
	DomainEnabled bool       `json:"domainEnabled"`
	Name          *string    `json:"name"`
	Enabled       bool       `json:"enabled"`
	TargetCount   int        `json:"targetCount"`
	CreatedAt     time.Time  `json:"createdAt"`
	UpdatedAt     time.Time  `json:"updatedAt"`
	DeletedAt     *time.Time `json:"deletedAt,omitempty"`
}

type AliasTarget

type AliasTarget struct {
	AliasEmail                string     `json:"aliasEmail"`
	TargetEmail               string     `json:"targetEmail"`
	IsForeign                 bool       `json:"isForeign"`
	ForwardingToTargetEnabled bool       `json:"forwardingEnabled"`
	SendingFromTargetEnabled  bool       `json:"sendingEnabled"` // Only for recursive
	CreatedAt                 time.Time  `json:"createdAt"`
	UpdatedAt                 time.Time  `json:"updatedAt"`
	DeletedAt                 *time.Time `json:"deletedAt,omitempty"`

	AliasEnabled  bool  `json:"-"`
	DomainEnabled *bool `json:"-"`
}

type AliasesCreateOptions

type AliasesCreateOptions struct {
	Disabled bool
}

type AliasesListOptions

type AliasesListOptions struct {
	FilterDomains  []string
	ByEmail        *utils.EmailAddress
	IncludeDeleted bool
	IncludeAll     bool
	Verbose        bool
}

type AliasesPatchOptions

type AliasesPatchOptions struct {
	Enabled *bool
}

type AliasesRepository

type AliasesRepository interface {
	List(options AliasesListOptions) ([]Alias, error)
	Create(email utils.EmailAddress, options AliasesCreateOptions) error
	Patch(email utils.EmailAddress, options AliasesPatchOptions) error
	Rename(oldEmail utils.EmailAddress, newEmail utils.EmailAddress) error
	Delete(email utils.EmailAddress, options DeleteOptions) error
	Restore(email utils.EmailAddress) error
}

func Aliases

func Aliases(r sq.BaseRunner) AliasesRepository

type AliasesTargetsCreateOptions

type AliasesTargetsCreateOptions struct {
	ForwardEnabled bool
	SendEnabled    bool
}

type AliasesTargetsListOptions

type AliasesTargetsListOptions struct {
	FilterAliasEmails []utils.EmailAddress
	IncludeDeleted    bool
	IncludeAll        bool
}

type AliasesTargetsPatchOptions

type AliasesTargetsPatchOptions struct {
	ForwardingToTargetEnabled *bool
	SendingFromTargetEnabled  *bool
}

type AliasesTargetsRepository

type AliasesTargetsRepository interface {
	List(options AliasesTargetsListOptions) ([]AliasTarget, error)
	Create(aliasEmail utils.EmailAddress, targetEmail utils.EmailAddress, options AliasesTargetsCreateOptions) error
	Patch(aliasEmail utils.EmailAddress, targetEmail utils.EmailAddress, options AliasesTargetsPatchOptions) error
	Delete(aliasEmail utils.EmailAddress, targetEmail utils.EmailAddress, options DeleteOptions) error
	Restore(aliasEmail utils.EmailAddress, targetEmail utils.EmailAddress) error
}

type Config

type Config struct {
	Host      string
	Port      string
	User      string
	DBName    string
	SSLMode   string
	Password  string
	TLSCert   string
	TLSKey    string
	TLSCACert string
}

func GetConfig

func GetConfig() Config

func (Config) DSN

func (c Config) DSN() string

type DeleteOptions

type DeleteOptions struct {
	Force     bool
	Permanent bool
}

type Domain

type Domain struct {
	FQDN                string     `json:"fqdn"`
	Type                string     `json:"type"`
	Enabled             bool       `json:"enabled"`
	Transport           *string    `json:"transport,omitempty"`
	TransportName       *string    `json:"transportName,omitempty"`
	TargetDomainFQDN    *string    `json:"targetDomainFQDN,omitempty"`
	TargetDomainEnabled bool       `json:"targetDomainEnabled"`
	CreatedAt           time.Time  `json:"createdAt"`
	UpdatedAt           time.Time  `json:"updatedAt"`
	DeletedAt           *time.Time `json:"deletedAt,omitempty"`
}

type DomainCatchallTarget

type DomainCatchallTarget struct {
	DomainFQDN                string     `json:"domain"`
	TargetEmail               string     `json:"targetEmail"`
	ForwardingToTargetEnabled bool       `json:"forwardingEnabled"`
	FallbackOnly              bool       `json:"fallbackOnly"`
	CreatedAt                 time.Time  `json:"createdAt"`
	UpdatedAt                 time.Time  `json:"updatedAt"`
	DeletedAt                 *time.Time `json:"deletedAt,omitempty"`

	DomainEnabled bool `json:"-"`
}

type DomainsCatchallTargetsCreateOptions

type DomainsCatchallTargetsCreateOptions struct {
	ForwardEnabled bool
	FallbackOnly   bool
}

type DomainsCatchallTargetsListOptions

type DomainsCatchallTargetsListOptions struct {
	FilterDomains  []string
	IncludeDeleted bool
	IncludeAll     bool
}

type DomainsCatchallTargetsPatchOptions

type DomainsCatchallTargetsPatchOptions struct {
	ForwardingToTargetEnabled *bool
	FallbackOnly              *bool
}

type DomainsCatchallTargetsRepository

type DomainsCatchallTargetsRepository interface {
	List(options DomainsCatchallTargetsListOptions) ([]DomainCatchallTarget, error)
	Create(srcDomainFQDN string, targetEmail utils.EmailAddress, options DomainsCatchallTargetsCreateOptions) error
	Patch(srcDomainFQDN string, targetEmail utils.EmailAddress, options DomainsCatchallTargetsPatchOptions) error
	Delete(srcDomainFQDN string, targetEmail utils.EmailAddress, options DeleteOptions) error
	Restore(srcDomainFQDN string, targetEmail utils.EmailAddress) error
}

type DomainsCreateOptions

type DomainsCreateOptions struct {
	DomainType       string
	TransportName    string // for managed and relayed
	TargetDomainFQDN string // for canonical
	Enabled          bool
}

type DomainsListOptions

type DomainsListOptions struct {
	ByFQDN         string
	IncludeDeleted bool
	IncludeAll     bool
}

type DomainsPatchOptions

type DomainsPatchOptions struct {
	Enabled          *bool
	TransportName    *string // for managed and relayed
	TargetDomainFQDN *string // for canonical
}

type DomainsRepository

type DomainsRepository interface {
	List(options DomainsListOptions) ([]Domain, error)
	Create(fqdn string, options DomainsCreateOptions) error
	Patch(fqdn string, options DomainsPatchOptions) error
	Rename(oldFQDN, newFQDN string) error
	Delete(fqdn string, options DeleteOptions) error
	Restore(fqdn string) error
}

func Domains

func Domains(r sq.BaseRunner) DomainsRepository

type Mailbox

type Mailbox struct {
	DomainFQDN       string     `json:"domainFQDN"`
	DomainEnabled    bool       `json:"domainEnabled"`
	Name             string     `json:"name"`
	LoginEnabled     bool       `json:"loginEnabled"`
	ReceivingEnabled bool       `json:"receivingEnabled"`
	SendingEnabled   bool       `json:"sendingEnabled"`
	PasswordSet      bool       `json:"passwordHashSet"`
	StorageQuota     *int32     `json:"storageQuota,omitempty"`
	Transport        *string    `json:"transport,omitempty"`
	TransportName    *string    `json:"transportName,omitempty"`
	CreatedAt        time.Time  `json:"createdAt"`
	UpdatedAt        time.Time  `json:"updatedAt"`
	DeletedAt        *time.Time `json:"deletedAt,omitempty"`
}

type MailboxLoginAttempt

type MailboxLoginAttempt struct {
	DomainFQDN    string    `json:"domainFQDN"`
	Name          string    `json:"name"`
	Succeeded     bool      `json:"succeeded"`
	FailureReason string    `json:"failureReason"`
	AttemptedAt   time.Time `json:"attemptedAt"`
}

type MailboxesCreateOptions

type MailboxesCreateOptions struct {
	PasswordHash     sql.NullString
	Quota            sql.NullInt32
	TransportName    sql.NullString
	LoginEnabled     bool
	ReceivingEnabled bool
	SendingEnabled   bool
}

type MailboxesListOptions

type MailboxesListOptions struct {
	FilterDomains  []string
	ByEmail        *utils.EmailAddress
	IncludeDeleted bool
	IncludeAll     bool
}

type MailboxesLoginAttemptsListOptions

type MailboxesLoginAttemptsListOptions struct {
	FilterDomains []string
	FilterEmails  []*utils.EmailAddress
}

type MailboxesLoginAttemptsRepository

type MailboxesLoginAttemptsRepository interface {
	List(options MailboxesLoginAttemptsListOptions) ([]MailboxLoginAttempt, error)
	CheckRateLimit(email utils.EmailAddress, count uint32, interval time.Duration) (ok bool, err error)
	Record(email utils.EmailAddress, succeeded bool, failureReason string) (err error)
}

type MailboxesPatchOptions

type MailboxesPatchOptions struct {
	PasswordHash  *sql.NullString
	Quota         *sql.NullInt32
	TransportName *sql.NullString
	Login         *bool
	Receiving     *bool
	Sending       *bool
}

type MailboxesRepository

type MailboxesRepository interface {
	List(options MailboxesListOptions) ([]Mailbox, error)
	Authenticate(email utils.EmailAddress, givenPassword string) (matches bool, err error)
	Create(address utils.EmailAddress, options MailboxesCreateOptions) error
	Patch(email utils.EmailAddress, options MailboxesPatchOptions) error
	Rename(oldEmail utils.EmailAddress, newEmail utils.EmailAddress) error
	Delete(email utils.EmailAddress, options DeleteOptions) error
	Restore(email utils.EmailAddress) error
}

func Mailboxes

func Mailboxes(r sq.BaseRunner) MailboxesRepository

type RecipientRelayed

type RecipientRelayed struct {
	DomainFQDN    string     `json:"domainFQDN"`
	DomainEnabled bool       `json:"domainEnabled"`
	Name          string     `json:"name"`
	Enabled       bool       `json:"enabled"`
	CreatedAt     time.Time  `json:"createdAt"`
	UpdatedAt     time.Time  `json:"updatedAt"`
	DeletedAt     *time.Time `json:"deletedAt,omitempty"`
}

type RecipientsRelayedCreateOptions

type RecipientsRelayedCreateOptions struct {
	Enabled bool
}

type RecipientsRelayedListOptions

type RecipientsRelayedListOptions struct {
	FilterDomains  []string
	ByEmail        *utils.EmailAddress
	IncludeDeleted bool
	IncludeAll     bool
}

type RecipientsRelayedPatchOptions

type RecipientsRelayedPatchOptions struct {
	Enabled *bool
}

type RecipientsRelayedRepository

type RecipientsRelayedRepository interface {
	List(options RecipientsRelayedListOptions) ([]RecipientRelayed, error)
	Create(email utils.EmailAddress, options RecipientsRelayedCreateOptions) error
	Patch(email utils.EmailAddress, options RecipientsRelayedPatchOptions) error
	Rename(oldEmail, newEmail utils.EmailAddress) error
	Delete(email utils.EmailAddress, options DeleteOptions) error
	Restore(email utils.EmailAddress) error
}

type Remote

type Remote struct {
	ID          int        `json:"id"`
	Name        string     `json:"name"`
	Enabled     bool       `json:"enabled"`
	PasswordSet bool       `json:"passwordSet"`
	CreatedAt   time.Time  `json:"createdAt"`
	UpdatedAt   time.Time  `json:"updatedAt"`
	DeletedAt   *time.Time `json:"deletedAt,omitempty"`
}

type RemoteSendGrant

type RemoteSendGrant struct {
	ID            int        `json:"-"`
	RemoteID      int        `json:"-"`
	RemoteName    string     `json:"remote_name"`
	DomainID      int        `json:"-"`
	DomainFQDN    string     `json:"domain_fqdn"`
	DomainEnabled bool       `json:"domain_enabled"`
	Name          string     `json:"name"`
	CreatedAt     time.Time  `json:"created_at"`
	UpdatedAt     time.Time  `json:"updated_at"`
	DeletedAt     *time.Time `json:"deleted_at,omitempty"`
}

type RemotesCreateOptions

type RemotesCreateOptions struct {
	PasswordHash sql.NullString
	Enabled      bool
}

type RemotesListOptions

type RemotesListOptions struct {
	ByName         string
	IncludeDeleted bool
	IncludeAll     bool
}

type RemotesPatchOptions

type RemotesPatchOptions struct {
	PasswordHash *sql.NullString
	Enabled      *bool
}

type RemotesRepository

type RemotesRepository interface {
	List(options RemotesListOptions) ([]Remote, error)
	Create(name string, options RemotesCreateOptions) error
	Patch(name string, options RemotesPatchOptions) error
	Rename(oldName, newName string) error
	Delete(name string, options DeleteOptions) error
	Restore(name string) error
}

func Remotes

func Remotes(r sq.BaseRunner) RemotesRepository

type RemotesSendGrantsCreateOptions

type RemotesSendGrantsCreateOptions struct {
}

type RemotesSendGrantsListOptions

type RemotesSendGrantsListOptions struct {
	FilterRemoteNames []string
	MatchEmail        *utils.EmailAddressOrWildcard
	IncludeDeleted    bool
	IncludeAll        bool
}

type RemotesSendGrantsRepository

type RemotesSendGrantsRepository interface {
	List(options RemotesSendGrantsListOptions) ([]RemoteSendGrant, error)
	Create(remoteName string, email utils.EmailAddressOrWildcard, options RemotesSendGrantsCreateOptions) error
	Delete(remoteName string, email utils.EmailAddressOrWildcard, options DeleteOptions) error
	Restore(remoteName string, email utils.EmailAddressOrWildcard) error
}

type Transport

type Transport struct {
	Name      string     `json:"name"`
	Method    string     `json:"method"`
	Host      string     `json:"host"`
	Port      *uint16    `json:"port,omitempty"`
	MXLookup  bool       `json:"mx_lookup"`
	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt time.Time  `json:"updated_at"`
	DeletedAt *time.Time `json:"deleted_at,omitempty"`
}

type TransportsCreateOptions

type TransportsCreateOptions struct {
	Method   string
	Host     string
	Port     sql.NullInt32
	MxLookup bool
}

type TransportsListOptions

type TransportsListOptions struct {
	ByName         string
	IncludeDeleted bool
	IncludeAll     bool
}

type TransportsPatchOptions

type TransportsPatchOptions struct {
	Method   *string
	Host     *string
	Port     *sql.NullInt32
	MxLookup *bool
}

type TransportsRepository

type TransportsRepository interface {
	List(options TransportsListOptions) ([]Transport, error)
	Create(name string, options TransportsCreateOptions) error
	Patch(name string, options TransportsPatchOptions) error
	Rename(oldName, newName string) error
	Delete(name string, options DeleteOptions) error
	Restore(name string) error
}

func Transports

func Transports(r sq.BaseRunner) TransportsRepository

type TxExecForEach

type TxExecForEach[T any] func(tx *sql.Tx, item T) error

type TxExecFunc

type TxExecFunc func(tx *sql.Tx) error

type TxForEachRunner

type TxForEachRunner[T any] struct {
	Items          []T
	Exec           TxExecForEach[T]
	ItemString     func(item T) string
	FailureMessage string
	SuccessMessage string
}

func (TxForEachRunner[T]) Run

func (r TxForEachRunner[T]) Run()

type TxRunner

type TxRunner struct {
	Exec           TxExecFunc
	ItemString     string
	FailureMessage string
	SuccessMessage string
}

func (TxRunner) Run

func (r TxRunner) Run()

Jump to

Keyboard shortcuts

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