mail

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT, MIT Imports: 19 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mail is the unread-mail service: notmuch queries (one per account, or the single query), re-run when the notmuch maildir changes, with optional desktop notifications for newly-arrived messages. The bar module and the dropdown both read one Service.

Index

Constants

View Source
const Debounce = 500 * time.Millisecond

Debounce coalesces a maildir-sync burst into one re-query.

View Source
const NotifyMax = 5

NotifyMax caps how many per-message notifications one arrival burst fires, so a large sync cannot flood the notification daemon.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountUnread

type AccountUnread struct {
	Name  string
	Icon  string
	Count uint32
	Err   error
}

AccountUnread is one account's resolved icon and unread count; Err is why the count could not be read, and Count is then 0.

type CLI

type CLI struct{}

CLI runs the notmuch binary.

func (CLI) Count

func (CLI) Count(ctx context.Context, query string) (uint32, error)

Count is `notmuch count <query>`.

func (CLI) DatabasePath

func (CLI) DatabasePath(ctx context.Context) (string, bool)

DatabasePath is `notmuch config get database.path` (maildir_path).

func (CLI) Newest

func (CLI) Newest(ctx context.Context, query string, limit int) ([]Message, error)

Newest is `notmuch search --format=json --sort=newest-first --limit=N <query>`, one (sender, subject) per thread.

type DesktopNotifier

type DesktopNotifier struct {
	Sender *desktopnotify.Sender
}

DesktopNotifier fires mail notifications as "lys-shell" through the session notification daemon.

func (DesktopNotifier) Notify

func (d DesktopNotifier) Notify(summary, body, icon string)

Notify sends in the background; failures are logged, never returned, as a missing notification must not fail the re-query.

type Message

type Message struct {
	Sender  string
	Subject string
}

Message is one newest-first search hit.

type Notifier

type Notifier interface {
	Notify(summary, body, icon string)
}

Notifier fires one desktop notification, fire-and-forget.

type Notmuch

type Notmuch interface {
	// Count is `notmuch count <query>`.
	Count(ctx context.Context, query string) (uint32, error)
	// Newest returns up to limit newest matches.
	Newest(ctx context.Context, query string, limit int) ([]Message, error)
	// DatabasePath is `notmuch config get database.path`; ok=false
	// when there is no database to watch.
	DatabasePath(ctx context.Context) (string, bool)
}

Notmuch is the query seam.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service holds the counts and runs the watch loop.

func New

func New(cfg config.MailConfig, notmuch Notmuch, notifier Notifier) *Service

New builds a service; Run starts it. A nil notifier disables notifications regardless of the notify key.

func (*Service) PerAccount

func (s *Service) PerAccount() bool

PerAccount reports whether the accounts are counted, rather than the single query.

func (*Service) Run

func (s *Service) Run(ctx context.Context)

Run seeds the counts without notifying (existing unread mail at startup is not "new"), then re-queries after each settled burst of maildir changes until ctx ends. Without a notmuch database the seed is all there is. The watch is armed before the seed query so a change during it is not lost.

func (*Service) State

func (s *Service) State() State

State returns the latest counts.

func (*Service) Subscribe

func (s *Service) Subscribe() (<-chan struct{}, func())

Subscribe ticks after every publish; stop unregisters.

type State

type State struct {
	Accounts []AccountUnread
	Total    uint32
	Err      error
}

State is one published read: the per-account counts in config order (empty without accounts), the total of the counts that were read, and Err, every query that failed, nil when all were read.

Jump to

Keyboard shortcuts

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