{"modulePath":"github.com/foxcpp/go-imap-sql","version":"v0.5.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package imapsql\n\n## Constants\n\n```go\nconst MailboxPathSep = \".\"\n```\n\n```go\nconst SchemaVersion = 5\n```\nSchemaVersion is incremented each time DB schema changes.\n\n```go\nconst VersionStr = \"0.4.0\"\n```\nVersionStr is a string value representing go-imap-sql version.\n\nMeant for debug logs, you may want to know which go-imap-sql version users have.\n\n## Variables\n\n```go\nvar (\n\tErrUserAlreadyExists = errors.New(\"imap: user already exists\")\n\tErrUserDoesntExists  = errors.New(\"imap: user doesn't exists\")\n)\n```\n\n```go\nvar ErrDeliveryInterrupted = errors.New(\"sql: delivery transaction interrupted, try again later\")\n```\n\n```go\nvar ErrUnsupportedSpecialAttr = errors.New(\"imap: special attribute is not supported\")\n```\n\n## Functions\n\n```go\nfunc RegisterCompressionAlgo(name string, algo CompressionAlgo)\n```\nRegisterCompressionAlgo adds a new compression algorithm to the registry so it can be used in Opts.CompressionAlgo.\n\n## Types\n\n```go\ntype Backend struct {\n\n\t// Opts structure used to construct this Backend object.\n\t//\n\t// For most cases it is safe to change options while backend is serving\n\t// requests.\n\t// Options that should NOT be changed while backend is processing commands:\n\t// - PRNG\n\t// - CompressAlgoParams\n\t// Changes for the following options have no effect after backend initialization:\n\t// - CompressAlgo\n\t// - ExclusiveLock\n\t// - CacheSize\n\t// - NoWAL\n\t// - UpdatesChan\n\tOpts Opts\n\n\t// database/sql.DB object created by New.\n\tDB *sql.DB\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc New(driver, dsn string, extStore ExternalStore, opts Opts) (*Backend, error)\n```\nNew creates new Backend instance using provided configuration.\n\ndriver and dsn arguments are passed directly to sql.Open.\n\nNote 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.\n\n```go\nfunc (b *Backend) Close() error\n```\n\n```go\nfunc (b *Backend) CreateMessageLimit() *uint32\n```\n\n```go\nfunc (b *Backend) CreateUser(username string) error\n```\nCreateUser creates user account.\n\n```go\nfunc (b *Backend) DeleteUser(username string) error\n```\nDeleteUser deleted user account with specified username.\n\nIt is error to delete account that doesn't exist, ErrUserDoesntExists will be returned in this case.\n\n```go\nfunc (b *Backend) EnableChildrenExt() bool\n```\nEnableChildrenExt enables generation of /HasChildren and /HasNoChildren attributes for mailboxes. It should be used only if server advertises CHILDREN extension support (see children subpackage).\n\n```go\nfunc (b *Backend) EnableSpecialUseExt() bool\n```\nEnableSpecialUseExt enables generation of special-use attributes for mailboxes. It should be used only if server advertises SPECIAL-USE extension support (see go-imap-specialuse).\n\n```go\nfunc (b *Backend) GetOrCreateUser(username string) (backend.User, error)\n```\nGetOrCreateUser is a convenience wrapper for GetUser and CreateUser.\n\nAll database operations are executed within one transaction so this method is atomic as defined by used RDBMS.\n\n```go\nfunc (b *Backend) GetUser(username string) (backend.User, error)\n```\nGetUser creates backend.User object for the user credentials.\n\n```go\nfunc (b *Backend) ListUsers() ([]string, error)\n```\nListUsers returns list of existing usernames.\n\nIt may return nil slice if no users are registered.\n\n```go\nfunc (b *Backend) Login(_ *imap.ConnInfo, username, password string) (backend.User, error)\n```\n\n```go\nfunc (b *Backend) NewDelivery() Delivery\n```\nNewDelivery creates a new state object for atomic delivery session.\n\nMessages added to the storage using that interface are added either to all recipients mailboxes or none or them.\n\nAlso use of this interface is more efficient than separate GetUser/GetMailbox/CreateMessage calls.\n\nNote that for performance reasons, the DB is not locked while the Delivery object exists, but only when BodyRaw/BodyParsed is called and until Abort/Commit is called. This means that the recipient mailbox can be deleted between AddRcpt and Body\\* calls. In that case, either Body\\* or Commit will return ErrDeliveryInterrupt. Sender should retry delivery after a short delay.\n\n```go\nfunc (b *Backend) SetMessageLimit(val *uint32) error\n```\nChange global APPEND limit, Opts.MaxMsgBytes.\n\nProvided to implement interfaces used by go-imap-backend-tests.\n\n```go\nfunc (b *Backend) SupportedThreadAlgorithms() []sortthread.ThreadAlgorithm\n```\n\n```go\nfunc (b *Backend) Updates() \u003c-chan backend.Update\n```\n\n```go\ntype Buffer interface {\n\tOpen() (io.ReadCloser, error)\n}\n```\nBuffer is the temporary storage for the message body.\n\n```go\ntype BufferedReadCloser struct {\n\t*bufio.Reader\n\tio.Closer\n}\n```\n\n```go\ntype CompressionAlgo interface {\n\t// WrapCompress wraps writer such that any data written to it\n\t// will be compressed using a certain compression algorithms.\n\t//\n\t// Close on returned writer should not close original writer, but\n\t// should flush any buffers if necessary.\n\t//\n\t// Algorithm settings can be customized by passing\n\t// implementation-defined params argument. Most algorithms\n\t// will include compression level here as a string. More complex\n\t// algorithms can use JSON to store complex settings. Empty string\n\t// means that the default parameters should be used.\n\tWrapCompress(w io.Writer, params string) (io.WriteCloser, error)\n\n\t// WrapDecompress wraps writer such that underlying stream should be decompressed\n\t// using a certain compression algorithms.\n\tWrapDecompress(r io.Reader) (io.Reader, error)\n}\n```\n\n```go\ntype Delivery struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc (d *Delivery) Abort() error\n```\n\n```go\nfunc (d *Delivery) AddRcpt(username string, userHeader textproto.Header) error\n```\nAddRcpt adds the recipient username/mailbox pair to the delivery.\n\nIf this function returns an error - further calls will still work correctly and there is no need to restart the delivery.\n\nThe specified user account and mailbox should exist at the time AddRcpt is called, but it can disappear before Body\\* call, in which case Delivery will be terminated with ErrDeliveryInterrupted error. See Backend.StartDelivery method documentation for details.\n\nFields from userHeader, if any, will be prepended to the message header \\*only\\* for that recipient. Use this to add Received and Delivered-To fields with recipient-specific information (e.g. its address).\n\n```go\nfunc (d *Delivery) BodyParsed(header textproto.Header, bodyLen int, body Buffer) error\n```\n\n```go\nfunc (d *Delivery) BodyRaw(message io.Reader) error\n```\nBodyRaw is convenience wrapper for BodyParsed. Use it only for most simple cases (e.g. for tests).\n\nYou want to use BodyParsed in most cases. It is much more efficient. BodyRaw reads the entire message into memory.\n\n```go\nfunc (d *Delivery) Commit() error\n```\nCommit finishes the delivery.\n\nIf this function returns no error - the message is successfully added to the mailbox of \\*all\\* recipients.\n\nAfter Commit or Abort is called, Delivery object can be reused as if it was just created.\n\n```go\nfunc (d *Delivery) Mailbox(name string) error\n```\nMailbox command changes the target mailbox for all recipients. It should be called before BodyParsed/BodyRaw.\n\nIf it is not called, it defaults to INBOX. If mailbox doesn't exist for some users - it will created.\n\n```go\nfunc (d *Delivery) SpecialMailbox(attribute, fallbackName string) error\n```\nSpecialMailbox is similar to Mailbox method but instead of looking up mailboxes by name it looks it up by the SPECIAL-USE attribute.\n\nIf no such mailbox exists for some user, it will be created with fallbackName and requested SPECIAL-USE attribute set.\n\nThe main use-case of this function is to reroute messages into Junk directory during multi-recipient delivery.\n\n```go\nfunc (d *Delivery) UserMailbox(username, mailbox string, flags []string)\n```\n\n```go\ntype DummyLogger struct{}\n```\n\n```go\nfunc (DummyLogger) Debugf(format string, v ...interface{})\n```\n\n```go\nfunc (DummyLogger) Debugln(v ...interface{})\n```\n\n```go\nfunc (DummyLogger) Printf(format string, v ...interface{})\n```\n\n```go\nfunc (DummyLogger) Println(v ...interface{})\n```\n\n```go\ntype ExtStoreObj interface {\n\tSync() error\n\tio.Reader\n\tio.Writer\n\tio.Closer\n}\n```\n\n```go\ntype ExternalError struct {\n\t// true if error was caused by an attempt to access non-existent key.\n\tNonExistent bool\n\n\tKey string\n\tErr error\n}\n```\n\n```go\nfunc (err ExternalError) Cause() error\n```\nCause implements Cause() for pkg/errors.\n\n```go\nfunc (err ExternalError) Error() string\n```\n\n```go\nfunc (err ExternalError) Unwrap() error\n```\nUnwrap implements Unwrap() for Go 1.13 'errors'.\n\n```go\ntype ExternalStore interface {\n\tCreate(key string) (ExtStoreObj, error)\n\n\t// Open returns the ExtStoreObj that reads the message body specified by\n\t// passed key.\n\t//\n\t// If no such message exists - ExternalError with NonExistent = true is\n\t// returned.\n\tOpen(key string) (ExtStoreObj, error)\n\n\t// Delete removes a set of keys from store. Non-existent keys are ignored.\n\tDelete(keys []string) error\n}\n```\nExternalStore is an interface used by go-imap-sql to store message bodies outside of main database.\n\n```go\ntype FSStore struct {\n\tRoot string\n}\n```\nFSStore struct represents directory on FS used to store message bodies.\n\nAlways use field names on initialization because new fields may be added without a major version change.\n\n```go\nfunc (s *FSStore) Create(key string) (ExtStoreObj, error)\n```\n\n```go\nfunc (s *FSStore) Delete(keys []string) error\n```\n\n```go\nfunc (s *FSStore) Open(key string) (ExtStoreObj, error)\n```\n\n```go\ntype Logger interface {\n\tPrintf(format string, v ...interface{})\n\tPrintln(v ...interface{})\n\tDebugf(format string, v ...interface{})\n\tDebugln(v ...interface{})\n}\n```\n\n```go\ntype Mailbox struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc (m *Mailbox) Check() error\n```\n\n```go\nfunc (m *Mailbox) CopyMessages(uid bool, seqset *imap.SeqSet, dest string) error\n```\n\n```go\nfunc (m *Mailbox) CreateMessage(flags []string, date time.Time, fullBody imap.Literal) error\n```\n\n```go\nfunc (m *Mailbox) CreateMessageLimit() *uint32\n```\n\n```go\nfunc (m *Mailbox) DelMessages(uid bool, seqset *imap.SeqSet) error\n```\n\n```go\nfunc (m *Mailbox) Expunge() error\n```\n\n```go\nfunc (m *Mailbox) Info() (*imap.MailboxInfo, error)\n```\n\n```go\nfunc (m *Mailbox) ListMessages(uid bool, seqset *imap.SeqSet, items []imap.FetchItem, ch chan\u003c- *imap.Message) error\n```\n\n```go\nfunc (m *Mailbox) MoveMessages(uid bool, seqset *imap.SeqSet, dest string) error\n```\n\n```go\nfunc (m *Mailbox) Name() string\n```\n\n```go\nfunc (m *Mailbox) SearchMessages(uid bool, criteria *imap.SearchCriteria) ([]uint32, error)\n```\n\n```go\nfunc (m *Mailbox) SetMessageLimit(val *uint32) error\n```\n\n```go\nfunc (m *Mailbox) SetSubscribed(subscribed bool) error\n```\n\n```go\nfunc (m *Mailbox) Sort(uid bool, sortCrit []sortthread.SortCriterion, searchCrit *imap.SearchCriteria) ([]uint32, error)\n```\n\n```go\nfunc (m *Mailbox) Status(items []imap.StatusItem) (*imap.MailboxStatus, error)\n```\n\n```go\nfunc (m *Mailbox) Thread(uid bool, threading sortthread.ThreadAlgorithm, searchCrit *imap.SearchCriteria) ([]*sortthread.Thread, error)\n```\n\n```go\nfunc (m *Mailbox) UpdateMessagesFlags(uid bool, seqset *imap.SeqSet, operation imap.FlagsOp, flags []string) error\n```\n\n```go\ntype Opts struct {\n\n\t// Maximum amount of bytes that backend will accept.\n\t// Intended for use with APPENDLIMIT extension.\n\t// nil value means no limit, 0 means zero limit (no new messages allowed)\n\tMaxMsgBytes *uint32\n\n\t// Controls when channel returned by Updates should be created.\n\t// If set to false - channel will be created before NewBackend returns.\n\t// If set to true - channel will be created upon first call to Updates.\n\t// Second is useful for tests that don't consume values from Updates\n\t// channel.\n\tLazyUpdatesInit bool\n\n\t// UpdatesChan allows to pass custom channel object used for unilateral\n\t// updates dispatching.\n\t//\n\t// You can use this to change default updates buffer size (20) or to split\n\t// initializaton into phases (which allows to break circular dependencies\n\t// if you need updates channel before database initialization).\n\tUpdatesChan chan backend.Update\n\n\t// Custom randomness source for UIDVALIDITY values generation.\n\tPRNG Rand\n\n\t// (SQLite3 only) Don't force WAL journaling mode.\n\tNoWAL bool\n\n\t// (SQLite3 only) Use different value for busy_timeout. Default is 50000.\n\t// To set to 0, use -1 (you probably don't want this).\n\tBusyTimeout int\n\n\t// (SQLite3 only) Use EXCLUSIVE locking mode.\n\tExclusiveLock bool\n\n\t// (SQLite3 only) Change page cache size. Positive value indicates cache\n\t// size in pages, negative in KiB. If set 0 - SQLite default will be used.\n\tCacheSize int\n\n\t// (SQLite3 only) Repack database file into minimal amount of disk space on\n\t// Close.\n\t// It runs VACUUM and PRAGMA wal_checkpoint(TRUNCATE).\n\t// Failures of these operations are ignored and don't affect return value\n\t// of Close.\n\tMinimizeOnClose bool\n\n\t// Compression algorithm to use for new messages. Empty string means no compression.\n\t//\n\t// Algorithms should be registered before using RegisterCompressionAlgo.\n\tCompressAlgo string\n\n\t// CompressAlgoParams is passed directly to compression algorithm without changes.\n\tCompressAlgoParams string\n\n\tLog Logger\n\t// contains filtered or unexported fields\n}\n```\nOpts structure specifies additional settings that may be set for backend.\n\nPlease use names to reference structure members on creation, fields may be reordered or added without major version increment.\n\n```go\ntype Rand interface {\n\tUint32() uint32\n}\n```\n\n```go\ntype SerializationError struct {\n\tErr error\n}\n```\n\n```go\nfunc (se SerializationError) Error() string\n```\n\n```go\nfunc (se SerializationError) Unwrap() error\n```\n\n```go\ntype User struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc (u *User) CreateMailbox(name string) error\n```\n\n```go\nfunc (u *User) CreateMailboxSpecial(name, specialUseAttr string) error\n```\nCreateMailboxSpecial creates a mailbox with SPECIAL-USE attribute set.\n\n```go\nfunc (u *User) CreateMessageLimit() *uint32\n```\n\n```go\nfunc (u *User) DeleteMailbox(name string) error\n```\n\n```go\nfunc (u *User) GetMailbox(name string) (backend.Mailbox, error)\n```\n\n```go\nfunc (u *User) ID() uint64\n```\n\n```go\nfunc (u *User) ListMailboxes(subscribed bool) ([]backend.Mailbox, error)\n```\n\n```go\nfunc (u *User) Logout() error\n```\n\n```go\nfunc (u *User) Namespaces() (personal, other, shared []namespace.Namespace, err error)\n```\n\n```go\nfunc (u *User) RenameMailbox(existingName, newName string) error\n```\n\n```go\nfunc (u *User) SetMessageLimit(val *uint32) error\n```\n\n```go\nfunc (u *User) Username() string\n```\n\n","path":"github.com/foxcpp/go-imap-sql","name":"imapsql","synopsis":"","isRedistributable":true}
