Skip to content

Serialization overhaul: improved support and explicit legacy failures #690

Description

@bbottema

Problem

Email implements Serializable, but its current serialized form deliberately omits three pieces of state that are needed to use the restored email:

  • attachment, embedded-image and decrypted-attachment DataSource content;
  • the forwarded MimeMessage;
  • SmimeSigningConfig.

The result is a partial read-back. Attachment metadata may still be present, but content access or sending eventually fails because the nested data source is gone. The website documents this as a list of transient fields, including one field that no longer exists, rather than defining what serialization is useful for.

Chosen behavior for v9.2.0

Treat Java serialization as a send-ready email snapshot:

  1. Materialize every attachment-like data source while the email is serialized.
  2. Store its bytes, name, MIME type and Jakarta Mail EncodingAware hint.
  3. Restore a private, read-only, byte-backed data source.
  4. Store a forwarded message as RFC822/MIME bytes and reconstruct it with a neutral Session.
  5. Serialize S/MIME signing configuration, including its PKCS12 data and key settings.

This preserves the email state needed to copy, govern, validate, convert and send it later. It does not preserve the original runtime object graph.

A custom DataSource is always materialized, even when that implementation also implements Serializable. After deserialization, its concrete type, lazy IMAP/URL access, caching, write behavior and implementation-specific methods are not restored. A lazy source is therefore fetched at serialization time.

Legacy streams

Simple Java Mail releases before 9.2.0 never wrote attachment bytes into the stream, so those bytes cannot be recovered later.

A pre-9.2 email should continue to deserialize for archival and metadata inspection. Its legacy attachment receives an unavailable-data placeholder. Reading or writing its content—and therefore attempting to send it—must fail with a clear exception explaining that the legacy stream contains no attachment data, instead of failing with a null pointer.

Forwarded MIME content and S/MIME signing configuration omitted by an old stream remain null; there is no data from which to reconstruct them.

Historical lineage

Acceptance criteria

  • New serialized emails restore attachment, embedded-image and decrypted-attachment bytes and MIME metadata.
  • Serializable custom data sources are still restored as internal read-only snapshots, never as their original implementation.
  • Lazy sources are read exactly once during serialization and their streams are closed.
  • Forwarded MIME messages survive with their headers, body structure and attachments.
  • S/MIME signing configuration survives, including PKCS12 bytes and algorithm.
  • Restored emails can be copied, governed, validated, converted and sent.
  • Pre-9.2 attachment-bearing fixtures still deserialize, but content access and sending fail with a clear legacy-data exception.
  • Serialization failures do not produce a usable partial snapshot.
  • Website, Javadocs, v9.2 migration notes and Unreleased release notes describe the new contract and its security implications.
  • Focused tests and the complete Java 8 build pass.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions