Expose BODYSTRUCTURE octet count as MessagePart.size (supersedes #184)#187
Merged
Conversation
BODYSTRUCTURE reports each part's body size in octets, but the value was dropped when building MessagePart from a BodyStructure. Carry it through as an optional size property (nil when the server reports 0/absent) so clients can show size labels and apply download caps without fetching part bytes.
body-fld-octets is mandatory in BODYSTRUCTURE, so NIOIMAP 0.3.0 never uses 0 as a missing-field sentinel: a missing value makes the body structure invalid and never reaches this converter. Collapsing 0 to nil made a known-empty part indistinguishable from unavailable size metadata, so callers showing exact sizes or enforcing download caps would wrongly treat empty parts as unknown-size. Addresses review feedback on #184. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
odrobnik
force-pushed
the
claude/pr-184-size-fix
branch
from
July 17, 2026 14:40
6341ab9 to
6c62988
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Carries #184 forward with the review finding fixed. The branch contains the original feature commit from @appinteractive as-is (
6245c30), withmainmerged in on top plus a follow-up fix — so merging this PR (with a merge commit) makes GitHub mark #184 as merged automatically.MessagePartgains an optionalsizeproperty populated from the BODYSTRUCTUREbody-fld-octetsfield, so clients can show size labels and enforce download caps from the structure fetch alone, without fetching part bytes:Fix over #184
The review on #184 flagged that the conversion collapsed a reported octet count of
0tonil. In the pinned NIOIMAP 0.3.0 parserbody-fld-octetsis mandatory — a missing field makes the BODYSTRUCTURE invalid and never reaches this converter — so0is a legitimately reported size of an empty part, not a missing-value sentinel. The converter now passes the octet count through unchanged, keeping empty parts distinguishable from parts whose size metadata is unavailable (e.g. not built from BODYSTRUCTURE). The doc comment spells out these semantics, and the test asserting0 → nilnow asserts0is preserved.Changes
MessagePart: newsize: Int?property, threaded through both public initializers and theCodableimplementation (encoded withencodeIfPresent, so existing archives decode fine).MessagePart+BodyStructure: readfields.octetCountwhen flattening singleparts, passing it through as-is.MessagePartSizeTests: singlepart carries the octet count, zero is preserved, multipart children each carry their own size.Note: the size is the encoded (transfer-encoding) octet count per RFC 3501 — for base64 parts roughly 4/3 of the decoded file size.
Test plan
swift buildclean🤖 Generated with Claude Code