Skip to content

Commit

Permalink
fix signed urls in logged mailables
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed May 2, 2024
1 parent 8888778 commit 1f07805
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ docs
phpunit.xml
psalm.xml
vendor
.phpunit.cache
48 changes: 19 additions & 29 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,31 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
verbose="true"
>
<testsuites>
<testsuite name="Spatie Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<php>
<env name="APP_DEBUG" value="true" />
<env name="CACHE_DRIVER" value="array" />
<env name="CACHE_STORE" value="array" />
</php>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Spatie Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<php>
<env name="APP_DEBUG" value="true"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="CACHE_STORE" value="array"/>
</php>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
17 changes: 16 additions & 1 deletion src/Payloads/LoggedMailPayload.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace Spatie\LaravelRay\Payloads;

use Psy\Util\Str;
use Spatie\Ray\Payloads\Payload;
use ZBateson\MailMimeParser\Header\AddressHeader;
use ZBateson\MailMimeParser\Header\HeaderConsts;
use ZBateson\MailMimeParser\Header\Part\AddressPart;
use ZBateson\MailMimeParser\IMessage;
use ZBateson\MailMimeParser\MailMimeParser;

class LoggedMailPayload extends Payload
Expand Down Expand Up @@ -34,7 +36,9 @@ public static function forLoggedMail(string $loggedMail): self

$message = $parser->parse($loggedMail, true);

$content = $message->getContent() ?? $message->getHtmlContent() ?? '';
// get the part in $loggedMail that starts with <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0

$content = self::getMailContent($loggedMail, $message);

return new self(
$content,
Expand Down Expand Up @@ -62,6 +66,17 @@ public function __construct(
$this->bcc = $bcc;
}

protected static function getMailContent(string $loggedMail, IMessage $message): string
{
$startOfHtml = strpos($loggedMail, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0', true);

if (! $startOfHtml) {
return $message->getContent() ?? $message->getHtmlContent() ?? '';
}

return substr($loggedMail, $startOfHtml) ?? '';
}

public function getType(): string
{
return 'mailable';
Expand Down

0 comments on commit 1f07805

Please sign in to comment.