Skip to content

Commit

Permalink
Merge pull request #270 from opcodesio/bug/mail-preview-improvements
Browse files Browse the repository at this point in the history
bug fixes for mail previews
  • Loading branch information
arukompas authored Aug 25, 2023
2 parents 579d5f4 + a960413 commit 1e27934
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/Logs/LaravelLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,25 @@ protected function extractContextsFromFullText(): void

protected function extractMailPreview(): void
{
$isMail = Str::contains($this->text, 'To:')
&& Str::contains($this->text, 'From:')
&& Str::contains($this->text, 'MIME-Version: 1.0');
$possibleParts = preg_split('/[^\r]\n/', $this->text);
$part = null;

foreach ($possibleParts as $possiblePart) {
if (
Str::contains($this->text, 'To:')
&& Str::contains($this->text, 'From:')
&& Str::contains($this->text, 'MIME-Version: 1.0')
) {
$part = $possiblePart;
break;
}
}

if (! $isMail) {
if (! $part) {
return;
}

$message = Message::fromString($this->text);
$message = Message::fromString($part);

$this->extra['mail_preview'] = [
'id' => $message->getId() ?: null,
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/LaravelLogs/LaravelLogsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
------=_Part_1_1234567890--
EOF;
// The email string (as per RFC 5322) actually needs to use \r\n sequence instead of \n
$messageString = str_replace("\n", "\r\n", $messageString);

$log = new LaravelLog($messageString);

Expand Down

0 comments on commit 1e27934

Please sign in to comment.