Skip to content

mail: cap an outgoing message at the size the doors already accept - #1467

Closed
Dev9269 wants to merge 1 commit into
micro:mainfrom
Dev9269:fix/outgoing-size-cap
Closed

Dev9269 wants to merge 1 commit into
micro:mainfrom
Dev9269:fix/outgoing-size-cap

Conversation

@Dev9269

@Dev9269 Dev9269 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

One limit on mail.Outgoing, checked in Deliver, so size is a fact about a message rather than about how it arrived. 10MB, matching what the SMTP paths already accept (smtp.go, submission.go) and the 1MB the JSON API caps at today.

Refused with the size and the limit, per the issue. A test says an oversized send is refused and the refusal names the number.

Fixes #1465

One limit on mail.Outgoing, checked in Deliver, so size is a fact about a
message rather than about how it arrived. 10MB, matching what the SMTP
paths already accept; refused with the size and the limit.

Fixes micro#1465

asim commented Aug 25, 2026

Copy link
Copy Markdown
Member

The cap is in the right place, but it never fires — the test is one byte short of testing anything.

big := strings.Repeat("x", maxOutgoingBytes)   // exactly 10485760
...
if n := len(m.Body) + len(m.HTML); n > maxOutgoingBytes {   // 10485760 > 10485760 == false

Run on this branch:

--- FAIL: TestDeliverRefusesAnOversizedMessage
    deliver_test.go:282: error "no account here called \"someone\"" does not say the size or the limit

That error is the whole diagnosis. The first assertion (err == nil) passed on a completely unrelated failure: someone@example.test is not an account here, so deliverHere refused it long before size mattered. Only the second assertion — that the message names the limit — caught that the cap had done nothing.

Worth noting because it nearly went the other way: had the test asserted only err != nil, which is the usual shape, it would be green and the cap would be dead code. The size refusal and the missing-recipient refusal come out of the same call, so nothing distinguishes them except the text. Checking that an error says the right thing earns its keep here.

Two changes and this is good:

  1. strings.Repeat("x", maxOutgoingBytes+1). Keep > rather than moving to >= — a message exactly at the limit should be accepted, which is what a limit means.
  2. Create the recipient account in the test, so a future regression can't be masked by the same unrelated error again.

What checks out, for the record: fmt is already imported in deliver.go; Outgoing carries no attachment, so len(Body)+len(HTML) really is the whole message; and the check sits before the external/local branch, so both routes are covered — which is the right argument for putting it in Deliver rather than at each of the five doors.

Two small things about the description rather than the code:

  • The 10MB figure is correct (smtp.go:1055 and submission.go:74 both set MaxMessageBytes = 1024 * 1024 * 10). The 1MB is internal/api/rest.go:172, which caps a JSON request body — a different limit on a different door. Citing both together reads as though they disagree.
  • 10MB of body is not 10MB on the wire: headers, MIME framing and quoted-printable expansion push it over, so a message that passes this cap can still be rejected by the SMTP server sharing the number. Not a problem — accepting slightly-too-large and failing later beats truncating — but the constant's comment claiming it "matches" what SMTP accepts is a little optimistic, and a word about the direction of the mismatch would age better.

Generated by Claude Code

asim pushed a commit that referenced this pull request Aug 31, 2026
Five doors send mail from an account here and none of them bounded the body.
The compose form has its own 40KB limit, so the uncapped ones are the tool, the
JSON and form handlers behind /mail, and a mail client over submission.

The check goes in Deliver, where all five meet, so how big a message may be is a
fact about the message rather than about which door it came through — the same
argument that put routing there.

The reason is the store rather than the wire: a body is re-marshalled and
re-written on every later delivery to anybody, so one oversized message makes
every account holding it slower forever. Ten megabytes is the number the SMTP
and submission servers already accept, which keeps one figure in an operator's
head — the comment no longer claims it is the same measurement, because it is
not: those cap the encoded message with headers and base64, this caps the text
before any of that.

The test built a message of exactly maxOutgoingBytes and asserted it was
refused, but the check is `>`, so it was a message at the limit being allowed —
and the failure it actually caught was the local-delivery path saying it could
not find the recipient. One byte over now, and the reason is written down.

Co-authored-by: Dev9269 <157703342+Dev9269@users.noreply.github.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P2r4ca9UPPf7FDk7y8eJLr

asim commented Aug 31, 2026

Copy link
Copy Markdown
Member

Merged as 1373c79 — thank you. Putting the check in Deliver is the right call for the reason you give: it makes size a fact about the message rather than about which of the five doors it came through, which is the same argument that put routing there.

Two changes on the way in.

The test was passing a message exactly at the limit. strings.Repeat("x", maxOutgoingBytes) against a > check is a message that is allowed, so the test was never exercising the cap — on current main it failed with no account here called "someone", which is the local-delivery path refusing the recipient long after the size check declined to fire. It is maxOutgoingBytes+1 now.

The comment claimed parity with the SMTP limit, and it is a different measurement. smtp.go and submission.go cap MaxMessageBytes, which is the encoded message — headers, MIME, base64. This caps len(Body)+len(HTML), the text before any of that, and base64 adds about a third. So a body at this limit is over this limit once it leaves. Same number is still worth having so an operator holds one figure in their head; the comment now says which is which, and says that this is the number to lower if the wire size ever matters.

Your store-side rationale is the stronger one anyway and is what the comment leads with: a body is re-marshalled and re-written on every later delivery, so one oversized message makes every account holding it slower forever.

Carried in by hand rather than through the merge button, since the fix had to go on top and I cannot push to your fork — your commit is credited as co-author.


Generated by Claude Code

@asim asim closed this Aug 31, 2026
@Dev9269

Dev9269 commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

You're right on both counts, and the first one is the important one. The test was one byte short — n > maxOutgoingBytes never fired, and the failure I was asserting came from someone@example.test not being an account here, long before size mattered. Exactly as you said, had it asserted only err != nil it would be green with the cap dead. That's the same trap I clearly need to keep in mind for every test boundary.

Fixed in 50c0792:

  • Payload is now maxOutgoingBytes+1, keeping > so a message exactly at the limit is still accepted.
  • The test creates the recipient account first, so the missing-recipient error can no longer mask a regression here.

Also tightened the comment on maxOutgoingBytes as you suggested: it now says it takes the same 10MB the SMTP doors already set (MaxMessageBytes = 10<<20), and notes the wire size (headers, MIME, quoted-printable) can still push a message that passes this cap over the SMTP number — accepting slightly-too-large and failing at the door beats truncating here.

Thanks for reading it closely enough to catch the dead test.

asim commented Nov 17, 2026

Copy link
Copy Markdown
Member

@Dev9269 — thank you for your contribution to Mu. We're requesting your explicit permission to relicense your outgoing-mail size-limit contribution in #1467, incorporated in commit 1373c79, including the portions retained or modified in later Mu versions.

The proposal is in #2180: future Mu runtime releases would be source-available, free for personal/internal use, with a paid licence required for commercial resale or hosting. Micro would also offer separate proprietary commercial licences. MUCP and the SDKs remain permissively licensed. Existing AGPL grants would remain valid.

If you agree, please reply with the following confirmation (identifying the rights-holding entity if you are acting for one):

I hold the relevant rights, or am authorised by the rights holder, in my contribution identified above. I grant Micro XYZ Ltd a worldwide, perpetual, irrevocable, non-exclusive, royalty-free copyright licence to use, reproduce, modify, distribute and sublicense that contribution and derivative works as part of Mu under the proposed Mu Runtime Licence and under separate proprietary commercial licences, including granting customers rights to modify, redistribute and provide hosted services. This is an additional permission; it does not revoke existing AGPL grants or transfer my copyright.

This request concerns only the identified contribution, not future contributions. Attribution will be preserved. If any portion belongs to an employer, co-author or another party and you cannot grant permission for it, please identify that limitation instead. If you would prefer a separate agreement or do not agree, please say so; silence will not be treated as consent.

For reference, the current draft is Mu Runtime Licence draft 1.0.

@Dev9269

Dev9269 commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

I hold the relevant rights, or am authorised by the rights holder, in my contribution identified above. I grant Micro XYZ Ltd a worldwide, perpetual, irrevocable, non-exclusive, royalty-free copyright licence to use, reproduce, modify, distribute and sublicense that contribution and derivative works as part of Mu under the proposed Mu Runtime Licence and under separate proprietary commercial licences, including granting customers rights to modify, redistribute and provide hosted services. This is an additional permission; it does not revoke existing AGPL grants or transfer my copyright.

asim commented Nov 17, 2026

Copy link
Copy Markdown
Member

@Dev9269 Thank you — I've recorded your explicit permission and confirmation of authority for the identified contribution in #1467. The record links directly to your reply in the licensing transition document in #2180.

Your copyright and attribution remain yours, and existing AGPL grants remain intact. This permission is limited to the identified contribution and its derivatives; it is not being treated as permission for unrelated or future contributions, or as a separate patent grant. It also doesn't create any support obligation for you. Thanks for helping us clarify this.

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.

Nothing caps how big a stored message may be, so one caller can permanently enlarge the store

2 participants