Skip to content

Count attachments and use the accept time when recording receive usage - #50

Merged
markmnl merged 1 commit into
mainfrom
quota-usage
Oct 10, 2026
Merged

markmnl merged 1 commit into
mainfrom
quota-usage

Conversation

@markmnl

@markmnl markmnl commented Oct 10, 2026

Copy link
Copy Markdown
Owner

What

fmsgd recorded a received message's usage (POST /fmsgid/recv) with only the body's wire size and the sender's timestamp. Attachments were never counted, and a backdated message fell outside fmsgid's per-day window.

  • Usage is now the stored size: the body plus every attachment, each decompressed if it was sent compressed (storedSize).
  • It's timestamped when this host accepted the message, not with the sender's timestamp (recordRecvUsage).
  • The receive limit check (recvLimitExceeded: messages per day, bytes per day, total bytes; -1 is unlimited) uses that same stored size. So a message whose attachments take a recipient over a limit is rejected with 101 (user full), as one with a large body already was. The check is otherwise unchanged.
  • The README has a new "Quotas and usage" section. It says fmsgd records receive usage only for mail from other hosts. Send usage and mail between local addresses are recorded by the client that sends and delivers locally, such as fmsg-webapi (companion PR).

Tests

  • usage_test.go: stored size (compressed body and attachments), every limit's boundaries, a message whose attachments go over a limit its body alone fits, and the recorded usage payload (accept time, stored size, one record per accepted recipient) against a stub fmsgid.
  • go vet ./..., gofmt clean, and go test ./... pass, including the pkg/message PostgreSQL integration tests against a throwaway Postgres 17.

Deploy

No schema change. Deploy before or with fmsg-webapi's quota change.

🤖 Generated with Claude Code

fmsgd recorded a received message's usage with only its body's wire size
and the sender's timestamp, so attachments were never counted and a
backdated message fell outside the per-day window.

Usage is now the stored size, the body plus every attachment, each
decompressed if it was sent compressed. It's timestamped when this host
accepted the message. The receive limit check uses the same stored size,
so a message whose attachments take a recipient over a limit is
rejected with 101 (user full), as one with a large body already was.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@markmnl
markmnl merged commit c99adfe into main Oct 10, 2026
2 of 3 checks passed
@markmnl
markmnl deleted the quota-usage branch October 10, 2026 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant