$headers lower-cased header names * @param array $attachments */ public function __construct( public readonly string $fromEmail, public readonly string $fromName, public readonly string $subject, public readonly string $textBody, public readonly string $htmlBody, public readonly array $headers, public readonly array $attachments = [], ) {} /** * Treats an empty string the same as an absent header — the IMAP * library backing ImapMailboxFetcher represents "header not present" as * an empty value rather than a missing array key in some cases, so * callers checking `header($x) !== null` alone would otherwise * misdetect every message as carrying every header. */ public function header(string $name): ?string { $value = $this->headers[strtolower($name)] ?? null; return $value !== null && $value !== '' ? $value : null; } public function body(): string { if (trim($this->textBody) !== '') { return $this->textBody; } return trim(html_entity_decode(strip_tags($this->htmlBody))); } }