moved

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package moved notices when the person moves an email MailRules filed out of the folder MailRules put it in, in another mail app: back to the Inbox, or to another folder. It runs only for a build whose module asks to know (ext.Moves); the free build never starts it.

It costs no connection of its own. Each mailbox's supervisor calls Sweep now and then on the mailbox's one worker connection, between two emails, so nothing MailRules does to the mailbox (sorting, undo, a fix, a cleanup) happens while it looks. A sweep reads what MailRules filed in the last WatchDays and is still in effect, at most SweepLimit emails, grouped by the folder they were filed in: one UID SEARCH per folder tells which are still there (mail.Mailbox.Present). Only an email found gone costs more: a Message-ID search of the mailbox's folders, Inbox first, until it turns up, for at most LocateLimit emails a sweep. Each gone email is recorded once (store.RecordMove), so it is never searched for again. At most Concurrent sweeps run at a time in the process; a mailbox whose turn finds them all busy waits for its next one. Nothing here changes a mailbox: SEARCH reads no message and sets no flag.

Index

Constants

View Source
const (
	// WatchDays is how long after MailRules filed an email a move of it is noticed.
	WatchDays = 7
	// SweepLimit is how many filed emails one sweep of a mailbox checks at most; the next
	// sweep goes on from there.
	SweepLimit = 500
	// LocateLimit is how many gone emails one sweep searches the folders for at most.
	LocateLimit = 20
	// Concurrent is how many sweeps run at once in the process.
	Concurrent = 4
	// SweepTimeout bounds one sweep, during which the mailbox's new mail waits.
	SweepTimeout = time.Minute
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Watcher

type Watcher struct {
	Store *store.Store
	// Serves, when set, says whether a tenant's mailboxes are swept; nil = every mailbox.
	Serves func(ctx context.Context, tenantID int64) bool
	// Found, when set, is called once for each move of the person recorded.
	Found func(m store.Move)
	Now   func() time.Time // nil = time.Now
	// contains filtered or unexported fields
}

Watcher sweeps mailboxes for emails the person moved. One serves every mailbox of the process; its zero value is not ready, use New.

func New

func New(st *store.Store) *Watcher

New returns a watcher over st.

func (*Watcher) Sweep

func (w *Watcher) Sweep(ctx context.Context, mb mail.Mailbox, acct store.Account) error

Sweep looks at what MailRules filed in acct, on mb, and records each email it finds gone from where MailRules left it. The caller holds the mailbox's processor between emails (worker.Supervisor), so no MailRules action moves mail meanwhile.

Jump to

Keyboard shortcuts

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