Skip to content

🪲 BUG-#65: Store raw RFC822 source as bytes for binary-safe backup/restore - #80

Merged
FernandoCelmer merged 1 commit into
developfrom
feature/65
May 17, 2026
Merged

🪲 BUG-#65: Store raw RFC822 source as bytes for binary-safe backup/restore#80
FernandoCelmer merged 1 commit into
developfrom
feature/65

Conversation

@FernandoCelmer

Copy link
Copy Markdown
Member

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.file is now bytes (was str). A field_validator coerces incoming str via latin-1 (byte-preserving) for backward compatibility with any caller still passing strings
  • RawModel.file switches TextLargeBinary (BLOB) so SQLite stores the bytes verbatim
  • Message.file follows suit (bytes), and Message.from_raw stores raw directly without .decode("utf-8", errors='replace')
  • Sync.orchestrate writes entry.raw() instead of entry.text()
  • MailBox.append receives bytes from Message.file unchanged (no more .encode("utf-8"))
  • Tests cover binary round-trip across all 256 byte values, str-input coercion, and upsert with bytes

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 through saveget

…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 FernandoCelmer left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Code Review

Code issues found: 0

Correct end-to-end:

  • RawSerializer.filebytes with a latin-1 coercion validator (byte-preserving for the 0-255 range — the standard trick for opaque-bytes-as-str interop).
  • RawModel.fileLargeBinary (SQLite stores as BLOB; legacy Text rows remain readable because SQLite is typeless).
  • Sync.sync now writes entry.raw() (bytes) instead of entry.text() (lossy UTF-8 with errors='replace').
  • Message.from_raw stores raw verbatim; MailBox.append no longer re-encodes a Message.
  • Test asserting bytes(range(256)) round-trips through saveget is exactly the right invariant.

Note for release notes — this is a breaking API change for Message.file (strbytes) 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.

@FernandoCelmer
FernandoCelmer merged commit bfb9c60 into develop May 17, 2026
10 checks passed
@FernandoCelmer
FernandoCelmer deleted the feature/65 branch May 17, 2026 21:53
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