Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd4a87d2

Browse files
flackfabpot
authored andcommitted
[Mime] Fix embed logic for background attributes
1 parent6e3d5c1 commitd4a87d2

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

‎src/Symfony/Component/Mime/Email.php‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,17 @@ private function prepareParts(): ?array
460460
if (null !==$this->html) {
461461
$htmlPart =newTextPart($html,$this->htmlCharset,'html');
462462
$html =$htmlPart->getBody();
463-
preg_match_all('(<img\s+[^>]*src\s*=\s*(?:([\'"])cid:([^"]+)\\1|cid:([^>\s]+)))i',$html,$names);
464-
$names =array_filter(array_unique(array_merge($names[2],$names[3])));
463+
464+
$regexes = [
465+
'<img\s+[^>]*src\s*=\s*(?:([\'"])cid:([^"]+)\\1|cid:([^>\s]+))',
466+
'<\w+\s+[^>]*background\s*=\s*(?:([\'"])cid:([^"]+)\\1|cid:([^>\s]+))',
467+
];
468+
$tmpMatches = [];
469+
foreach ($regexesas$regex) {
470+
preg_match_all('/'.$regex.'/i',$html,$tmpMatches);
471+
$names =array_merge($names,$tmpMatches[2],$tmpMatches[3]);
472+
}
473+
$names =array_filter(array_unique($names));
465474
}
466475

467476
$attachmentParts =$inlineParts = [];

‎src/Symfony/Component/Mime/Tests/EmailTest.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,14 @@ public function testGenerateBody()
351351
// 2 parts only, not 3 (text + embedded image once)
352352
$this->assertCount(2,$parts =$body->getParts());
353353
$this->assertStringMatchesFormat('html content <img src=3D"cid:%s@symfony">',$parts[0]->bodyToString());
354+
355+
$e = (newEmail())->from('me@example.com')->to('you@example.com');
356+
$e->html('<div background="cid:test.gif"></div>');
357+
$e->embed($image,'test.gif');
358+
$body =$e->getBody();
359+
$this->assertInstanceOf(RelatedPart::class,$body);
360+
$this->assertCount(2,$parts =$body->getParts());
361+
$this->assertStringMatchesFormat('<div background=3D"cid:%s@symfony"></div>',$parts[0]->bodyToString());
354362
}
355363

356364
publicfunctiontestAttachments()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp