repository

package
v0.0.0-...-865c5c3 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2020 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnvelopeFromHeaders

func EnvelopeFromHeaders(headers Headers) *imap.Envelope

The message document "caches" message headers that are not only needed for the envelope, but sometimes requested by mail clients on their own. See https://github.com/foxcpp/go-imap-sql/blob/9d2bcb71fca8a3b467b5ae7be92b91656fa0c1e3/sql_fetch.go#L16 for some popular headers. This function converts some of these headers into an envelope

func HeaderAddressList

func HeaderAddressList(value string) ([]*imap.Address, error)

Types

type ChangeStreamEvent

type ChangeStreamEvent struct {
	Id            bson.M `bson:"_id"`
	OperationType OperationType
	FullDocument  *Message
	Ns            MessageUpdateNamespace
	To            *MessageUpdateNamespace
	DocumentKey   struct {
		Id string `bson:"_id"`
	}
	UpdateDescription *struct {
		UpdatedFields bson.M
		RemovedFields []string
	}
	ClusterTime time.Time
	// contains filtered or unexported fields
}

type Headers

type Headers map[string]string

type Mailbox

type Mailbox struct {
	Id          string `bson:"_id"`
	Name        string
	Owner       string
	NewMessages bool
	NextUid     uint32
	UidValidity uint32

	Permissions  map[string]Permission
	SubscribedBy []string
}

type MailboxRepository

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

func NewMailboxRepository

func NewMailboxRepository(conn *mongodbConnection.Connection) (*MailboxRepository, error)

func (*MailboxRepository) AllocateUid

func (repo *MailboxRepository) AllocateUid(name, owner string) (uint32, error)

func (*MailboxRepository) AllocateUidById

func (repo *MailboxRepository) AllocateUidById(mailboxId string) (uint32, error)

func (*MailboxRepository) ChangeMailboxName

func (repo *MailboxRepository) ChangeMailboxName(id, newName string) error

func (*MailboxRepository) CountUnseenMessages

func (i *MailboxRepository) CountUnseenMessages(id string) (int64, error)

func (*MailboxRepository) CreateMailbox

func (repo *MailboxRepository) CreateMailbox(name, owner string, access map[string]Permission) (*Mailbox, error)

func (*MailboxRepository) DeleteMailbox

func (repo *MailboxRepository) DeleteMailbox(name, owner string) error

func (*MailboxRepository) FindByNameAndOwner

func (repo *MailboxRepository) FindByNameAndOwner(name, owner string) (*Mailbox, error)

func (*MailboxRepository) FindChildren

func (repo *MailboxRepository) FindChildren(name, owner string) ([]Mailbox, error)

Determines if the mailbox has any children, this causes different behavior when renaming or deleting

if an error is returned, the boolean return value can NOT be used

func (*MailboxRepository) FindFirstUnseenMessageUid

func (i *MailboxRepository) FindFirstUnseenMessageUid(mailboxId string) (uint32, error)

func (*MailboxRepository) FindMailboxFlags

func (i *MailboxRepository) FindMailboxFlags(id string) (map[string]struct{}, error)

func (*MailboxRepository) FindUserMailboxes

func (repo *MailboxRepository) FindUserMailboxes(username string, subscribed bool) ([]Mailbox, error)

func (*MailboxRepository) SetSubscriptionByUser

func (repo *MailboxRepository) SetSubscriptionByUser(name, owner, user string, state bool) error

type Message

type Message struct {
	ID        string `bson:"_id"`
	MailboxId string `bson:"mailboxId"`
	Uid       uint32

	Header        Headers
	Flags         []string
	Recent        bool
	InternalDate  time.Time           `bson:"internalDate"`
	SentDate      time.Time           `bson:"sentDate"`
	BodyStructure *imap.BodyStructure `bson:"bodyStructure"`
	Size          uint32
}

func MessageFromBody

func MessageFromBody(flags []string, date time.Time, body io.Reader, bodySize uint32) (*Message, error)

Parses a imap literal into a partial message document Missing fields: - ID (auto assigned by the database) - Mailbox ID - Uid

type MessageRepository

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

func NewMessageRepository

func NewMessageRepository(conn *mongodbConnection.Connection) (*MessageRepository, error)

func (*MessageRepository) AcquireRecentMessage

func (repo *MessageRepository) AcquireRecentMessage(messageId string) (bool, error)

func (*MessageRepository) AcquireRecents

func (repo *MessageRepository) AcquireRecents(mailboxId string) (map[uint32]struct{}, error)

func (*MessageRepository) CopyMessage

func (repo *MessageRepository) CopyMessage(mailboxSource string, uid uint32, mailboxTarget string, targetUid uint32) (uint32, error)

func (*MessageRepository) CreateBodyWriter

func (repo *MessageRepository) CreateBodyWriter(mailboxId string, uid uint32) (io.WriteCloser, error)

Creates a io.Writer that points to the gridfs bucket for messages

func (*MessageRepository) ExpungeMailbox

func (repo *MessageRepository) ExpungeMailbox(mailboxId string) (int64, error)

func (*MessageRepository) FetchMessage

func (repo *MessageRepository) FetchMessage(mailboxId string, uid uint32, seqNum uint32, items []imap.FetchItem) (*imap.Message, error)

func (*MessageRepository) FetchUids

func (repo *MessageRepository) FetchUids(mailboxId string) ([]int, error)

func (*MessageRepository) FindMessage

func (repo *MessageRepository) FindMessage(criteria *imap.SearchCriteria, uidList []uint32, mailboxId string) ([]uint32, error)

func (*MessageRepository) Insert

func (repo *MessageRepository) Insert(message *Message) error

func (*MessageRepository) UpdateFlags

func (repo *MessageRepository) UpdateFlags(uid bool, set *imap.SeqSet, op imap.FlagsOp, flags []string, uids []uint32, mailboxId string) (map[uint32][]string, error)

func (*MessageRepository) WatchMailbox

func (repo *MessageRepository) WatchMailbox(ctx context.Context, mailboxId string) (<-chan ChangeStreamEvent, error)

Opens a change stream for a mailbox

type MessageUpdateNamespace

type MessageUpdateNamespace struct {
	Db   string
	Coll string
}

type OperationType

type OperationType string
const (
	OpInsert OperationType = "insert"
	OpDelete OperationType = "delete"
)

type Permission

type Permission string
const (
	READONLY  Permission = "r"
	READWRITE Permission = "rw"
)

type User

type User struct {
	Name             string   `bson:"_id"`
	Mails            []string `bson:"mails"`
	PrimaryMailboxId string
}

type UserRepository

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

func NewUserRepository

func NewUserRepository(conn *mongodbConnection.Connection) (*UserRepository, error)

func (*UserRepository) FindUserByMail

func (repo *UserRepository) FindUserByMail(mail string) (*User, error)

func (*UserRepository) FindUserByName

func (repo *UserRepository) FindUserByName(name string) (*User, error)

func (*UserRepository) ProvisionUserFromUserInfo

func (repo *UserRepository) ProvisionUserFromUserInfo(userInfo *ldap.UserInfo, mailboxRepo *MailboxRepository) (*User, error)

* Method that creates necessary documents for a ldap user if necessary. If the user already exists, bring existing data in line with ldap contents

Jump to

Keyboard shortcuts

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