storage

package
v1.17.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MIT Imports: 39 Imported by: 0

Documentation

Overview

Package storage handles all database actions

Index

Constants

This section is empty.

Variables

View Source
var (

	// StatsDeleted for counting the number of messages deleted
	StatsDeleted float64
)

Functions

func AddMessageTag added in v1.12.0

func AddMessageTag(id, name string) error

AddMessageTag adds a tag to a message

func BroadcastMailboxStats

func BroadcastMailboxStats()

BroadcastMailboxStats broadcasts the total number of messages displayed to the web UI, as well as the total unread messages. The lookup is very fast (< 10ms / 100k messages under load). Rate limited to 4x per second.

func Close

func Close()

Close will close the database, and delete if temporary

func CountRead

func CountRead() float64

CountRead returns the number of emails in the database that are read.

func CountTotal

func CountTotal() float64

CountTotal returns the number of emails in the database

func CountUnread

func CountUnread() float64

CountUnread returns the number of emails in the database that are unread.

func DbSize added in v1.16.0

func DbSize() float64

DbSize returns the size of the SQLite database.

func DeleteAllMessageTags added in v1.12.0

func DeleteAllMessageTags(id string) error

DeleteAllMessageTags deleted all tags from a message

func DeleteAllMessages

func DeleteAllMessages() error

DeleteAllMessages will delete all messages from a mailbox

func DeleteMessageTag added in v1.12.0

func DeleteMessageTag(id, name string) error

DeleteMessageTag deleted a tag from a message

func DeleteMessages added in v1.16.0

func DeleteMessages(ids []string) error

DeleteMessages deletes one or more messages in bulk

func DeleteSearch

func DeleteSearch(search, timezone string) error

DeleteSearch will delete all messages for search terms. The search is broken up by segments (exact phrases can be quoted), and interprets specific terms such as: is:read, is:unread, has:attachment, to:<term>, from:<term> & subject:<term> Negative searches also also included by prefixing the search term with a `-` or `!`

func GetAllTags

func GetAllTags() []string

GetAllTags returns all used tags

func GetAllTagsCount added in v1.12.0

func GetAllTagsCount() map[string]int64

GetAllTagsCount returns all used tags with their total messages

func GetAttachmentPart

func GetAttachmentPart(id, partID string) (*enmime.Part, error)

GetAttachmentPart returns an *enmime.Part (attachment or inline) from a message

func GetMessageRaw

func GetMessageRaw(id string) ([]byte, error)

GetMessageRaw returns an []byte of the full message

func InitDB

func InitDB() error

InitDB will initialise the database

func IsUnread

func IsUnread(id string) bool

IsUnread returns whether a message is unread or not.

func LatestID added in v1.11.0

func LatestID(r *http.Request) (string, error)

LatestID returns the latest message ID

If a query argument is set in the request the function will return the latest message matching the search

func MarkAllRead

func MarkAllRead() error

MarkAllRead will mark all messages as read

func MarkAllUnread

func MarkAllUnread() error

MarkAllUnread will mark all messages as unread

func MarkRead

func MarkRead(id string) error

MarkRead will mark a message as read

func MarkUnread

func MarkUnread(id string) error

MarkUnread will mark a message as unread

func MessageIDExists

func MessageIDExists(id string) bool

MessageIDExists checks whether a Message-ID exists in the DB

func Ping added in v1.15.1

func Ping() error

Ping the database connection and return an error if unsuccessful

func ReindexAll added in v1.9.5

func ReindexAll()

ReindexAll will regenerate the search text and snippet for a message and update the database.

func SetMessageTags added in v1.12.0

func SetMessageTags(id string, tags []string) error

SetMessageTags will set the tags for a given database ID

func SettingGet added in v1.14.0

func SettingGet(k string) string

SettingGet returns a setting string value, blank is it does not exist

func SettingPut added in v1.14.0

func SettingPut(k, v string) error

SettingPut sets a setting string value, inserting if new

func Store

func Store(body *[]byte) (string, error)

Store will save an email to the database tables. Returns the database ID of the saved message.

Types

type Attachment

type Attachment struct {
	// Attachment part ID
	PartID string
	// File name
	FileName string
	// Content type
	ContentType string
	// Content ID
	ContentID string
	// Size in bytes
	Size float64
}

Attachment struct for inline and attachments

swagger:model Attachment

func AttachmentSummary

func AttachmentSummary(a *enmime.Part) Attachment

AttachmentSummary returns a summary of the attachment without any binary data

type DBMailSummary

type DBMailSummary struct {
	From    *mail.Address
	To      []*mail.Address
	Cc      []*mail.Address
	Bcc     []*mail.Address
	ReplyTo []*mail.Address
}

DBMailSummary struct for storing mail summary

type ListUnsubscribe added in v1.13.0

type ListUnsubscribe struct {
	// List-Unsubscribe header value
	Header string
	// Detected links, maximum one email and one HTTP(S)
	Links []string
	// Validation errors if any
	Errors string
	// List-Unsubscribe-Post value if set
	HeaderPost string
}

ListUnsubscribe contains a summary of List-Unsubscribe & List-Unsubscribe-Post headers including validation of the link structure

type MailboxStats

type MailboxStats struct {
	Total  float64
	Unread float64
	Tags   []string
}

MailboxStats struct for quick mailbox total/read lookups

func StatsGet

func StatsGet() MailboxStats

StatsGet returns the total/unread statistics for a mailbox

type Message

type Message struct {
	// Database ID
	ID string
	// Message ID
	MessageID string
	// From address
	From *mail.Address
	// To addresses
	To []*mail.Address
	// Cc addresses
	Cc []*mail.Address
	// Bcc addresses
	Bcc []*mail.Address
	// ReplyTo addresses
	ReplyTo []*mail.Address
	// Return-Path
	ReturnPath string
	// Message subject
	Subject string
	// List-Unsubscribe header information
	// swagger:ignore
	ListUnsubscribe ListUnsubscribe
	// Message date if set, else date received
	Date time.Time
	// Message tags
	Tags []string
	// Message body text
	Text string
	// Message body HTML
	HTML string
	// Message size in bytes
	Size float64
	// Inline message attachments
	Inline []Attachment
	// Message attachments
	Attachments []Attachment
}

Message data excluding physical attachments

swagger:model Message

func GetMessage

func GetMessage(id string) (*Message, error)

GetMessage returns a Message generated from the mailbox_data collection. If the message lacks a date header, then the received datetime is used.

type MessageSummary

type MessageSummary struct {
	// Database ID
	ID string
	// Message ID
	MessageID string
	// Read status
	Read bool
	// From address
	From *mail.Address
	// To address
	To []*mail.Address
	// Cc addresses
	Cc []*mail.Address
	// Bcc addresses
	Bcc []*mail.Address
	// Reply-To address
	ReplyTo []*mail.Address
	// Email subject
	Subject string
	// Created time
	Created time.Time
	// Message tags
	Tags []string
	// Message size in bytes (total)
	Size float64
	// Whether the message has any attachments
	Attachments int
	// Message snippet includes up to 250 characters
	Snippet string
}

MessageSummary struct for frontend messages

swagger:model MessageSummary

func List

func List(start, limit int) ([]MessageSummary, error)

List returns a subset of messages from the mailbox, sorted latest to oldest

func Search(search, timezone string, start, limit int) ([]MessageSummary, int, error)

Search will search a mailbox for search terms. The search is broken up by segments (exact phrases can be quoted), and interprets specific terms such as: is:read, is:unread, has:attachment, to:<term>, from:<term> & subject:<term> Negative searches also also included by prefixing the search term with a `-` or `!`

Jump to

Keyboard shortcuts

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