Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Mail/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,13 @@ public function setHtmlBody(string $html, ?string $basePath = null): static
|<body[^<>]*\s background\s*=\s*
|<[^<>]+\s style\s*=\s* ["\'][^"\'>]+[:\s] url\(
|<style[^>]*>[^<]+ [:\s] url\()
(["\']?)(?![a-z]+:|[/\#])([^"\'>)\s]+)
(["\']?)(?![a-z]+:|[\#])([^"\'>)\s]+)
|\[\[ ([\w()+./@~-]+) \]\]
#ix',
captureOffset: true,
);
foreach (array_reverse($matches) as $m) {
$file = rtrim($basePath, '/\\') . '/' . (isset($m[4]) ? $m[4][0] : urldecode($m[3][0]));
$file = rtrim($basePath, '/\\') . '/' . ltrim(isset($m[4]) ? $m[4][0] : urldecode($m[3][0]), '/\\');
if (!isset($cids[$file])) {
$cids[$file] = substr($this->addEmbeddedFile($file)->getHeader('Content-ID'), 1, -1);
}
Expand Down
43 changes: 43 additions & 0 deletions tests/Mail/Mail.textualAndHtmlBody.embedded.expect3
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
MIME-Version: 1.0
X-Mailer: Nette Framework
Date: %a%
From: John Doe <doe@example.com>
To: Lady Jane <jane@example.com>
Subject: Hello Jane!
Message-ID: <%S%@%S%>
Content-Type: multipart/alternative;
boundary="--------%S%"

----------%S%
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

Sample text
----------%S%
Content-Type: multipart/related;
boundary="--------%S%"

----------%S%
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit

<BODY id=1 background="cid:%S%">
<img src="cid:%S%">
<div title=a style="background:url('cid:%S%')">
<style type=text/css>body { background: url('cid:%S%') } </style>
cid:%S%

----------%S%
Content-Type: image/png
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename="background.png"
Content-ID: <%S%>

iVBORw0KGgoAAAANSUhEUgAABAAAAAAGCAMAAABq1Ry/AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJ
bWFnZVJlYWR5ccllPAAAADlQTFRFIYzeKYzeMZTeOZTeQpTeQpzeSpzeUpzeY6Xee73nhL3nlMbn
nMbnrc7nvdbvxt7v1ufv5+fv7+/vqVk59gAAAKFJREFUeNrsmMEKgzAQRHcTq63WJPr/H9ska4vQ
2rOG5+CEgT0JPiYrqiKiJue723Afp+ccQlqWFSHUtqQCQCoFVF0BwCMDYI4p8XUQal3269ubAeB7
A0CI1gBWDMMattIA1BBQAdC9G0DcrgAfVuwPDMOaMHGqtgEo5o8bwDcKiETi1aP4QoDtyQWgtyXg
bgdwzIDfxeBfYphhhk81/BJgAHfwneqeqMofAAAAAElFTkSuQmCC
----------%S%--
----------%S%--
22 changes: 20 additions & 2 deletions tests/Mail/Mail.textualAndHtmlBody.embedded.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ $mailer->send($mail);

Assert::matchFile(__DIR__ . '/Mail.textualAndHtmlBody.embedded.expect', TestMailer::$output);



$mail = new Message;
$mail->setHTMLBody("
<a href='test.php?src=SOME'>some link</a>
Expand All @@ -53,3 +51,23 @@ $mailer = new TestMailer;
$mailer->send($mail);

Assert::matchFile(__DIR__ . '/Mail.textualAndHtmlBody.embedded2.expect', TestMailer::$output);

$mail = new Message;

$mail->setFrom('John Doe <doe@example.com>');
$mail->addTo('Lady Jane <jane@example.com>');
$mail->setSubject('Hello Jane!');

$mail->setBody('Sample text');
$mail->setHTMLBody('
<BODY id=1 background="/background.png">
<img src="/backgroun%64.png">
<div title=a style="background:url(\'/background.png\')">
<style type=text/css>body { background: url(\'/background.png\') } </style>
[[background.png]]
', __DIR__ . '/fixtures');
// append automatically $mail->addEmbeddedFile('files/background.png');

$mailer = new TestMailer;
$mailer->send($mail);
Assert::matchFile(__DIR__ . '/Mail.textualAndHtmlBody.embedded.expect3', $mailer::$output);