Karta.Bounces.DSN (Karta v1.0.0)

Reading delivery status notifications (RFC 3464) and the common bounces that are not one.

parse/1 takes a whole message and returns a Karta.Bounces.DSN.Report:

  • a message/delivery-status (or message/global-delivery-status) part is read as the standard says: the first block of fields is the report's (Reporting-MTA, Original-Envelope-Id, Arrival-Date), each later block one recipient's (Final-Recipient, Original-Recipient, Action, Status, Remote-MTA, Diagnostic-Code). The Action and the enhanced status of RFC 3463 decide whether the failure is permanent (5.x.x) or temporary (4.x.x); a delivered or relayed recipient is a success notice, not a bounce.
  • without such a part, the message is a bounce of the kind some systems send: the first enhanced or three-digit status in its subject and plain-text parts decides. Anything unreadable is :unknown, which Karta treats as temporary rather than suppressing an address on a guess.

A feedback report (RFC 5965, a message/feedback-report part) is not a bounce and is refused as :feedback_report (Karta.Complaints.ARF reads it). Parsing is bounded: the MIME tree at most 10 deep and 50 parts, a delivery-status part at most 262,144 bytes and 20 recipients, and the text searched at most 65,536 bytes.

Summary

Functions

Reads a bounce. {:ok, report}, or {:error, reason} with reason :feedback_report (not a bounce), :no_recipients (a delivery-status part without a group), :too_many_recipients, :too_large, or what Karta.Mail.Message.parse/2 says about an unreadable message.

Functions

parse(raw)

@spec parse(binary()) ::
  {:ok, Karta.Bounces.DSN.Report.t()}
  | {:error,
     :feedback_report
     | :no_recipients
     | :too_many_recipients
     | :too_large
     | atom()}

Reads a bounce. {:ok, report}, or {:error, reason} with reason :feedback_report (not a bounce), :no_recipients (a delivery-status part without a group), :too_many_recipients, :too_large, or what Karta.Mail.Message.parse/2 says about an unreadable message.