diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a50f7fcbf..59955640b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -21,7 +21,12 @@ jobs: fail-fast: true matrix: php: [7.3, 7.4, 8.0, 8.1] - laravel: [^8.0] + laravel: [^8.0, ^9.0] + exclude: + - php: 7.3 + laravel: ^9.0 + - php: 7.4 + laravel: ^9.0 name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} diff --git a/composer.json b/composer.json index 8cf90a5cb..73a1b197f 100644 --- a/composer.json +++ b/composer.json @@ -16,12 +16,12 @@ "require": { "php": "^7.3|^8.0", "ext-json": "*", - "laravel/framework": "^8.29", - "symfony/var-dumper": "^5.0" + "laravel/framework": "^8.29|^9.0", + "symfony/var-dumper": "^5.0|^6.0" }, "require-dev": { "ext-gd": "*", - "orchestra/testbench": "^6.0" + "orchestra/testbench": "^6.0|^7.0" }, "autoload": { "psr-4": { diff --git a/src/Watchers/MailWatcher.php b/src/Watchers/MailWatcher.php index 89408445f..6fd3167ef 100644 --- a/src/Watchers/MailWatcher.php +++ b/src/Watchers/MailWatcher.php @@ -5,6 +5,8 @@ use Illuminate\Mail\Events\MessageSent; use Laravel\Telescope\IncomingEntry; use Laravel\Telescope\Telescope; +use Symfony\Component\Mime\Address; +use Symfony\Component\Mime\Part\AbstractPart; class MailWatcher extends Watcher { @@ -31,16 +33,18 @@ public function recordMail(MessageSent $event) return; } + $body = $event->message->getBody(); + Telescope::recordMail(IncomingEntry::make([ 'mailable' => $this->getMailable($event), 'queued' => $this->getQueuedStatus($event), - 'from' => $event->message->getFrom(), - 'replyTo' => $event->message->getReplyTo(), - 'to' => $event->message->getTo(), - 'cc' => $event->message->getCc(), - 'bcc' => $event->message->getBcc(), + 'from' => $this->formatAddresses($event->message->getFrom()), + 'replyTo' => $this->formatAddresses($event->message->getReplyTo()), + 'to' => $this->formatAddresses($event->message->getTo()), + 'cc' => $this->formatAddresses($event->message->getCc()), + 'bcc' => $this->formatAddresses($event->message->getBcc()), 'subject' => $event->message->getSubject(), - 'html' => $event->message->getBody(), + 'html' => $body instanceof AbstractPart ? $body->bodyToString() : $body, 'raw' => $event->message->toString(), ])->tags($this->tags($event->message, $event->data))); } @@ -75,6 +79,27 @@ protected function getQueuedStatus($event) return $event->data['__telescope_queued'] ?? false; } + /** + * Convert the given addresses into a readable format. + * + * @param array|null $addresses + * @return array|null + */ + protected function formatAddresses(?array $addresses) + { + if (is_null($addresses)) { + return null; + } + + return collect($addresses)->flatMap(function ($address, $key) { + if ($address instanceof Address) { + return [$address->getAddress() => $address->getName()]; + } + + return [$key => $address]; + })->all(); + } + /** * Extract the tags from the message. *