Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
MailMessageDetailDto
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
3 / 3
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isAuthentic
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 getDownloadableAttachments
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5/** @license For full copyright and license information, please see the LICENSE.md file. */
6
7namespace App\Modules\Mail\Domain\Model;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11/**
12 * Mail Message Detail Data Transfer Object.
13 *
14 * Encapsulates the complete message payload for isolated reading: sanitized HTML body,
15 * fallback plain-text, attachments collection, and authentication inspection badges (SPF/DKIM/DMARC).
16 *
17 * @package App\Modules\Mail\Domain\Model
18 */
19final readonly class MailMessageDetailDto
20{
21    /**
22     * MailMessageDetailDto constructor.
23     *
24     * @param MailMessageSummaryDto          $summary          Lightweight header summary.
25     * @param string                         $htmlBody         Sanitized HTML body content.
26     * @param string                         $textBody         Plain-text fallback body.
27     * @param array<MailAttachmentDto>       $attachments      Parsed message attachments.
28     * @param array<string, mixed>           $headers          Key-value raw email headers.
29     * @param array<string>                  $replyTo          Reply-to address collection.
30     * @param array<string>                  $bcc              BCC address collection.
31     * @param string                         $spfStatus        SPF check status ('pass', 'fail', 'none').
32     * @param string                         $dkimStatus       DKIM signature status ('pass', 'fail', 'none').
33     * @param string                         $dmarcStatus      DMARC policy status ('pass', 'fail', 'none').
34     * @param bool                           $hasBlockedImages Whether remote images were blocked.
35     */
36    public function __construct(
37        public MailMessageSummaryDto $summary,
38        public string $htmlBody = '',
39        public string $textBody = '',
40        public array $attachments = [],
41        public array $headers = [],
42        public array $replyTo = [],
43        public array $bcc = [],
44        public string $spfStatus = 'none',
45        public string $dkimStatus = 'none',
46        public string $dmarcStatus = 'none',
47        public bool $hasBlockedImages = false
48    ) {
49    }
50
51    /**
52     * Returns whether email passed both SPF and DKIM checks.
53     *
54     * @return bool True if fully authenticated.
55     */
56    public function isAuthentic(): bool
57    {
58        return $this->spfStatus === 'pass' && $this->dkimStatus === 'pass';
59    }
60
61    /**
62     * Returns downloadable, non-inline attachments.
63     *
64     * @return array<MailAttachmentDto> Non-inline attachments.
65     */
66    public function getDownloadableAttachments(): array
67    {
68        return array_values(array_filter(
69            $this->attachments,
70            static fn (MailAttachmentDto $att): bool => !$att->isInline
71        ));
72    }
73}