🪲 BUG-#65: Store raw RFC822 source as bytes for binary-safe backup/restore - #80
Merged
Conversation
…store RawSerializer.file becomes bytes with str→bytes coercion validator. RawModel.file switches to LargeBinary. Sync stores entry.raw() and MailBox.append passes bytes through unchanged. Message.file also becomes bytes. Tests assert binary round-trip across all 256 byte values.
FernandoCelmer
commented
May 17, 2026
FernandoCelmer
left a comment
Member
Author
There was a problem hiding this comment.
🔍 Code Review
Code issues found: 0
Correct end-to-end:
RawSerializer.file→byteswith alatin-1coercion validator (byte-preserving for the 0-255 range — the standard trick for opaque-bytes-as-str interop).RawModel.file→LargeBinary(SQLite stores as BLOB; legacy Text rows remain readable because SQLite is typeless).Sync.syncnow writesentry.raw()(bytes) instead ofentry.text()(lossy UTF-8 witherrors='replace').Message.from_rawstoresrawverbatim;MailBox.appendno longer re-encodes aMessage.- Test asserting
bytes(range(256))round-trips throughsave→getis exactly the right invariant.
Note for release notes — this is a breaking API change for Message.file (str → bytes) and RawSerializer.file. Both are exported from email_profile. Current version is 1.0.0.dev1 so pre-release semantics apply, but the CHANGELOG should call this out before a stable 1.0.0 ships — any consumer printing msg.file will now see b'...'.
Closes #65.
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.
Summary
Stop lossy UTF-8 round-tripping of RFC822 source. Backup/restore now preserves binary attachments and non-UTF8 bodies byte-for-byte.
Changes
RawSerializer.fileis nowbytes(wasstr). Afield_validatorcoerces incomingstrvia latin-1 (byte-preserving) for backward compatibility with any caller still passing stringsRawModel.fileswitchesText→LargeBinary(BLOB) so SQLite stores the bytes verbatimMessage.filefollows suit (bytes), andMessage.from_rawstoresrawdirectly without.decode("utf-8", errors='replace')Sync.orchestratewritesentry.raw()instead ofentry.text()MailBox.appendreceives bytes fromMessage.fileunchanged (no more.encode("utf-8"))Migration
Existing rows stored as Text are still readable by SQLite; SQLAlchemy decodes the legacy column. New writes use the bytes path. If a consumer needs to migrate historical rows,
re.encode("latin-1")on the stored string round-trips any byte sequence — but no automatic migration is shipped since the schema change is forward-compatible.Closes #65
Test plan
pytest— 211 passed (was 208 + 3 new bytes tests)bytes(range(256))round-trips throughsave→get