Files
counters/CLAUDE.md
T
Dimitrije DimitrijevicandClaude Opus 5.5 d465739f6d Add countersend test tool and project CLAUDE.md
countersend send plays mailqueuer against /in and /out, and
countersend receive writes each notification to a file in place of
the web app. send refuses a run that would notify unless given
--allow-notify. The Makefile builds it in build, freebsd and
build-linux. docs/testing-with-countersend.md has the steps.

Also add CLAUDE.md and gitignore .claude/.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 13:04:03 +01:00

3.4 KiB

migadu_counters

Go daemon for real-time mail counting at Migadu. mailqueuer POSTs each recipient to /in or /out. The daemon increments daily address, domain and organisation counters in Redis and notifies the web app when a counter reaches a warning threshold or a limit. It replaces the rspamd Lua plugin migadu_counters.lua, and it enforces nothing itself.

README.md is the contract for the API, Redis keys, config, logs and metrics. Read it there rather than from memory. The design record is in plans/, and open work is in todo.md.

Commands

make build         # bin/migadu_counters, bin/counterctl, bin/countersend
make test          # go test -race ./...
make vet           # go vet + gofmt
make test-contrib  # shell test for contrib/pull-domains.sh (needs tinycdb cdb + rsync)
make freebsd       # static FreeBSD amd64 binaries

Layout

  • cmd/migadu_counters: the daemon.
  • cmd/counterctl: reads counters through GET /counters.
  • cmd/countersend: standalone test tool. send plays mailqueuer, receive writes each notification to a file. Guide: docs/testing-with-countersend.md.
  • internal/: api, config, counting, domains, metrics, notify, server, store, txlog, watcher.
  • contrib/: CDB pull script and cron example.
  • review/: past code reviews and proof tests, excluded from the gofmt check.

Rules not to break

  • Redis keys are shared with the web app: cnt/<A|D|O>/<id>/d/<YYYY-MM-DD>/<i|o>, DB 0, UTC day, TTL 31 days, INCR and EXPIRE in one MULTI/EXEC.
  • Notifications are sent at most once and never repeated. A request that was sent but got no answer is not retried.
  • Notification markers use the ntf/ prefix because the web app scans cnt/*<address>*.
  • Warning URLs must not use the breach URL's path, because the web app treats every call there as a breach. The daemon refuses to start if they do.
  • The suffix of a user@dom@SUFFIX login may be a credential and is never logged or printed.
  • countersend send refuses a run that would trigger a notification unless given --allow-notify. Keep that default, because real URLs email customers.

How to work here

  • Write the failing test first, then the code.
  • Use the real fixture test_files/rspamd_domains_db.cdb. It is gitignored because it holds real customer domains, so never copy its contents into commits, docs or memory. On a fresh clone the tests fail until it is copied from an agent host (see README.md).
  • Run make vet and make test before reporting work as done.
  • Commit or push only when asked.

Gotchas

  • SIGHUP reloads the CDB and reopens logs but does not reread the config. Notify URL changes need a restart.
  • Replace the CDB with mv, never in place. Rewriting it truncates the inode the daemon holds open.
  • FreeBSD base has no curl (use fetch), and root's shell may be csh.
  • The local shell is zsh: quote URLs containing ?, and an unquoted $VAR holding several words is not split.
  • golang.org/x/net is pinned to v0.43.0.
  • cdb (tinycdb) and redis-server are installed through Homebrew.

../mailqueuer (will call this daemon, no client yet), ../migadu_web3 (web app receiving the notifications), ansible-freebsd3 (deployment role, not written yet).

Memory

Project memory lives in .claude/memory/, which git ignores. Save new memories there, one fact per file with a line added to its index:

@.claude/memory/MEMORY.md