Skip to content

Commit

Permalink
Merge pull request #10 from xima-media/cc-bcc-fields
Browse files Browse the repository at this point in the history
Add cc and bcc fields to log output
  • Loading branch information
maikschneider authored Jun 28, 2023
2 parents a2a35b9 + e10a89b commit 2e63f07
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
30 changes: 30 additions & 0 deletions Classes/Domain/Model/Dto/MailMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ class MailMessage

public string $toName = '';

/**
* @var array{name: string, email: string}[]
*/
public array $ccRecipients = [];

/**
* @var array{name: string, email: string}[]
*/
public array $bccRecipients = [];

public string $bodyPlain = '';

public string $bodyHtml = '';
Expand Down Expand Up @@ -65,4 +75,24 @@ public function getDisplayToAddress(): string
}
return $this->to;
}

public function getDisplayCcRecipients(): string
{
$displayArray = [];
foreach ($this->ccRecipients as $recipient) {
$displayArray[] = $recipient['name'] . ' <' . $recipient['email'] . '>';
}

return implode(', ', $displayArray);
}

public function getDisplayBccRecipients(): string
{
$displayArray = [];
foreach ($this->bccRecipients as $recipient) {
$displayArray[] = $recipient['name'] . ' <' . $recipient['email'] . '>';
}

return implode(', ', $displayArray);
}
}
16 changes: 16 additions & 0 deletions Classes/Utility/LogParserUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,22 @@ protected static function convertToDto(string $msg): MailMessage
$dto->to = $toAddresses[0]['address'] ?? '';
}

$ccAddresses = $parser->getAddresses('cc');
foreach ($ccAddresses as $address) {
$dto->ccRecipients[] = [
'name' => $address['display'] ?? '',
'email' => $address['address'] ?? '',
];
}

$bccAddresses = $parser->getAddresses('bcc');
foreach ($bccAddresses as $address) {
$dto->bccRecipients[] = [
'name' => $address['display'] ?? '',
'email' => $address['address'] ?? '',
];
}

$headers = $parser->getHeaders();
$dto->subject = $headers['subject'] ?? '';
$dto->messageId = md5($headers['message-id'] ?? '');
Expand Down
5 changes: 4 additions & 1 deletion Resources/Private/Templates/Backend/Index.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ <h1>Mail Log</h1>
<div class="tab-header">
<div class="row">
<div class="col">
<span><strong>To:</strong> {mail.displayToAddress}<br/><strong>Date:</strong>
<span><strong>To:</strong> {mail.displayToAddress}<br/>
<f:if condition="{mail.displayCcRecipients}"><strong>Cc:</strong> {mail.displayCcRecipients}<br/></f:if>
<f:if condition="{mail.displayBccRecipients}"><strong>Bcc:</strong> {mail.displayBccRecipients}<br/></f:if>
<strong>Date:</strong>
<f:format.date format="H:i, d.m.Y">{mail.date}</f:format.date>
</span>
</div>
Expand Down

0 comments on commit 2e63f07

Please sign in to comment.