Core\Mail\Message::Kind
What a received message is, as Core\Mail\Message::kind() returns it.
The six cases are Bounce, Delay, Complaint, AutoReply, Reply and Other. A Bounce is a delivery report where at least one address failed. A Delay is a delivery report where a delivery is late, and the server still tries. A Complaint is a report that a reader marked your mail as spam. An AutoReply is a message that a program wrote, such as an out-of-office reply. A Reply has an In-Reply-To header. Every other message is Other.
Good to know: the cases are checked in this order, and the first match is the kind. So an out-of-office reply with In-Reply-To is an AutoReply, not a Reply. Compare a kind with ==, or use match to handle each case.
Examples
One message of each kind
<?nvs// Shows one message of each kind, and what a program usually does with it.
use Core\Mail\Message;
class Handle{ public static function kind(Message::Kind $kind): string { return match ($kind) { Message::Kind::Bounce => 'Bounce: stop sending to the failed address', Message::Kind::Delay => 'Delay: wait, the server tries again', Message::Kind::Complaint => 'Complaint: stop sending newsletters to this reader', Message::Kind::AutoReply => 'AutoReply: ignore it', Message::Kind::Reply => 'Reply: add it to the conversation', Message::Kind::Other => 'Other: read it as a new message', }; }}
class Sample{ // `report` returns a report of the given type, with one part. public static function report(string $type, string $part): string { return "From: mailer-daemon@mx.example.net\nSubject: Report\n" . 'Content-Type: multipart/report; report-type=' . $type . "; boundary=\"b\"\n\n" . "--b\n" . $part . "--b--\n"; }
// `status` returns the part of a delivery report, with one recipient and the given action. public static function status(string $action): string { return "Content-Type: message/delivery-status\n\nReporting-MTA: dns; mx.example.net\n\n" . "Final-Recipient: rfc822; ada@example.org\nAction: " . $action . "\n"; }}
array<string> $messages = [ Sample::report('delivery-status', Sample::status('failed')), Sample::report('delivery-status', Sample::status('delayed')), Sample::report('feedback-report', "Content-Type: message/feedback-report\n\nFeedback-Type: abuse\n"), // The kinds are checked in this order: `Bounce`, `Delay`, `Complaint`, `AutoReply`, `Reply`, `Other`. // This message has `In-Reply-To` too, but `AutoReply` is checked before `Reply`. "From: bo@example.org\nAuto-Submitted: auto-replied\nIn-Reply-To: <a1@example.com>\n\nI am away.\n", "From: cy@example.org\nIn-Reply-To: <a1@example.com>\n\nYes, thank you.\n", "From: dee@example.org\nSubject: A question\n\nHello.\n",];
foreach ($messages as string $raw) { echo Handle::kind(Message::parse($raw)->kind()), "\n";}Bounce: stop sending to the failed addressDelay: wait, the server tries againComplaint: stop sending newsletters to this readerAutoReply: ignore itReply: add it to the conversationOther: read it as a new messageChangelog
| Version | Change |
|---|---|
0.0.6 | Core\Mail\Message::kind returns what kind of message it is: a bounce, a delay, a complaint, an automatic reply, a reply or other. A bounce is a message from a mail server that says your mail could not be delivered. answers() returns the message id of the mail it is about, so you can find the mail you sent. |
