maildb

package
v0.0.0-...-c007887 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2022 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMdbTransaction       = errors.New("Not in a transaction")
	ErrMdbAddressEmpty      = errors.New("address is empty")
	ErrMdbTargetEmpty       = errors.New("target is empty")
	ErrMdbAddrIllegalChars  = errors.New("illegal chars in address")
	ErrMdbAddrNoAddr        = errors.New("address extension without user part")
	ErrMdbNoLocalPipe       = errors.New("no local pipe or redirect")
	ErrMdbNoQuotedSpace     = errors.New("pipe with spaces requires quotes")
	ErrMdbBadInclude        = errors.New("badly formed or empty include")
	ErrMdbArgStringEmpty    = errors.New("Empty string not allowed here")
	ErrMdbTransNoColon      = errors.New("No ':' separator")
	ErrMdbAddressNotFound   = errors.New("address not found")
	ErrMdbDomainNotFound    = errors.New("domain not found")
	ErrMdbDupAddress        = errors.New("Address already exists")
	ErrMdbDupDomain         = errors.New("Domain already exists")
	ErrMdbAddressBusy       = errors.New("Address still in use")
	ErrMdbDomainBusy        = errors.New("Domain still in use")
	ErrMdbTransNotFound     = errors.New("Transport not found")
	ErrMdbDupTrans          = errors.New("Transport already exists")
	ErrMdbTransBusy         = errors.New("Transport still in use")
	ErrMdbAccessNotFound    = errors.New("Access not found")
	ErrMdbAccessBadAction   = errors.New("Access action cannot be empty")
	ErrMdbAccessBusy        = errors.New("Access still in use")
	ErrMdbDupAccess         = errors.New("Access already exists")
	ErrMdbNotAlias          = errors.New("address is not an alias")
	ErrMdbNoAliases         = errors.New("No Aliases")
	ErrMdbAddressTarget     = errors.New("virtual alias must have an addressable target")
	ErrMdbNoRecipients      = errors.New("No recipients supplied for alias")
	ErrMdbRecipientNotFound = errors.New("alias recipient not found")
	ErrMdbNoMailboxes       = errors.New("No Mailboxes")
	ErrMdbMboxNoDomain      = errors.New("Mailbox must have a domain")
	ErrMdbMboxNotMboxDomain = errors.New("Mailbox must be in a vmailbox domain")
	ErrMdbNotMbox           = errors.New("address is not a mailbox")
	ErrMdbIsAlias           = errors.New("New mailbox already an alias")
	ErrMdbIsMbox            = errors.New("New alias already a mailbox")
	ErrMdbMboxBadPw         = errors.New("Unrecognized password type")
	ErrMdbBadName           = errors.New("Not a correct name")
	ErrMdbBadClass          = errors.New("Unknown domain class")
	ErrMdbBadUid            = errors.New("User ID must be unsigned decimal integer")
	ErrMdbBadGid            = errors.New("Group ID must be unsigned decimal integer")
	ErrMdbBadUpdate         = errors.New("Update did not happen")
	ErrMdbMboxIsRecip       = errors.New("Mailbox is an alias recipient")
)

Error return constants

View Source
var (
	NullStr = sql.NullString{Valid: false}
	NullInt = sql.NullInt64{Valid: false}
)

Useful constants

View Source
var DbContent embed.FS

Embedded files for database

Functions

func IsErrConstraintForeignKey

func IsErrConstraintForeignKey(err error) bool

IsErrConstraintForeignKey attempting insert with either non-existent ref or delete with refs pointing to it.

func IsErrConstraintNotNull

func IsErrConstraintNotNull(err error) bool

IsErrConstraintNotNull

func IsErrConstraintUnique

func IsErrConstraintUnique(err error) bool

IsErrConstraintUnique

Types

type Access

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

Access

func (*Access) Action

func (a *Access) Action() string

Action

func (*Access) Export

func (a *Access) Export() string

Export

func (*Access) Name

func (a *Access) Name() string

Name

func (*Access) SetAction

func (a *Access) SetAction(action string) error

SetAction under transaction

type Address

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

func (*Address) Address

func (a *Address) Address() string

Address

func (*Address) Alias

func (a *Address) Alias() (*Alias, error)

Alias Return the alias recipients for this address

func (*Address) AttachAlias

func (a *Address) AttachAlias(target string) error

AttachAlias Attach an alias recipient to this address. If it was just a simple address before, it is now an alias with one or more recipients

func (*Address) ClearRclass

func (a *Address) ClearRclass() error

ClearRclass

func (*Address) ClearTransport

func (a *Address) ClearTransport() error

ClearTransport

func (*Address) Export

func (a *Address) Export() string

Export

func (*Address) Id

func (a *Address) Id() int64

Id

func (*Address) InVMailDomain

func (a *Address) InVMailDomain() bool

InVmailDomain

func (*Address) IsLocal

func (a *Address) IsLocal() bool

IsLocal a "local" address has no domain (address.domain IS NULL)

func (*Address) Rclass

func (a *Address) Rclass() string

Rclass

func (*Address) SetRclass

func (a *Address) SetRclass(name string) error

SetRclass

func (*Address) SetTransport

func (a *Address) SetTransport(name string) error

SetTransport

func (*Address) Transport

func (a *Address) Transport() string

Transport

type AddressParts

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

AddressParts

func DecodeRFC822

func DecodeRFC822(addr string) (*AddressParts, error)

DecodeRFC822 Decode an RFC822 address into its constituent parts Actually, we decode per RFC5322

func DecodeTarget

func DecodeTarget(addr string) (*AddressParts, error)

DecodeTarget Decode an RFC822 address and the various options for extensions

func (*AddressParts) IsLocal

func (ap *AddressParts) IsLocal() bool

IsLocal

func (*AddressParts) IsPipe

func (ap *AddressParts) IsPipe() bool

IsPipe

func (*AddressParts) String

func (ap *AddressParts) String() string

type Alias

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

Alias

func (*Alias) Export

func (al *Alias) Export() string

Export return a line for this alias Note that /etc/aliases is a different syntax from virtual(5)

func (*Alias) Id

func (al *Alias) Id() int64

Id

func (*Alias) Targets

func (al *Alias) Targets() []*Recipient

Targets

type Class

type Class int

Class domain classes are used for easy categorizing domains, some of which we actually own and others (like relay) are somewhere else.

type Domain

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

Domain

func (*Domain) Class

func (d *Domain) Class() string

Class

func (*Domain) ClearRclass

func (d *Domain) ClearRclass() error

ClearRclass

func (*Domain) ClearTransport

func (d *Domain) ClearTransport() error

ClearTransport

func (*Domain) ClearVGid

func (d *Domain) ClearVGid() error

ClearVGid

func (*Domain) ClearVUid

func (d *Domain) ClearVUid() error

ClearVUid

func (*Domain) Export

func (d *Domain) Export() string

Export is export/import file format

func (*Domain) Id

func (d *Domain) Id() int64

Id

func (*Domain) IsInternet

func (d *Domain) IsInternet() bool

IsInternet

func (*Domain) IsLocal

func (d *Domain) IsLocal() bool

IsLocal

func (*Domain) IsRelay

func (d *Domain) IsRelay() bool

IsRelay

func (*Domain) IsVirtual

func (d *Domain) IsVirtual() bool

IsVirtual

func (*Domain) IsVmailbox

func (d *Domain) IsVmailbox() bool

IsVmailbox

func (*Domain) Name

func (d *Domain) Name() string

Name just the name

func (*Domain) Rclass

func (d *Domain) Rclass() string

Rclass

func (*Domain) SetClass

func (d *Domain) SetClass(class string) error

SetClass

func (*Domain) SetRclass

func (d *Domain) SetRclass(rclass string) error

SetRclass

func (*Domain) SetTransport

func (d *Domain) SetTransport(name string) error

SetTransport

func (*Domain) SetVGid

func (d *Domain) SetVGid(vgid int64) error

SetVGid

func (*Domain) SetVUid

func (d *Domain) SetVUid(vuid int64) error

SetVUid

func (*Domain) Transport

func (d *Domain) Transport() string

Transport

func (*Domain) Vgid

func (d *Domain) Vgid() string

Vgid

func (*Domain) Vuid

func (d *Domain) Vuid() string

Vuid

type Input

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

func (*Input) Close

func (i *Input) Close()

Close

func (*Input) Reader

func (i *Input) Reader() io.Reader

Reader

type MailDB

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

MailDB

func NewMailDB

func NewMailDB(dbPath string) (*MailDB, error)

NewMailDB Sqlite DB open. ":memory:" for testing...

func (*MailDB) Begin

func (mdb *MailDB) Begin()

Begin If a begin() goes bad, we are in serious trouble. Just crash

func (*MailDB) Close

func (mdb *MailDB) Close()

Close This must match a successful NewMailDB or it will panic best practice is to defer a call here in the same function that did the open

func (*MailDB) DefaultInt

func (mdb *MailDB) DefaultInt(sym string) int64

func (*MailDB) DefaultString

func (mdb *MailDB) DefaultString(sym string) string

DefaultString We panic() here because an error here means someone has changed/mis-matched to the schema and at that point the best thing to do is crash, not mess up the DB

func (*MailDB) DeleteAccess

func (mdb *MailDB) DeleteAccess(name string) error

DeleteAccess

func (*MailDB) DeleteAddress

func (mdb *MailDB) DeleteAddress(addr string) error

DeleteAddress does not need a transaction because the cleanup delete to an unreferenced domain is done by a trigger

func (*MailDB) DeleteDomain

func (mdb *MailDB) DeleteDomain(name string) error

DeleteDomain

func (*MailDB) DeleteTransport

func (mdb *MailDB) DeleteTransport(name string) error

DeleteTransport

func (*MailDB) DeleteVMailbox

func (mdb *MailDB) DeleteVMailbox(address string) error

DeleteVMailbox Potential cascaded delete of address is handled by triggers

func (*MailDB) End

func (mdb *MailDB) End(err *error)

End This is deferred so pass a reference to the error var Commit on no errors, rollback otherwise

func (*MailDB) FindAccess

func (mdb *MailDB) FindAccess(name string) ([]*Access, error)

FindAccess '*' find all access rules 'something*something' find matching names

func (*MailDB) FindAddress

func (mdb *MailDB) FindAddress(address string) ([]*Address, error)

FindAddress

func (*MailDB) FindDomain

func (mdb *MailDB) FindDomain(name string) ([]*Domain, error)

FindDomain LookupDomain but with wildcards '*' - find all domains '*.somedomain' - find all subdomains of somedomain '*.*' - find all domains with subdomains

func (*MailDB) FindTransport

func (mdb *MailDB) FindTransport(name string) ([]*Transport, error)

FindTransport '*' find all transport rules 'something*something' find matching names

func (*MailDB) FindVMailbox

func (mdb *MailDB) FindVMailbox(user string) ([]*VMailbox, error)

FindVMailbox name@domain username for mailbox *@domain all users in this domain *@* all users in all domains * error. No local system users (for now) return a list of matched mailboxes

func (*MailDB) GetAccess

func (mdb *MailDB) GetAccess(name string) (*Access, error)

GetAccess inside transactions

func (*MailDB) GetAddress

func (mdb *MailDB) GetAddress(addr string) (*Address, error)

GetAddress Lookup an address under an active transaction really a copy of LookupAddress with transaction queries...

func (*MailDB) GetDomain

func (mdb *MailDB) GetDomain(name string) (*Domain, error)

GetDomain fetch the domain under transaction

func (*MailDB) GetOrInsAddress

func (mdb *MailDB) GetOrInsAddress(addr string) (*Address, error)

GetOrInsAddress get the address and if not found, insert it. Make this common pattern a function on its own. Transaction required

func (*MailDB) GetTransport

func (mdb *MailDB) GetTransport(name string) (*Transport, error)

GetTransport inside transactions

func (*MailDB) GetVMailbox

func (mdb *MailDB) GetVMailbox(user string) (*VMailbox, error)

GetVmailbox lookup a mailbox under a transaction

func (*MailDB) InsertAccess

func (mdb *MailDB) InsertAccess(name string, action string) (*Access, error)

InsertAccess

func (*MailDB) InsertAddress

func (mdb *MailDB) InsertAddress(address string) (*Address, error)

InsertAddress Insert an address MUST be under a transaction

func (*MailDB) InsertDomain

func (mdb *MailDB) InsertDomain(name string) (*Domain, error)

InsertDomain returns a *Domain. If error, rollback the transaction.

func (*MailDB) InsertTransport

func (mdb *MailDB) InsertTransport(name string) (*Transport, error)

InsertTransport

func (*MailDB) InsertVMailbox

func (mdb *MailDB) InsertVMailbox(user string) (*VMailbox, error)

InsertVMailbox must be under a transaction

func (*MailDB) LoadSchema

func (mdb *MailDB) LoadSchema(schema string) error

LoadSchema if the schema name starts with "/" or ".", read from the filesystem otherwise read from the embedded files

func (*MailDB) LookupAccess

func (mdb *MailDB) LookupAccess(name string) (*Access, error)

LookupAccess outside transactions

func (*MailDB) LookupAddress

func (mdb *MailDB) LookupAddress(addr string) (*Address, error)

LookupAddress Lookup an address without an active transaction

func (*MailDB) LookupAlias

func (mdb *MailDB) LookupAlias(alias string) ([]*Alias, error)

LookupAlias get either "local_user" or "mbox@domain" aliases name@domain returns that alias recipients for this address * returns all local (/etc/aliases) aliases *@domain returns all aliases in this domain name@* returns all aliases of this name, e.g. abuse@foo.com, abuse@example.org *@* returns all virtual aliases in the database

func (*MailDB) LookupDomain

func (mdb *MailDB) LookupDomain(name string) (*Domain, error)

LookupDomain Does lookup outside a transaction

func (*MailDB) LookupTransport

func (mdb *MailDB) LookupTransport(name string) (*Transport, error)

LookupTransport outside transactions

func (*MailDB) LookupVMailbox

func (mdb *MailDB) LookupVMailbox(user string) (*VMailbox, error)

LookupVmailbox lookup a mailbox without transactions

func (*MailDB) NewInput

func (mdb *MailDB) NewInput(name string, embeddedName string) (*Input, error)

FetchFile

func (*MailDB) Query

func (mdb *MailDB) Query(q string) ([]QueryRes, error)

Query Generic query. Used mainly for testing return empty slice for no rows

func (*MailDB) RemoveAlias

func (mdb *MailDB) RemoveAlias(alias string) error

RemoveAlias and all its targets All we need to do here is delete the aliases that aliasAddr points to As the set of aliases disappear, their delete triggers clean up all the orphan targets (and the alias address itself) on the way out

func (*MailDB) RemoveRecipient

func (mdb *MailDB) RemoveRecipient(alias string, recipient string) error

RemoveRecipient. Remove the alias as well if this is the last target

type QueryRes

type QueryRes map[string]interface{}

QueryRes

func (QueryRes) NumColumns

func (r QueryRes) NumColumns() int

NumColumns

type Recipient

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

Recipient in alias list

func (*Recipient) Recipient

func (tg *Recipient) Recipient() string

Recipient beware! virtual aliases cannot have /etc/aliases attributes (pipes and stuff)

type TableInfo

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

type Transport

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

Transport DB table

func (*Transport) ClearNexthop

func (tr *Transport) ClearNexthop() error

ClearNexthop

func (*Transport) ClearTransport

func (tr *Transport) ClearTransport() error

ClearTransport

func (*Transport) Export

func (tr *Transport) Export() string

Export

func (*Transport) Name

func (tr *Transport) Name() string

Name

func (*Transport) Nexthop

func (tr *Transport) Nexthop() string

Nexthop

func (*Transport) SetNexthop

func (tr *Transport) SetNexthop(hop string) error

SetNexthop

func (*Transport) SetTransport

func (tr *Transport) SetTransport(trans string) error

SetTransport

func (*Transport) Transport

func (tr *Transport) Transport() string

Transport

type TransportParts

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

func DecodeTransport

func DecodeTransport(trans string) (*TransportParts, error)

DecodeTransport

type VMailbox

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

VMailbox

func (*VMailbox) ClearGid

func (m *VMailbox) ClearGid() error

ClearGid

func (*VMailbox) ClearHome

func (m *VMailbox) ClearHome() error

ClearHome

func (*VMailbox) ClearPassword

func (m *VMailbox) ClearPassword() error

ClearPassword

func (*VMailbox) ClearQuota

func (m *VMailbox) ClearQuota() error

ClearQuota

func (*VMailbox) ClearUid

func (m *VMailbox) ClearUid() error

ClearUid

func (*VMailbox) Disable

func (m *VMailbox) Disable() error

Disable

func (*VMailbox) Enable

func (m *VMailbox) Enable() error

Enable

func (*VMailbox) Export

func (vm *VMailbox) Export() string

Export

func (*VMailbox) Gid

func (vm *VMailbox) Gid() string

Gid

func (*VMailbox) Home

func (vm *VMailbox) Home() string

Home

func (*VMailbox) IsEnabled

func (mb *VMailbox) IsEnabled() bool

IsEnabled

func (*VMailbox) Password

func (vm *VMailbox) Password() string

Password

func (*VMailbox) PwType

func (vm *VMailbox) PwType() string

PwType

func (*VMailbox) Quota

func (vm *VMailbox) Quota() string

Quota only the value here. Caller has to wrap appropriately if going to Dovecot

func (*VMailbox) ResetQuota

func (m *VMailbox) ResetQuota() error

ResetQuota

func (*VMailbox) SetGid

func (m *VMailbox) SetGid(gid int64) error

SetGid

func (*VMailbox) SetHome

func (m *VMailbox) SetHome(home string) error

SetHome

func (*VMailbox) SetPassword

func (m *VMailbox) SetPassword(ps string) error

SetPassword

func (*VMailbox) SetPwType

func (m *VMailbox) SetPwType(pwType string) error

SetPwType

func (*VMailbox) SetQuota

func (m *VMailbox) SetQuota(quota string) error

SetQuota

func (*VMailbox) SetUid

func (m *VMailbox) SetUid(uid int64) error

SetUid

func (*VMailbox) String

func (vm *VMailbox) String() string

String FIX: should be Export()...

func (*VMailbox) Uid

func (vm *VMailbox) Uid() string

Uid

func (*VMailbox) User

func (vm *VMailbox) User() string

User

Jump to

Keyboard shortcuts

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