mail

package
v0.164.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 28 Imported by: 0 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 Caprock Mail: an IMAP/SMTP client that keeps every inbox the user adds in one local database (mail.db, beside Caprock's own) and serves it to the dashboard under /v1/mail.

It is an integration the user switches on by adding an account (ADR-047): until then nothing is opened, no goroutine runs and nothing leaves the machine. Once an account exists, Caprock talks only to the IMAP and SMTP servers the user typed in (for an account signed in with Google or Microsoft: that provider's servers and token endpoint, internal/mail/oauth), and — only while AI is turned on: for an AI action the user runs, and for the background sorting of the inbox (triage.go) — to the provider picked in Mail's settings: the vendor of the user's own coding CLI (Claude Code, Codex, Gemini CLI), an API with the user's key, or a model server at the address given (loopback by default). See internal/mail/ai.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AIDeps added in v0.119.0

type AIDeps struct {
	// Binary finds a CLI by command name ("claude", "codex", "gemini") and
	// returns its absolute path, "" when this computer does not have it.
	// Called on every status request: it must not wait on a shell.
	Binary func(command string) string
	// Env is the user's login-shell environment, for the CLI's PATH and
	// whatever its login reads.
	Env func() []string
	// Dir is an empty working folder of Caprock's for the calls.
	Dir string
}

AIDeps is what Mail's assistant needs from the daemon to run the user's own coding CLIs: where each one is, and the environment it runs in.

type Service

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

Service owns Mail's database and sync engine, both opened on first use.

Sample mode (POST /v1/mail/sample, or CAPROCK_MAIL_DEMO=1 for the whole run) puts a second, throwaway instance in front of the real one: two sample accounts on in-process fake servers, a temporary database and passwords kept in memory. While it is on every route serves the sample; the real mail.db and the keychain are not touched, and turning it off drops the sample and leaves the real instance as it was (or still unopened).

func New

func New(dataDir string, log *slog.Logger) *Service

New prepares Mail under dataDir. If Mail was used before (mail.db exists) its accounts start syncing at once; otherwise nothing happens until the dashboard asks.

CAPROCK_MAIL_DEMO=1 starts in sample mode and keeps it on, for screenshots; the real mail.db is then never opened.

func (*Service) Close

func (s *Service) Close()

Close stops syncing and closes the database (and the sample, if on).

func (*Service) Handler

func (s *Service) Handler() http.Handler

Handler serves /v1/mail/*. Caprock's router puts it behind the same CSRF guard and device pairing as every other /v1 route.

func (*Service) SetAI added in v0.119.0

func (s *Service) SetAI(d AIDeps)

SetAI hands Mail the daemon's CLI finder and environment. Without it no CLI provider is offered (a test's Service, for one).

func (*Service) SetSample added in v0.116.0

func (s *Service) SetSample(on bool) error

SetSample turns sample mode on or off. Under CAPROCK_MAIL_DEMO=1 it cannot be turned off.

Directories

Path Synopsis
Package ai is Mail's assistant: a summary of a thread and a draft reply.
Package ai is Mail's assistant: a summary of a thread and a draft reply.
Package engine talks to mail servers: it keeps the local copy in step with IMAP, applies the user's actions there, and sends over SMTP.
Package engine talks to mail servers: it keeps the local copy in step with IMAP, applies the user's actions there, and sends over SMTP.
Package fakemail runs an in-memory IMAP and SMTP server on loopback, for tests and for the demo mode that previews the client without a real account.
Package fakemail runs an in-memory IMAP and SMTP server on loopback, for tests and for the demo mode that previews the client without a real account.
Package importer reads the mail accounts a user already has in another client — Thunderbird and (on macOS) Apple Mail — so Caprock Mail can offer to add them instead of making the user retype servers and passwords.
Package importer reads the mail accounts a user already has in another client — Thunderbird and (on macOS) Apple Mail — so Caprock Mail can offer to add them instead of making the user retype servers and passwords.
Package store owns the SQLite database.
Package store owns the SQLite database.
Package oauth signs Caprock Mail into Google and Microsoft accounts the way an installed app should (RFC 8252): the authorization code flow with PKCE (RFC 7636, S256) in the user's own browser, redirected back to the daemon on loopback.
Package oauth signs Caprock Mail into Google and Microsoft accounts the way an installed app should (RFC 8252): the authorization code flow with PKCE (RFC 7636, S256) in the user's own browser, redirected back to the daemon on loopback.
oauthtest
Package oauthtest is a fake OAuth provider for tests: an authorization step that stands in for the user's browser, and a token endpoint that checks PKCE, issues ID tokens and refreshes.
Package oauthtest is a fake OAuth provider for tests: an authorization step that stands in for the user's browser, and a token endpoint that checks PKCE, issues ID tokens and refreshes.
Package providers knows the server settings of common mail hosts, so adding an account is an address and a password.
Package providers knows the server settings of common mail hosts, so adding an account is an address and a password.
Package secrets keeps account passwords out of the database: in the OS keychain (macOS login keychain, Windows Credential Manager, Secret Service), else a file only this user can read.
Package secrets keeps account passwords out of the database: in the OS keychain (macOS login keychain, Windows Credential Manager, Secret Service), else a file only this user can read.
Package spam is Caprock Mail's local junk filter: no AI, no network, no account anywhere.
Package spam is Caprock Mail's local junk filter: no AI, no network, no account anywhere.

Jump to

Keyboard shortcuts

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