neutron: github.com/emersion/neutron/backend Index | Files | Directories

package backend

import "github.com/emersion/neutron/backend"

Contains a generic interface for backends.

Index

Package Files

addresses.go attachments.go backend.go contacts.go conversations.go domains.go events.go keys.go labels.go messages.go send.go users.go

Constants

const (
    InboxLabel   string = "0"
    DraftLabel          = "1"
    SentLabel           = "2"
    TrashLabel          = "3"
    SpamLabel           = "4"
    ArchiveLabel        = "6"
    StarredLabel        = "10"
)

System labels

const (
    DraftType        int = 1
    SentType             = 2
    SentToMyselfType     = 3
)

Message types.

const (
    Unencrypted                    int = 0
    EndToEndEncryptedInternal          = 1
    EncryptedExternal                  = 2
    EndToEndEncryptedExternal          = 3
    StoredEncryptedExternal            = 4
    StoredEncrypted                    = 5
    EndToEndEncryptedExternalReply     = 6
    EncryptedPgp                       = 7
    EncryptedPgpMime                   = 8
)

Message encryption types.

const (
    InboxLocation   int = 0
    DraftLocation       = 1
    SentLocation        = 2
    TrashLocation       = 3
    SpamLocation        = 4
    ArchiveLocation     = 6
)

Messages locations.

const (
    RoleFreeUser int = iota
    RolePaidMember
    RolePaidAdmin
)
const PgpMessageType = "PGP MESSAGE"

func ArmorMessage Uses

func ArmorMessage(w io.Writer) (io.WriteCloser, error)

Encode a PGP message armor.

func IsEncrypted Uses

func IsEncrypted(data string) bool

Check if a string contains an encrypted message.

type Address Uses

type Address struct {
    ID          string
    DomainID    string
    Email       string
    Send        int
    Receive     int
    Status      int
    Type        int
    DisplayName string
    Signature   string
    MemberID    string
    MemberName  string

    HasKeys int
    Keys    []*Keypair
}

A user's address.

func (*Address) GetEmail Uses

func (a *Address) GetEmail() *Email

Get this address' email.

type AddressUpdate Uses

type AddressUpdate struct {
    Address     *Address
    Status      bool
    Type        bool
    DisplayName bool
    Signature   bool
}

func (*AddressUpdate) Apply Uses

func (update *AddressUpdate) Apply(address *Address)

type AddressesBackend Uses

type AddressesBackend interface {
    // Get a user's address.
    GetAddress(user, id string) (*Address, error)
    // List all addresses owned by a user.
    ListAddresses(user string) ([]*Address, error)
    // Create a new address.
    InsertAddress(user string, address *Address) (*Address, error)
    // Update an existing address.
    UpdateAddress(user string, update *AddressUpdate) (*Address, error)
    // Delete an address.
    DeleteAddress(user, id string) error
}

type Attachment Uses

type Attachment struct {
    ID         string
    MessageID  string `json:",omitempty"`
    Name       string
    Size       int
    MIMEType   string
    KeyPackets string `json:",omitempty"`
    Headers    textproto.MIMEHeader
    DataPacket string `json:",omitempty"` // TODO: remove this from here
}

An attachment.

type AttachmentKey Uses

type AttachmentKey struct {
    ID   string
    Key  string
    Algo string
}

func (*AttachmentKey) Decrypt Uses

func (at *AttachmentKey) Decrypt(encrypted []byte) (decrypted []byte, err error)

Decrypt a symmetrically encrypted packet with this key.

type AttachmentsBackend Uses

type AttachmentsBackend interface {
    // List all message's attachments.
    ListAttachments(user, msg string) ([]*Attachment, error)
    // Get an attachment content.
    ReadAttachment(user, id string) (*Attachment, []byte, error)
    // Insert a new attachment.
    InsertAttachment(user string, attachment *Attachment, contents []byte) (*Attachment, error)
    // Delete an attachment.
    DeleteAttachment(user, id string) error
}

Stores attachments.

type Backend Uses

type Backend struct {
    ContactsBackend
    LabelsBackend
    ConversationsBackend
    SendBackend
    DomainsBackend
    EventsBackend
    UsersBackend
    AddressesBackend
    KeysBackend
    AttachmentsBackend
}

A backend takes care of storing all mailbox data.

func New Uses

func New() *Backend

func (*Backend) Set Uses

func (b *Backend) Set(backends ...interface{})

Set one or some of this backend's components.

type Contact Uses

type Contact struct {
    ID    string
    Name  string
    Email string
}

A contact is an entry in the user's address book.

type ContactUpdate Uses

type ContactUpdate struct {
    Contact *Contact
    Name    bool
    Email   bool
}

A request to update a contact. Fields set to true will be updated with values in Contact.

func (*ContactUpdate) Apply Uses

func (update *ContactUpdate) Apply(contact *Contact)

Apply this update on a contact.

type ContactsBackend Uses

type ContactsBackend interface {
    // List all user's contacts.
    ListContacts(user string) ([]*Contact, error)
    // Insert a new contact.
    InsertContact(user string, contact *Contact) (*Contact, error)
    // Update an existing contact.
    UpdateContact(user string, update *ContactUpdate) (*Contact, error)
    // Delete a contact.
    DeleteContact(user, id string) error
    // Delete all contacts of a specific user.
    DeleteAllContacts(user string) error
}

Stores contacts data.

type Conversation Uses

type Conversation struct {
    ID             string
    Order          int
    Subject        string
    Senders        []*Email
    Recipients     []*Email
    NumMessages    int
    NumUnread      int
    NumAttachments int
    ExpirationTime int
    TotalSize      int
    Time           int64
    LabelIDs       []string
    Labels         []*ConversationLabel
}

A conversation is a sequence of messages.

type ConversationLabel Uses

type ConversationLabel struct {
    ID          string
    Count       int
    NumMessages int
    NumUnread   int
}

Contains messages counts by labels.

type ConversationsBackend Uses

type ConversationsBackend interface {
    MessagesBackend

    // List all messages belonging to a conversation.
    ListConversationMessages(user, id string) (msgs []*Message, err error)

    // Get a specific conversation.
    GetConversation(user, id string) (conv *Conversation, err error)
    // List all user's conversations. A message filter can be provided.
    ListConversations(user string, filter *MessagesFilter) ([]*Conversation, int, error)
    // Count all user's conversations by label.
    CountConversations(user string) ([]*MessagesCount, error)
    // Permanently delete a conversation.
    DeleteConversation(user, id string) error
}

Stores conversations data.

type Domain Uses

type Domain struct {
    ID         string
    DomainName string

    State       int
    VerifyState int
    MxState     int
    SpfState    int
    DkimState   int
    DmarcState  int

    Addresses []*Address
}

A domain name.

type DomainsBackend Uses

type DomainsBackend interface {
    // List all domains.
    ListDomains() ([]*Domain, error)
    // Get a domain.
    GetDomain(id string) (*Domain, error)
    // Get the domain which has the specified name.
    GetDomainByName(name string) (*Domain, error)
    // Insert a new domain.
    InsertDomain(domain *Domain) (*Domain, error)
}

Stores domains data.

type Email Uses

type Email struct {
    Name    string
    Address string
}

An email contains an address and a name.

type Event Uses

type Event struct {
    ID  string `json:"EventID"`

    Refresh int
    Reload  int
    Notices []string

    // See https://github.com/ProtonMail/WebClient/blob/master/src/app/services/event.js#L274
    Messages           []*EventMessageDelta      `json:",omitempty"`
    Conversations      []*EventConversationDelta `json:",omitempty"`
    MessageCounts      []*MessagesCount          `json:",omitempty"`
    ConversationCounts []*MessagesCount          `json:",omitempty"`
    Total              *MessagesTotal            `json:",omitempty"`
    Unread             *MessagesTotal            `json:",omitempty"`
    Labels             []*EventLabelDelta        `json:",omitempty"`
    Contacts           []*EventContactDelta      `json:",omitempty"`
    User               *User                     `json:",omitempty"`

    UsedSpace int `json:",omitempty"`
}

func NewContactDeltaEvent Uses

func NewContactDeltaEvent(id string, action EventAction, contact *Contact) *Event

func NewConversationDeltaEvent Uses

func NewConversationDeltaEvent(id string, action EventAction, conv *Conversation) *Event

func NewLabelDeltaEvent Uses

func NewLabelDeltaEvent(id string, action EventAction, label *Label) *Event

func NewMessageDeltaEvent Uses

func NewMessageDeltaEvent(id string, action EventAction, msg *Message) *Event

func NewUserEvent Uses

func NewUserEvent(user *User) *Event

type EventAction Uses

type EventAction int
const (
    EventDelete EventAction = iota
    EventCreate
    EventUpdate
)

type EventContactDelta Uses

type EventContactDelta struct {
    EventDelta
    Contact *Contact
}

type EventConversationDelta Uses

type EventConversationDelta struct {
    EventDelta
    Conversation *Conversation
}

type EventDelta Uses

type EventDelta struct {
    ID     string
    Action EventAction
}

type EventLabelDelta Uses

type EventLabelDelta struct {
    EventDelta
    Label *Label
}

type EventMessageDelta Uses

type EventMessageDelta struct {
    EventDelta
    Message *Message
}

type EventsBackend Uses

type EventsBackend interface {
    // Insert a new event.
    InsertEvent(user string, event *Event) error
    // Get the last event.
    GetLastEvent(user string) (*Event, error)
    // Get the sum of all events after a specific one.
    GetEventsAfter(user, id string) (*Event, error)
    // Delete all user's events. This happens when the user is no longer connected.
    DeleteAllEvents(user string) error
}

Stores events data.

type Keypair Uses

type Keypair struct {
    ID          string
    PublicKey   string
    PrivateKey  string
    Fingerprint string // TODO: populate this field
}

A keypair contains a private and a public key.

func NewKeypair Uses

func NewKeypair(pub, priv string) *Keypair

Create a new keypair.

func (*Keypair) Encrypt Uses

func (kp *Keypair) Encrypt(data string) (encrypted string, err error)

Encrypt a message to the keypair's owner.

type KeysBackend Uses

type KeysBackend interface {
    // Get a public key for a user.
    // If no key is available, an empty string and no error must be returned.
    GetPublicKey(email string) (string, error)
    // Get a keypair for a user. Contains public & private key.
    GetKeypair(email string) (*Keypair, error)
    // Create a new keypair.
    InsertKeypair(email string, keypair *Keypair) (*Keypair, error)
    // Update a user's private key.
    // PublicKey must be updated only if it isn't empty.
    UpdateKeypair(email string, keypair *Keypair) (*Keypair, error)
}

type Label Uses

type Label struct {
    ID        string
    Name      string
    Color     string
    Display   int
    Type      LabelType
    Exclusive int
    Order     int
}

A message label.

type LabelTotal Uses

type LabelTotal struct {
    LabelID string
    Count   int
}

type LabelType Uses

type LabelType int
const (
    LabelMessage LabelType = 1
    LabelContact
)

type LabelUpdate Uses

type LabelUpdate struct {
    Label   *Label
    Name    bool
    Color   bool
    Display bool
    Order   bool
}

A request to update a label. Fields set to true will be updated with values in Label.

func (*LabelUpdate) Apply Uses

func (update *LabelUpdate) Apply(label *Label)

Apply this update on a label.

type LabelsBackend Uses

type LabelsBackend interface {
    // List all user's labels.
    ListLabels(user string) ([]*Label, error)
    // Insert a new label.
    InsertLabel(user string, label *Label) (*Label, error)
    // Update an existing label.
    UpdateLabel(user string, update *LabelUpdate) (*Label, error)
    // Delete a label.
    DeleteLabel(user, id string) error
}

Stores labels data.

type LabelsOperation Uses

type LabelsOperation int

The operation to apply to labels.

const (
    KeepLabels    LabelsOperation = iota // Do nothing
    ReplaceLabels                        // Replace current labels with new ones
    AddLabels                            // Add new labels to current ones
    RemoveLabels                         // Remove specified labels from current ones
)

type LocationTotal Uses

type LocationTotal struct {
    Location int
    Count    int
}

type Message Uses

type Message struct {
    ID             string
    Order          int
    ConversationID string
    Subject        string
    IsRead         int
    Type           int
    SenderAddress  string
    SenderName     string
    Sender         *Email
    ToList         []*Email
    CCList         []*Email
    BCCList        []*Email
    Time           int64
    Size           int
    HasAttachment  int
    NumAttachments int
    IsEncrypted    int
    ExpirationTime int
    IsReplied      int
    IsRepliedAll   int
    IsForwarded    int
    AddressID      string
    Body           string `json:",omitempty"`
    Header         string `json:",omitempty"`
    ReplyTo        *Email
    Attachments    []*Attachment
    Starred        int
    Location       int
    LabelIDs       []string
}

A message.

type MessagePackage Uses

type MessagePackage struct {
    Address    string
    Type       int
    Body       string
    KeyPackets []string
}

type MessageUpdate Uses

type MessageUpdate struct {
    Message   *Message
    ToList    bool
    CCList    bool
    BCCList   bool
    Subject   bool
    IsRead    bool
    Type      bool
    AddressID bool
    Body      bool
    Time      bool
    Starred   bool
    LabelIDs  LabelsOperation
}

A request to update a message. Fields set to true will be updated with values in Message.

func (*MessageUpdate) Apply Uses

func (update *MessageUpdate) Apply(msg *Message)

Apply this update on a message.

type MessagesBackend Uses

type MessagesBackend interface {
    // Get a message.
    GetMessage(user, id string) (*Message, error)
    // List all user's messages. A message filter can be provided.
    ListMessages(user string, filter *MessagesFilter) ([]*Message, int, error)
    // Count all user's messages by label.
    CountMessages(user string) ([]*MessagesCount, error)
    // Insert a new message.
    InsertMessage(user string, msg *Message) (*Message, error)
    // Update an existing message.
    UpdateMessage(user string, update *MessageUpdate) (*Message, error)
    // Permanently delete a message.
    DeleteMessage(user, id string) error
}

Stores messages data.

type MessagesCount Uses

type MessagesCount struct {
    LabelID string
    Total   int
    Unread  int
}

Contains message counts for one label.

type MessagesFilter Uses

type MessagesFilter struct {
    Limit       int
    Page        int
    Label       string
    Keyword     string
    Address     string // Address ID
    Attachments bool
    From        string
    To          string
    Begin       int64 // Timestamp
    End         int64 // Timestamp
    Sort        string
    Desc        bool
}

Contains fields to filter messages.

type MessagesTotal Uses

type MessagesTotal struct {
    Locations []*LocationTotal
    Labels    []*LabelTotal
    Starred   int
}

Contains a summary of messages counts per location and label.

func MessagesTotalFromCounts Uses

func MessagesTotalFromCounts(counts []*MessagesCount) (totals *MessagesTotal, unread *MessagesTotal)

type OutgoingAttachment Uses

type OutgoingAttachment struct {
    *Attachment

    Data []byte
}

An attachment that is going to be sent.

type OutgoingMessage Uses

type OutgoingMessage struct {
    *Message
    *MessagePackage

    InReplyTo   string
    References  string
    Attachments []*OutgoingAttachment
}

A message that is going to be sent. Message.Body MUST be ignored, MessagePackage.Body MUST be used instead. The recipient is specified in MessagePackage.Address.

type SendBackend Uses

type SendBackend interface {
    // Send a message to an e-mail address.
    SendMessage(user string, msg *OutgoingMessage) error
}

Sends messages to email addresses.

type User Uses

type User struct {
    ID                string
    Name              string
    NotificationEmail string
    Signature         string
    NumMessagePerPage int
    UsedSpace         int
    Notify            int
    AutoSaveContacts  int
    Language          string
    LogAuth           int
    ComposerMode      int
    MessageButtons    int
    ShowImages        int
    ShowEmbedded      int
    ViewMode          int
    ViewLayout        int
    SwipeLeft         int
    SwipeRight        int
    Theme             string
    Currency          string
    Credit            int
    InvoiceText       string
    AlsoArchive       int
    Hotkeys           int
    PMSignature       int
    TwoFactor         int
    PasswordReset     int
    PasswordMode      int
    News              int
    DisplayName       string
    MaxSpace          int
    MaxUpload         int
    Role              int
    Private           int
    Subscribed        int
    Deliquent         int
    VPN               interface{}
    Addresses         []*Address
    Keys              []*Keypair
}

A user.

func (*User) GetMainAddress Uses

func (u *User) GetMainAddress() *Address

type UserUpdate Uses

type UserUpdate struct {
    User             *User
    DisplayName      bool
    Signature        bool
    AutoSaveContacts bool
    ShowImages       bool
    ComposerMode     bool
    ViewLayout       bool
    MessageButtons   bool
    Theme            bool
}

A request to update a user. Fields set to true will be updated with values in User.

func (*UserUpdate) Apply Uses

func (update *UserUpdate) Apply(user *User)

Apply this update on a user.

type UsersBackend Uses

type UsersBackend interface {
    // Check if a username is available.
    IsUsernameAvailable(username string) (bool, error)
    // Get a user.
    GetUser(id string) (*User, error)
    // Check if the provided username and password are correct
    Auth(username, password string) (*User, error)
    // Insert a new user. Returns the newly created user.
    InsertUser(user *User, password string) (*User, error)
    // Update an existing user.
    UpdateUser(update *UserUpdate) error
    // Update a user's password.
    UpdateUserPassword(id, current, new string) error
}

Directories

PathSynopsis
diskStores data in files on disk.
eventsProvides backends to trigger events.
imapStores messages on an IMAP server.
memoryStores data in memory.
smtpSends messages with a SMTP server.
utilBackend utilities.
util/textprotoProvides utilities to parse and format messages.
util/textproto/chunksplitProvides a chunk splitter.

Package backend imports 10 packages (graph) and is imported by 9 packages. Updated 2018-01-08. Refresh now. Tools for package owners.