zinc

package
v0.0.0-...-9864bbb Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StartZincService

func StartZincService(url, user, password string)

StartZincService starts the zinc service singleton.

func UploadEmails

func UploadEmails(bulk *BulkEmails, auth *ZincAuth) error

UploadEmails uploads a list of emails to the zinc server

func ValidateSortField

func ValidateSortField(sortField string) error

ValidateSortField validates a sort field with the format: (+|-)(from|to|cc|bcc|date)

Types

type BulkEmails

type BulkEmails struct {
	Index   string        `json:"index"`
	Records []email.Email `json:"records"`
}

BulkEmails is used to upload emails in bulk to the zinc server

type DateRange

type DateRange struct {
	From time.Time `json:"from"` // the start date. Default: 0
	To   time.Time `json:"to"`   // the end date. Default: max time
}

DateRange represents a range of dates (from, to) to filter the query.

type EmailWithId

type EmailWithId struct {
	Id        string    `json:"_id"`
	MessageId string    `json:"messageId"`
	Date      time.Time `json:"date"`
	From      string    `json:"from"`
	To        []string  `json:"to"`
	Cc        []string  `json:"cc"`
	Bcc       []string  `json:"bcc"`
	Subject   string    `json:"subject"`
	Body      string    `json:"body"`
	IsRead    bool      `json:"isRead"`
	IsStarred bool      `json:"isStarred"`
}

EmailWithId is the returned email format from the zinc server.

type QueryPaginationSettings

type QueryPaginationSettings struct {
	Start int // the offset to start from (pagination). Default: 0
	Size  int // the number of elements to return (pagination). Default: 100
}

QueryPaginationSettings sets the pagination parameters for the query.

type QueryResponse

type QueryResponse struct {
	Total  int           `json:"total"`  // Total number of emails that match the query (not the number of emails returned)
	Took   int           `json:"took"`   // Time it took to execute the query
	Emails []EmailWithId `json:"emails"` // Emails that match the query (paginated)
}

QueryResponse is the response from the zinc server to a query.

type QuerySettings

type QuerySettings struct {
	Sort        string                   // the sorting parameters. Default: "-date"
	Pagination  *QueryPaginationSettings // the pagination parameters. Default: {Start: 0, Size: 100}
	StarredOnly bool                     // if true, only starred emails will be returned. Default: false
}

QuerySettings sets the parameters for the query.

func NewQuerySettings

func NewQuerySettings(sortBy string, start, size int, starredOnly bool) (*QuerySettings, error)

NewQuerySettings creates new QuerySettings.

func (*QuerySettings) ParseQuerySettings

func (settings *QuerySettings) ParseQuerySettings() string

ParseQuerySettings parses the query settings to a string.

func (*QuerySettings) ParseQuerySortSettings

func (settings *QuerySettings) ParseQuerySortSettings() string

ParseQuerySortSettings parses the query sort settings to a string. (only pagination and sort since starred is a filter)

func (*QuerySettings) ParseStarredFilter

func (settings *QuerySettings) ParseStarredFilter() string

ParseStarredFilter parses the starred filter to a string.

type SearchQuery

type SearchQuery struct {
	From            string    `json:"from"`            // from address (exact match)
	To              []string  `json:"to"`              // to addresses (exact match to all)
	Cc              []string  `json:"cc"`              // cc addresses (exact match to all)
	Bcc             []string  `json:"bcc"`             // bcc addresses (exact match to all)
	SubjectIncludes string    `json:"subjectIncludes"` // subject (has text)
	BodyIncludes    string    `json:"bodyIncludes"`    // body includes (has text)
	BodyExcludes    string    `json:"bodyExcludes"`    // body excludes (does not have text)
	DateRange       DateRange `json:"dateRange"`       // the date range to filter the query
}

SearchQuery represents a query to search for emails. The query will only return emails that match all the fields. If a field is empty, it will be ignored.

type ZincAuth

type ZincAuth struct {
	Url      string
	User     string
	Password string
}

ZincAuth is a struct that contains the authentication information for the zinc server.

type ZincService

type ZincService struct {
	Url      string
	User     string
	Password string
}

ZincService is a service that interacts with the zinc server.

var Service *ZincService

ZincService Singleton

func NewZincService

func NewZincService(url, user, password string) *ZincService

NewZincService returns a new zinc service.

func (*ZincService) CheckIndex

func (service *ZincService) CheckIndex() (bool, error)

CheckIndex checks if the index exists in the zinc server

func (*ZincService) CreateIndex

func (service *ZincService) CreateIndex() error

CreateIndex creates an index in the zinc server with a mapping that matches the Email struct

func (*ZincService) DeleteEmail

func (service *ZincService) DeleteEmail(id string) error

DeleteEmail deletes an email from the zinc server.

func (*ZincService) DeleteEmails

func (service *ZincService) DeleteEmails(ids []string) error

DeleteEmails deletes a list of emails from the zinc server.

func (*ZincService) DeleteIndex

func (service *ZincService) DeleteIndex() error

DeleteIndex deletes the emails index from the zinc server

func (*ZincService) GetAllEmails

func (service *ZincService) GetAllEmails(settings *QuerySettings) (*QueryResponse, error)

GetAllEmails returns all emails from the zinc server (paginated).

func (*ZincService) GetEmailById

func (service *ZincService) GetEmailById(id string) (*EmailWithId, error)

GetEmailById returns the email that has the given _id (zinc id).

func (*ZincService) GetEmailByMessageId

func (service *ZincService) GetEmailByMessageId(messageId string) (*EmailWithId, error)

GetEmailByMessageId returns the email that has the given message id.

func (*ZincService) GetEmailsByQueryString

func (service *ZincService) GetEmailsByQueryString(queryString string, settings *QuerySettings) (*QueryResponse, error)

GetEmailsByQueryString returns all emails that match the given query string (paginated). A query string is a string composed of query language syntax. For example: "query string +other word +content:test"

func (*ZincService) GetEmailsBySearchQuery

func (service *ZincService) GetEmailsBySearchQuery(searchQuery *SearchQuery, settings *QuerySettings) (*QueryResponse, error)

GetEmailsBySearchQuery returns all emails that match the given search query (paginated).

func (*ZincService) UpdateEmail

func (service *ZincService) UpdateEmail(id string, email *email.Email) (*EmailWithId, error)

UpdateEmail updates an email in the zinc server.

func (*ZincService) UpdateEmails

func (service *ZincService) UpdateEmails(emails []*EmailWithId) ([]*EmailWithId, error)

UpdateEmails updates a list of emails in the zinc server.

Jump to

Keyboard shortcuts

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