8000 [Twig Bridge][Mime] Allow attachment name to be set for inline images · symfony/symfony@67a84c1 · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit 67a84c1

Browse files
committed
[Twig Bridge][Mime] Allow attachment name to be set for inline images
Using a recommended Twig setup this would normally result in attachment names like '@assets/img/file.png' which might not be a good file name to expose to email clients. This allows the name to be specified, analogous to `attach`.
1 parent 240b66b commit 67a84c1

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/Symfony/Bridge/Twig/Mime/WrappedTemplatedEmail.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,16 @@ public function toName(): string
3939
* some Twig namespace for email images (e.g. '@email/images/logo.png').
4040
* @param string|null $contentType The media type (i.e. MIME type) of the image file (e.g. 'image/png').
4141
* Some email clients require this to display embedded images.
42+
* @param string|null $name A custom file name that overrides the original name (filepath) of the image
4243
*/
43-
public function image(string $image, ?string $contentType = null): string
44+
public function image(string $image, ?string $contentType = null, ?string $name = null): string
4445
{
4546
$file = $this->twig->getLoader()->getSourceContext($image);
4647
$body = $file->getPath() ? new File($file->getPath()) : $file->getCode();
47-
$this->message->addPart((new DataPart($body, $image, $contentType))->asInline());
48+
$name = $name ?: $image;
49+
$this->message->addPart((new DataPart($body, $name, $contentType))->asInline());
4850

49-
return 'cid:'.$image;
51+
return 'cid:'.$name;
5052
}
5153

5254
/**

0 commit comments

Comments
 (0)
0