Documentation
¶
Index ¶
- Constants
- Variables
- type Backend
- func (b *Backend) CheckPlain(username, password string) bool
- func (b *Backend) Close() error
- func (b *Backend) CreateMessageLimit() *uint32
- func (b *Backend) CreateUser(username, password string) error
- func (b *Backend) CreateUserNoPass(username string) error
- func (b *Backend) CreateUserWithHash(username, hashAlgo, password string) error
- func (b *Backend) DeleteUser(username string) error
- func (b *Backend) EnableChildrenExt() bool
- func (b *Backend) EnableHashAlgo(name string, hashFunc func(saltedPass []byte) []byte, ...)
- func (b *Backend) GetOrCreateUser(username string) (backend.User, error)
- func (b *Backend) GetUser(username string) (backend.User, error)
- func (b *Backend) ListUsers() ([]string, error)
- func (b *Backend) Login(_ *imap.ConnInfo, username, password string) (backend.User, error)
- func (b *Backend) ResetPassword(username string) error
- func (b *Backend) SetMessageLimit(val *uint32) error
- func (b *Backend) SetUserPassword(username, newPassword string) error
- func (b *Backend) SetUserPasswordWithHash(hashAlgo, username, newPassword string) error
- func (b *Backend) Updates() <-chan backend.Update
- func (b *Backend) UserCreds(username string) (id uint64, hashAlgo string, passHash []byte, passSalt []byte, err error)
- type ExternalStore
- type Mailbox
- func (m *Mailbox) Check() error
- func (m *Mailbox) CopyMessages(uid bool, seqset *imap.SeqSet, dest string) error
- func (m *Mailbox) CreateMessage(flags []string, date time.Time, fullBody imap.Literal) error
- func (m *Mailbox) CreateMessageLimit() *uint32
- func (m *Mailbox) DelMessages(uid bool, seqset *imap.SeqSet) error
- func (m *Mailbox) Expunge() error
- func (m *Mailbox) Info() (*imap.MailboxInfo, error)
- func (m *Mailbox) ListMessages(uid bool, seqset *imap.SeqSet, items []imap.FetchItem, ch chan<- *imap.Message) error
- func (m *Mailbox) MoveMessages(uid bool, seqset *imap.SeqSet, dest string) error
- func (m *Mailbox) Name() string
- func (m *Mailbox) SearchMessages(uid bool, criteria *imap.SearchCriteria) ([]uint32, error)
- func (m *Mailbox) SetMessageLimit(val *uint32) error
- func (m *Mailbox) SetSubscribed(subscribed bool) error
- func (m *Mailbox) Status(items []imap.StatusItem) (*imap.MailboxStatus, error)
- func (m *Mailbox) UpdateMessagesFlags(uid bool, seqset *imap.SeqSet, operation imap.FlagsOp, flags []string) error
- type Opts
- type Rand
- type User
- func (u *User) CreateMailbox(name string) error
- func (u *User) CreateMessageLimit() *uint32
- func (u *User) DeleteMailbox(name string) error
- func (u *User) GetMailbox(name string) (backend.Mailbox, error)
- func (u *User) ID() uint64
- func (u *User) ListMailboxes(subscribed bool) ([]backend.Mailbox, error)
- func (u *User) Logout() error
- func (u *User) RenameMailbox(existingName, newName string) error
- func (u *User) SetMessageLimit(val *uint32) error
- func (u *User) Username() string
Constants ¶
const MailboxPathSep = "."
const SchemaVersion = 3
SchemaVersion is incremented each time DB schema changes.
const VersionStr = "0.2"
VersionStr is a string value representing go-imap-sql version.
Meant for debug logs, you may want to know which go-imap-sql version users have. See below for per-component variants.
Variables ¶
var ( ErrUserAlreadyExists = errors.New("imap: user already exists") ErrUserDoesntExists = errors.New("imap: user doesn't exists") )
Functions ¶
This section is empty.
Types ¶
type Backend ¶ added in v0.2.0
type Backend struct { // Opts structure used to construct this Backend object. // // For most cases it is safe to change options while backend is serving // requests. // Options that should NOT be changed while backend is processing commands: // - ExternalStore // - PRNG // Changes for the following options have no effect after backend initialization: // - AllowSchemaUpgrade // - ExclusiveLock // - CacheSize // - NoWAL // - UpdatesChan Opts Opts // database/sql.DB object created by New. DB *sql.DB // contains filtered or unexported fields }
func New ¶ added in v0.2.0
New creates new Backend instance using provided configuration.
driver and dsn arguments are passed directly to sql.Open.
Note that it is not safe to create multiple Backend instances working with the single database as they need to keep some state synchronized and there is no measures for this implemented in go-imap-sql.
func (*Backend) CheckPlain ¶ added in v0.2.0
CheckPlain checks the credentials of the user account.
func (*Backend) CreateMessageLimit ¶ added in v0.2.0
func (*Backend) CreateUser ¶ added in v0.2.0
CreateUser creates user account with specified credentials.
This method can fail if used crypto/rand fails to create enough entropy. It is error to create account with username that already exists. ErrUserAlreadyExists will be returned in this case.
func (*Backend) CreateUserNoPass ¶ added in v0.3.0
CreateUserNoPass creates new user account without a password set.
It will be unable to log in until SetUserPassword is called for it.
func (*Backend) CreateUserWithHash ¶ added in v0.3.0
func (*Backend) DeleteUser ¶ added in v0.2.0
DeleteUser deleted user account with specified username.
It is error to delete account that doesn't exist, ErrUserDoesntExists will be returned in this case.
func (*Backend) EnableChildrenExt ¶ added in v0.2.0
EnableChildrenExt enables generation of /HasChildren and /HasNoChildren attributes for mailboxes. It should be used only if server advertises CHILDREN extension support (see children subpackage).
func (*Backend) EnableHashAlgo ¶ added in v0.3.0
func (b *Backend) EnableHashAlgo(name string, hashFunc func(saltedPass []byte) []byte, checkFunc func(saltedPass, hash []byte) bool)
EnableHashAlgo enables support for additional hash algorithm using two provided callback functions.
Note that generated hash should be ASCII-encoded.
func (*Backend) GetOrCreateUser ¶ added in v0.2.0
GetOrCreateUser is a convenience wrapper for GetUser and CreateUser.
Users are created with invalid password such that CheckPlain and Login will always return "invalid credentials" error.
All database operations are executed within one transaction so this method is atomic as defined by used RDBMS.
func (*Backend) GetUser ¶ added in v0.2.0
GetUser creates backend.User object without for the user credentials.
If you want to check user credentials, you should use Login or CheckPlain.
func (*Backend) ListUsers ¶ added in v0.2.0
ListUsers returns list of existing usernames.
It may return nil slice if no users are registered.
func (*Backend) ResetPassword ¶ added in v0.3.0
ResetPassword sets user account password to invalid value such that Login and CheckPlain will always return "invalid credentials" error.
func (*Backend) SetMessageLimit ¶ added in v0.2.0
Change global APPEND limit, Opts.MaxMsgBytes.
Provided to implement interfaces used by go-imap-backend-tests.
func (*Backend) SetUserPassword ¶ added in v0.2.0
SetUserPassword changes password associated with account with specified username.
Opts.DefaultHashAlgo is used for password hashing. This method can fail if crypto/rand fails to generate enough entropy.
It is error to change password for account that doesn't exist, ErrUserDoesntExists will be returned in this case.
func (*Backend) SetUserPasswordWithHash ¶ added in v0.3.0
SetUserPasswordWithHash is a version of SetUserPassword that allows to specify any supported hash algorithm instead of Opts.DefaultHashAlgo.
func (*Backend) UserCreds ¶ added in v0.2.0
func (b *Backend) UserCreds(username string) (id uint64, hashAlgo string, passHash []byte, passSalt []byte, err error)
UserCreds returns internal identifier and credentials for user named username.
It is exported for use by extensions and is not considered part of the public API. Hence it can be changed between minor releases.
type ExternalStore ¶ added in v0.2.0
type ExternalStore interface { Create(key string) (io.WriteCloser, error) Open(key string) (io.ReadCloser, error) Delete(keys []string) error }
ExternalStore is an interface used by go-imap-sql to store message bodies outside of main database.
type Mailbox ¶ added in v0.2.0
type Mailbox struct {
// contains filtered or unexported fields
}
func (*Mailbox) CopyMessages ¶ added in v0.2.0
func (*Mailbox) CreateMessage ¶ added in v0.2.0
func (*Mailbox) CreateMessageLimit ¶ added in v0.2.0
func (*Mailbox) DelMessages ¶ added in v0.2.0
func (*Mailbox) ListMessages ¶ added in v0.2.0
func (*Mailbox) MoveMessages ¶ added in v0.2.0
func (*Mailbox) SearchMessages ¶ added in v0.2.0
func (*Mailbox) SetMessageLimit ¶ added in v0.2.0
func (*Mailbox) SetSubscribed ¶ added in v0.2.0
type Opts ¶ added in v0.2.0
type Opts struct { // Maximum amount of bytes that backend will accept. // Intended for use with APPENDLIMIT extension. // nil value means no limit, 0 means zero limit (no new messages allowed) MaxMsgBytes *uint32 // Controls when channel returned by Updates should be created. // If set to false - channel will be created before NewBackend returns. // If set to true - channel will be created upon first call to Updates. // Second is useful for tests that don't consume values from Updates // channel. LazyUpdatesInit bool // UpdatesChan allows to pass custom channel object used for unilateral // updates dispatching. // // You can use this to change default updates buffer size (20) or to split // initializaton into phases (which allows to break circular dependencies // if you need updates channel before database initialization). UpdatesChan chan backend.Update // Custom randomness source for UIDVALIDITY values generation. PRNG Rand // (SQLite3 only) Don't force WAL journaling mode. NoWAL bool // (SQLite3 only) Use different value for busy_timeout. Default is 50000. // To set to 0, use -1 (you probably don't want this). BusyTimeout int // (SQLite3 only) Use EXCLUSIVE locking mode. ExclusiveLock bool // (SQLite3 only) Change page cache size. Positive value indicates cache // size in pages, negative in KiB. If set 0 - SQLite default will be used. CacheSize int // (SQLite3 only) Repack database file into minimal amount of disk space on // Close. // It runs VACUUM and PRAGMA wal_checkpoint(TRUNCATE). // Failures of these operations are ignored and don't affect return value // of Close. MinimizeOnClose bool // External storage to use to store message bodies. If specified - all new messages // will be saved to it. However, already existing messages stored in DB // directly will not be moved. ExternalStore ExternalStore // Automatically update database schema on imapsql.New. AllowSchemaUpgrade bool // Hash algorithm to use for authentication passwords when no algorithm is // explicitly specified. // "sha3-512" and "bcrypt" are supported out of the box. "bcrypt" is used // by default. // Support for aditional algoritms can be enabled using EnableHashAlgo. DefaultHashAlgo string // Bcrypt cost value to use when computing password hashes. // Default is 10. Can't be smaller than 4, can't be bigger than 31. // // It is safe to change it, existing records will not be affected. BcryptCost int // contains filtered or unexported fields }
Opts structure specifies additional settings that may be set for backend.
Please use names to reference structure members on creation, fields may be reordered or added without major version increment.
type User ¶ added in v0.2.0
type User struct {
// contains filtered or unexported fields
}