Skip to content

Expose structured delivery-status reports through Email #763

Closed

Description

@bbottema

Delivery-report cancellation, accepted 6 November 2026

Optional delivery-report parsing can turn a cancelled read into a successful import when the exception identifies interruption but the thread's interrupt flag is clear.

// The delivery-status stream throws InterruptedIOException;
// the thread interrupt flag is clear.
Email received = mail.converter().fromMimeMessage(notification)
    .withFetchAttachmentData(false).toEmail();

Preserve cancellation from acquiring, reading or closing the selected report stream, including typed interruption and interrupted causes or suppressed failures. Use the existing conversion interruption rules; an ordinary socket timeout remains eligible for optional recovery. Preserve the caller's thread state and original failure context.

Keep completed report blocks and warnings after ordinary I/O failure, without treating a partial recipient block as complete. Unexpected application failures retain their exception behavior. This completes the unreleased report feature under ADR 0035, alongside ADR 0036 and ADR 0041. No new API or recovery setting is added.


Goal

Expose structured delivery-status report facts through the existing Email gateway. Applications convert incoming MIME/EML through the usual converter, then inspect Email.getDeliveryStatusReport(); no separate report-converter API.

Email notification = mail.converter().mimeMessageToEmailBuilder(incomingMessage).buildEmail();
DeliveryStatusReport report = notification.getDeliveryStatusReport();
if (report != null) {
    applicationWorkflow.accept(report);
}

Delivered design

  • Immutable, serializable core read contracts: DeliveryStatusReport, RecipientDeliveryReport, DeliveryAction, EnhancedStatusCode, ReportedRecipient, ReportedMailServer and DeliveryDiagnostic. Internal Lombok builders assemble the snapshots in the main module.
  • Interpret standard and internationalized delivery-status MIME structures after existing protection processing. Only the effective outer notification supplies a report; attached or forwarded reports are not promoted.
  • Expose ENVID, reporting server, ordered recipient occurrences, action, checked enhanced-status components, reported addresses, diagnostics and timestamps. Optional Recipient and SmtpServerResponse views avoid re-parsing familiar formats while preserving unfamiliar source values.
  • Read imperfect mail tolerantly: recover unambiguous formatting defects with warnings, retain completed facts after optional report extraction fails, and leave missing, contradictory or ambiguous facts unavailable. An interrupted block is not presented as complete. Required content reads, thread interruption and unexpected runtime failures retain their existing failure behavior.
  • Preserve copying, serialization, exact/protected source bytes and attachment behavior. Snapshots retain no live MIME objects or streams. Templates cannot manufacture received report metadata; replies and forwards do not inherit it.
  • Reports are received claims, not authenticated delivery proof, read receipts or automatic retry instructions. Ingestion, trust, correlation, persistence and business actions remain application-owned.
  • No new property, outgoing default/override/lock, CLI command, receiver, workflow engine or JSON dependency.

Architecture and usage

Related: #736, #738, #710, #723, #756. Comparison context: the SMTP-library research companion.

The integration/Strategic Patterns portfolio remains separately tracked under #764. Its pending code, documentation and Journal/case-study changes are not part of this delivery.

Implemented for unreleased 10.0.0 on the existing feature branches; this issue does not authorize a release or completion of #764.

Activity

  1. added this to the 10.0.0 milestone on Oct 16, 2026
  2. bbottema commented on Oct 16, 2026

    @bbottema
    OwnerAuthor

    Companion pattern-led Docker integration programme: #764. Implementation plan: docs/plans/763-delivery-status-reports.md. ADR 0008 will record the source-metadata boundary.

  3. moved this from Todo to In Progress in Simple Java Mail 10.0.0on Oct 16, 2026
  4. bbottema commented on Oct 16, 2026

    @bbottema
    OwnerAuthor

    Delivery-status reports are implemented for the unreleased 10.0.0 development branch.

    The converted Email exposes the received report through its ordinary API:

    Email notification = mail.converter().fromMimeMessage(incomingMessage).toEmail();
    DeliveryStatusReport report = notification.getDeliveryStatusReport();
    if (report != null) {
        System.out.println(report);
        for (RecipientDeliveryReport recipient : report.getRecipients()) {
            System.out.println(recipient.getAction() + " " + recipient.getStatusCode());
        }
    }

    Example summary: DeliveryStatusReport{recipients=3, delivered=1, delayed=1, failed=1, warnings=0}.

    The report model preserves standard and international fields, warnings and available source facts through copying and serialization. Reports remain received claims, not authenticated proof, a mutation of an earlier receipt, or automatic retry instructions.

    See ADR 0035 for tolerant-reading behavior and the delivery-report guide for usage. Application-owned integration remains separately tracked under #764.

  5. bbottema commented on Oct 18, 2026

    @bbottema
    OwnerAuthor

    Implemented and accepted for 10.0.0. Convert a received notification as usual, then inspect its typed delivery report:

    Email notification = SimpleJavaMail.fromDefaults()
            .converter()
            .mimeMessageToEmailBuilder(incomingMessage)
            .buildEmail();
    
    DeliveryStatusReport report = notification.getDeliveryStatusReport();
    if (report != null) {
        System.out.println("Envelope ID: " + report.getEnvelopeId());
        for (RecipientDeliveryReport recipient : report.getRecipients()) {
            System.out.println(recipient.getAction() + " " + recipient.getStatusCode());
            ReportedRecipient target = recipient.getFinalRecipient();
            if (target != null && target.getMailbox() != null) {
                System.out.println(target.getMailbox().getAddress());
            }
        }
        report.getWarnings().forEach(System.out::println);
    }

    incomingMessage is the application's received MimeMessage. An ordinary email has no report. Optional fields can be absent; unfamiliar address/diagnostic formats retain their original values rather than being forced into a mailbox or SMTP reply.

    Malformed notifications keep whatever can be interpreted safely, with warnings. Ambiguous facts remain unavailable, and exact/protected source bytes stay authoritative. The application still decides whether to trust the notification, which submission it belongs to, and what action to take; a report is not an automatic retry instruction.

    Pushed as implementation, architecture, guidance and comparison progress, and the website walkthrough.

    The integration/Strategic Patterns work remains untouched under #764. This completes #763, not a published 10.0.0 release.

  6. moved this from In Progress to Done in Simple Java Mail 10.0.0on Oct 18, 2026
  7. 23 remaining items

  8. bbottema commented on Nov 1, 2026

    @bbottema
    OwnerAuthor

    Development addenda for unreleased 10.0.0

    These follow-ups complete this feature's 10.0.0 implementation. Dates identify the original development records; before examples describe earlier development revisions.

    2026-10-21: Keep historical received-mail results out of template completion

    Template completion should prepare outgoing content and sending choices. It should not copy results learned when an earlier message was received. At the reviewed unreleased 10.0.0 revision 8d1bfd64ed6497edccfacc9675b51b270af98ef4, crypto receive results are already omitted, but an interpreted received delivery-status report is copied into the completed Email.

    Email received = mail.converter().fromEml(reportEml).toEmail();
    Email completed = mailer.getEmailGovernance()
        .produceEmailApplyingDefaultsAndOverrides(received);
    // Before: completed.getDeliveryStatusReport() is the received report.

    The maintainer clarified on 21 October 2026 that completion carries outgoing protection configuration, not historical crypto results, and that this rule applies to every historical result exposed by Email. S/MIME/OpenPGP signing and encryption, DKIM signing, and outgoing delivery-notification requests retain their existing precedence, suppression and lock rules. Applying completion does not perform cryptography itself.

    Audit original S/MIME results, original OpenPGP results and their preserved original-byte snapshots, interpreted delivery reports, decrypted-attachment result views, and the retained S/MIME signed-message interpretation. The completed composed Email should have absent/plain/empty historical-result views, whether the facts occur on the supplied Email, a default or an override. Ordinary outgoing body/header/resource content remains content; this is not a rule to delete imported message content.

    Reading incoming mail, ordinary copying and supported serialization keep their current historical inspection contracts. Automatic exact-Email sending/rehearsal/export retains its authoritative source; explicit template completion remains composed as clarified in #818. No public construction or new provenance API is needed.

    Reconcile ADR 0002, ADR 0008, ADR 0036 and ADR 0037, public Javadocs and applicable website/migration guidance.

    The maintainer approved the documentation and historical-field audit, then explicitly approved removing the received-report carryover on 21 October 2026.

    Message content, outgoing headers/resources, fixed Message-ID/date, envelope/recipient choices, protection configurations and outgoing notification requests are not historical-result fields. Outlook-specific data is returned by a separate conversion result and is not an additional Email history property.

    The only runtime change removes the four-line transfer of the supplied received DeliveryStatusReport. Completion now omits all five audited history groups. Existing content and exact-source behavior remain intact.

    No Java signature, property, Spring binding or CLI-cache change was needed. Input copying/serialization retain their existing supported contract; the unreleased received-report correction adds no invented 9.x migration recipe.

    Delivered in main commit b1e71672 on codex/10.0.0 and website commit 9257df6 on codex/10.0.0-content after the maintainer authorized completion of the workflow. Version 10.0.0 remains unreleased.

    Completed behavior — 2026-10-21

    Email received = mail.converter().fromEml(reportEml).toEmail();
    Email completed = mailer.getEmailGovernance()
        .produceEmailApplyingDefaultsAndOverrides(received);
    // completed.getDeliveryStatusReport() == null
    // received.getDeliveryStatusReport() remains available

    Completion now leaves all audited historical result views with the source Email. Outgoing S/MIME/OpenPGP protection settings, DKIM signing and delivery-notification requests still follow their existing precedence, suppression and lock rules. Ordinary content, copying, serialization and original exact-Email preparation keep their established contracts.

    The only runtime correction removes the received-report transfer; the other historical result families already followed this rule.

    Delivered in main commit b1e71672 and website commit 9257df6. ADR 0002, ADR 0008, ADR 0036 and ADR 0037, public Javadocs, website guides, target-only migration fixtures and the unreleased release note agree.

    This completes the reviewed work on codex/10.0.0 and codex/10.0.0-content. Version 10.0.0 has not been released.

    2026-10-28: Keep delivery-report timestamps with trailing comments

    A valid delivery-report timestamp becomes unavailable when a harmless trailing comment follows its numeric timezone.

    Last-Attempt-Date: Fri, 16 Oct 2026 10:20:30 +0200 (CEST)
    

    After importing the delivery report, the recipient's getLastAttemptAt() returns no timestamp and the report calls the date invalid. Will-Retry-Until has the same problem.

    Accept well-formed trailing comments and whitespace while retaining strict calendar and timezone interpretation. Malformed comments, extra non-comment text, impossible dates and missing or invalid zones must not invent a timestamp. Keep the existing ISO-date recovery behavior and neighboring report facts.

    This follows ADR 0035 for 10.0.0.

    Completed behavior — 2026-10-28

    Last-Attempt-Date: Fri, 16 Oct 2026 10:20:30 +0200 (CEST)
    

    The recipient's getLastAttemptAt() now retains 2026-10-16T08:20:30Z; Will-Retry-Until follows the same rule through getRetryUntil(). Well-formed trailing comments and whitespace do not add a recovery warning. Invalid suffixes, calendars and timezones still leave the timestamp unavailable, and exact input bytes remain authoritative.

    Implemented on the 10.0.0 development branch in 1db04659c, following ADR 0035. This is not a published 10.0.0 release.

    Documentation: website companion and maintained guidance.

    2026-10-29: Leave delivery-report dates unavailable when timezone hours are invalid

    Delivery reports can turn an impossible timezone into an apparently usable timestamp. For example, a report containing this field produces a nonnull getLastAttemptAt() after ordinary Email conversion:

    Last-Attempt-Date: Fri, 16 Oct 2026 10:20:30 +9900
    

    Will-Retry-Until has the same problem. Applications reading those results can receive dates shifted by several days even though the supplied timezone is invalid.

    Reject numeric timezone hours outside 00 through 23 for both fields. Leave the timestamp unavailable and retain the existing invalid-date warning, neighboring recipient facts and original report content. Keep valid numeric offsets, strict calendar interpretation, well-formed trailing comments and the existing ISO-date recovery behavior.

    This follows ADR 0035 for unreleased 10.0.0 and completes the invalid-zone boundary described under #763.

    Completed behavior — 2026-10-29

    Email email = mail.converter().fromEml(notification).toEmail();
    RecipientDeliveryReport recipient =
        email.getDeliveryStatusReport().getRecipients().get(0);
    
    Instant attemptedAt = recipient.getLastAttemptAt();
    Instant retryUntil = recipient.getRetryUntil();

    A report field with an invalid numeric timezone such as +9900, +2400 or -2400 now leaves its corresponding timestamp null and adds the existing invalid-date warning. Valid offsets, trailing comments, ISO dates, neighboring report facts and original report content retain their behavior.

    Implemented for unreleased 10.0.0 in 01f5eaf70, following ADR 0035. The shared documentation and website guidance describe the same behavior.

    2026-10-29: Read delivery-report actions with valid comments

    A delivery report can give a clear action with a valid comment, but importing it currently reports UNKNOWN because the parser includes the comment when looking up the action.

    Final-Recipient: rfc822; reader@example.org
    Action: failed (recipient removed)
    Status: 5.1.1
    
    DeliveryAction action = mail.converter().fromEml(dsn).toEmail()
        .getDeliveryStatusReport().getRecipients().get(0).getAction();
    // Currently UNKNOWN; the reported action is FAILED.

    Read exactly one recognized action token while ignoring well-formed external comments and whitespace. Apply this to all five standard actions, retaining case-insensitive interpretation and adding no warning for valid comments. Missing or unknown actions, extra tokens, quoted values, malformed comments and existing contradictory-field cases must remain unavailable through UNKNOWN and the existing warnings.

    Preserve the original report content, exact/protected bytes, neighboring recipient facts and the existing duplicate-field rules. This changes no public API or configuration.

    This follows RFC 3464 section 2.1.1, ADR 0035 and ADR 0008, for the unreleased 10.0.0 branch.

    Completed behavior — 2026-10-29

    DeliveryAction action = mail.converter().fromEml(dsn).toEmail()
        .getDeliveryStatusReport().getRecipients().get(0).getAction();
    // FAILED for the original Action: failed (recipient removed) example.

    A recognized action now remains available when the field contains valid external comments or whitespace. All five standard actions retain case-insensitive interpretation. Unknown actions, quoted values, malformed comments and competing tokens still produce UNKNOWN, and duplicate-field handling and original report content keep their existing behavior.

    Delivered on the unreleased codex/10.0.0 branch in dd7026c9, with the matching website guidance in c8838b54. ADR 0035 records the clarification under the existing source-fact boundary in ADR 0008. No public API or configuration changed.

  9. moved this from Done to In Progress in Simple Java Mail 10.0.0on Nov 6, 2026
  10. bbottema commented on Nov 6, 2026

    @bbottema
    OwnerAuthor
    try {
        Email received = mail.converter().fromMimeMessage(notification)
            .withFetchAttachmentData(false).toEmail();
        DeliveryStatusReport report = received.getDeliveryStatusReport();
        // Inspect any completed report facts and warnings.
    } catch (CancellationException cancelled) {
        // Stop processing this input; cancellation is not a successful import.
        throw cancelled;
    }

    This follow-up is implemented on the unreleased 10.0.0 development branch. Acquiring, reading or closing the optional delivery-status stream now keeps typed interruption outside best-effort recovery, including interrupted causes and suppressed cleanup failures when the thread's interrupt flag is clear. The caller's thread state stays unchanged.

    Ordinary I/O failures and socket timeouts still retain completed report blocks and an incomplete-extraction warning. An unfinished recipient block does not become a complete fact, and unrelated application failures keep their exception behavior.

    The implementation is in 9c7d5df, with the usage guidance in d900443. The behavior follows ADR 0035, ADR 0036 and ADR 0041.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions