filter

package
v0.10.7 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Actions

type Actions struct {
	AddLabel         string
	Category         gmail.Category
	Archive          bool
	Delete           bool
	MarkImportant    bool
	MarkNotImportant bool
	MarkRead         bool
	MarkNotSpam      bool
	Star             bool
	Forward          string
}

Actions represents an action associated with a Gmail filter.

func (Actions) Empty

func (a Actions) Empty() bool

Empty returns true if no action is specified.

type Criteria

type Criteria struct {
	From    string
	To      string
	Subject string
	Query   string
}

Criteria represents the filtering criteria associated with a Gmail filter.

func GenerateCriteria

func GenerateCriteria(crit parser.CriteriaAST) (Criteria, error)

GenerateCriteria translates a rule criteria into an entry that maps directly into Gmail filters.

func (Criteria) Empty

func (c Criteria) Empty() bool

Empty returns true if no criteria is specified.

func (Criteria) ToGmailSearch

func (c Criteria) ToGmailSearch() string

ToGmailSearch returns the equivalent query in Gmail search syntax.

type Filter

type Filter struct {
	// ID is an optional identifier associated with a filter.
	ID       string
	Action   Actions
	Criteria Criteria
}

Filter matches 1:1 a filter created on Gmail.

func (Filter) HasLabel

func (f Filter) HasLabel(name string) bool

HasLabel returns true if the given label is used by the filter.

func (Filter) String

func (f Filter) String() string

type Filters

type Filters []Filter

Filters is a list of filters created in Gmail.

func FromRule

func FromRule(rule parser.Rule, sizeLimit int) (Filters, error)

FromRule translates a rule into entries that map directly into Gmail filters.

func FromRules

func FromRules(rs []parser.Rule) (Filters, error)

FromRules translates rules into entries that map directly into Gmail filters.

func FromRulesWithLimit

func FromRulesWithLimit(rs []parser.Rule, sizeLimit int) (Filters, error)

FromRulesWithLimit translates rules into entries that map directly into Gmail, but uses a custom size limit.

func (Filters) HasLabel

func (fs Filters) HasLabel(name string) bool

HasLabel returns true if the given label is used by at least one filter.

func (Filters) String

func (fs Filters) String() string

type FiltersDiff

type FiltersDiff struct {
	Added   Filters
	Removed Filters
}

FiltersDiff contains filters that have been added and removed locally with respect to upstream.

func Diff

func Diff(upstream, local Filters) (FiltersDiff, error)

Diff computes the diff between two lists of filters.

To compute the diff, IDs are ignored, only the contents of the filters are actually considered.

func NewMinimalFiltersDiff

func NewMinimalFiltersDiff(added, removed Filters) FiltersDiff

NewMinimalFiltersDiff creates a new FiltersDiff with reordered filters, where similar added and removed ones are next to each other.

The algorithm used is a quadratic approximation to the otherwise NP-complete travel salesman problem. Hopefully the number of filters is low enough to make this not too slow and the approximation not too bad.

func (FiltersDiff) Empty

func (f FiltersDiff) Empty() bool

Empty returns true if the diff is empty.

func (FiltersDiff) String

func (f FiltersDiff) String() string

Jump to

Keyboard shortcuts

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