File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed
src/Symfony/Component/Mime Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -460,8 +460,17 @@ private function prepareParts(): ?array
460460 if (null !== $ this ->html ) {
461461 $ htmlPart = new TextPart ($ 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 ($ regexes as $ 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 = [];
Original file line number Diff line number Diff 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 = (new Email ())->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 public function testAttachments ()
You can’t perform that action at this time.
0 commit comments