diff --git a/src/Symfony/Bridge/Twig/Mime/NotificationEmail.php b/src/Symfony/Bridge/Twig/Mime/NotificationEmail.php index 3148d60a8c85..215b53a03f2a 100644 --- a/src/Symfony/Bridge/Twig/Mime/NotificationEmail.php +++ b/src/Symfony/Bridge/Twig/Mime/NotificationEmail.php @@ -14,6 +14,7 @@ use Symfony\Component\ErrorHandler\Exception\FlattenException; use Symfony\Component\Mime\Header\Headers; use Symfony\Component\Mime\Part\AbstractPart; +use Symfony\Component\Mime\Part\DataPart; use Twig\Extra\CssInliner\CssInlinerExtension; use Twig\Extra\Inky\InkyExtension; use Twig\Extra\Markdown\MarkdownExtension; @@ -134,7 +135,7 @@ public function exception(\Throwable|FlattenException $exception): static $exceptionAsString = $this->getExceptionAsString($exception); $this->context['exception'] = true; - $this->attach($exceptionAsString, 'exception.txt', 'text/plain'); + $this->addPart(new DataPart($exceptionAsString, 'exception.txt', 'text/plain')); $this->importance(self::IMPORTANCE_URGENT); if (!$this->getSubject()) { diff --git a/src/Symfony/Bridge/Twig/Mime/WrappedTemplatedEmail.php b/src/Symfony/Bridge/Twig/Mime/WrappedTemplatedEmail.php index e0b3bef29308..1d3b92d6dbdd 100644 --- a/src/Symfony/Bridge/Twig/Mime/WrappedTemplatedEmail.php +++ b/src/Symfony/Bridge/Twig/Mime/WrappedTemplatedEmail.php @@ -12,6 +12,8 @@ namespace Symfony\Bridge\Twig\Mime; use Symfony\Component\Mime\Address; +use Symfony\Component\Mime\Part\BodyFile; +use Symfony\Component\Mime\Part\DataPart; use Twig\Environment; /** @@ -38,11 +40,8 @@ public function toName(): string public function image(string $image, string $contentType = null): string { $file = $this->twig->getLoader()->getSourceContext($image); - if ($path = $file->getPath()) { - $this->message->embedFromPath($path, $image, $contentType); - } else { - $this->message->embed($file->getCode(), $image, $contentType); - } + $body = $file->getPath() ? new BodyFile($file->getPath()) : $file->getCode(); + $this->message->addPart((new DataPart($body, $image, $contentType))->asInline()); return 'cid:'.$image; } @@ -50,11 +49,8 @@ public function image(string $image, string $contentType = null): string public function attach(string $file, string $name = null, string $contentType = null): void { $file = $this->twig->getLoader()->getSourceContext($file); - if ($path = $file->getPath()) { - $this->message->attachFromPath($path, $name, $contentType); - } else { - $this->message->attach($file->getCode(), $name, $contentType); - } + $body = $file->getPath() ? new BodyFile($file->getPath()) : $file->getCode(); + $this->message->addPart(new DataPart($body, $name, $contentType)); } /** diff --git a/src/Symfony/Bridge/Twig/Tests/Mime/TemplatedEmailTest.php b/src/Symfony/Bridge/Twig/Tests/Mime/TemplatedEmailTest.php index cb2786d8ea75..96d60fa4d9ba 100644 --- a/src/Symfony/Bridge/Twig/Tests/Mime/TemplatedEmailTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Mime/TemplatedEmailTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Bridge\Twig\Mime\TemplatedEmail; +use Symfony\Component\Mime\Part\DataPart; use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor; use Symfony\Component\Serializer\Encoder\JsonEncoder; use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer; @@ -58,7 +59,7 @@ public function testSymfonySerialize() $e->textTemplate('email.txt.twig'); $e->htmlTemplate('email.html.twig'); $e->context(['foo' => 'bar']); - $e->attach('Some Text file', 'test.txt'); + $e->addPart(new DataPart('Some Text file', 'test.txt')); $expected = clone $e; $expectedJson = <<addCc('cc@symfony.com') ->text('Bar!') ->html('

Foo

') - ->attach(file_get_contents(__FILE__), 'foobar.php') + ->addPart(new DataPart(file_get_contents(__FILE__), 'foobar.php')) ); $mailer->send((new Email())->to('fabien@symfony.com', 'thomas@symfony.com')->from('fabien@symfony.com')->subject('Foo') @@ -33,7 +34,7 @@ public function indexAction(MailerInterface $mailer) ->addCc('cc@symfony.com') ->text('Bar!') ->html('

Foo

') - ->attach(file_get_contents(__FILE__), 'foobar.php') + ->addPart(new DataPart(file_get_contents(__FILE__), 'foobar.php')) ); return new Response(); diff --git a/src/Symfony/Component/Mailer/Bridge/Infobip/Tests/Transport/InfobipApiTransportTest.php b/src/Symfony/Component/Mailer/Bridge/Infobip/Tests/Transport/InfobipApiTransportTest.php index 55da5a5aff23..107f5d406075 100644 --- a/src/Symfony/Component/Mailer/Bridge/Infobip/Tests/Transport/InfobipApiTransportTest.php +++ b/src/Symfony/Component/Mailer/Bridge/Infobip/Tests/Transport/InfobipApiTransportTest.php @@ -19,6 +19,7 @@ use Symfony\Component\Mailer\SentMessage; use Symfony\Component\Mime\Address; use Symfony\Component\Mime\Email; +use Symfony\Component\Mime\Part\DataPart; use Symfony\Contracts\HttpClient\ResponseInterface; class InfobipApiTransportTest extends TestCase @@ -206,8 +207,8 @@ public function testSendEmailWithAttachmentsShouldCalledInfobipWithTheRightParam { $email = $this->basicValidEmail() ->text('foobar') - ->attach('some attachment', 'attachment.txt', 'text/plain') - ->embed('some inline attachment', 'inline.txt', 'text/plain') + ->addPart(new DataPart('some attachment', 'attachment.txt', 'text/plain')) + ->addPart((new DataPart('some inline attachment', 'inline.txt', 'text/plain'))->asInline()) ; $this->transport->send($email); @@ -320,8 +321,8 @@ public function testSendEmailWithAttachmentsWithSuccess() { $email = $this->basicValidEmail() ->text('foobar') - ->attach('some attachment', 'attachment.txt', 'text/plain') - ->embed('some inline attachment', 'inline.txt', 'text/plain') + ->addPart(new DataPart('some attachment', 'attachment.txt', 'text/plain')) + ->addPart((new DataPart('some inline attachment', 'inline.txt', 'text/plain'))->asInline()) ; $sentMessage = $this->transport->send($email); diff --git a/src/Symfony/Component/Mailer/Bridge/Infobip/composer.json b/src/Symfony/Component/Mailer/Bridge/Infobip/composer.json index 30305803fccb..044caf4f7ec1 100644 --- a/src/Symfony/Component/Mailer/Bridge/Infobip/composer.json +++ b/src/Symfony/Component/Mailer/Bridge/Infobip/composer.json @@ -27,6 +27,9 @@ "require-dev": { "symfony/http-client": "^6.1" }, + "conflict": { + "symfony/mime": "<6.2" + }, "autoload": { "psr-4": { "Symfony\\Component\\Mailer\\Bridge\\Infobip\\": "" diff --git a/src/Symfony/Component/Mailer/Bridge/Sendgrid/Tests/Transport/SendgridApiTransportTest.php b/src/Symfony/Component/Mailer/Bridge/Sendgrid/Tests/Transport/SendgridApiTransportTest.php index ef6d2a51a26c..d26be37a8b2c 100644 --- a/src/Symfony/Component/Mailer/Bridge/Sendgrid/Tests/Transport/SendgridApiTransportTest.php +++ b/src/Symfony/Component/Mailer/Bridge/Sendgrid/Tests/Transport/SendgridApiTransportTest.php @@ -18,6 +18,7 @@ use Symfony\Component\Mailer\Header\TagHeader; use Symfony\Component\Mime\Address; use Symfony\Component\Mime\Email; +use Symfony\Component\Mime\Part\DataPart; use Symfony\Contracts\HttpClient\HttpClientInterface; use Symfony\Contracts\HttpClient\ResponseInterface; @@ -107,7 +108,7 @@ public function testLineBreaksInEncodedAttachment() $email->from('foo@example.com') ->to('bar@example.com') // even if content doesn't include new lines, the base64 encoding performed later may add them - ->attach('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod', 'lorem.txt'); + ->addPart(new DataPart('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod', 'lorem.txt')); $response = $this->createMock(ResponseInterface::class); diff --git a/src/Symfony/Component/Mailer/Bridge/Sendgrid/composer.json b/src/Symfony/Component/Mailer/Bridge/Sendgrid/composer.json index f30b4ddd1781..91ded9b9fb26 100644 --- a/src/Symfony/Component/Mailer/Bridge/Sendgrid/composer.json +++ b/src/Symfony/Component/Mailer/Bridge/Sendgrid/composer.json @@ -22,6 +22,9 @@ "require-dev": { "symfony/http-client": "^5.4|^6.0" }, + "conflict": { + "symfony/mime": "<6.2" + }, "autoload": { "psr-4": { "Symfony\\Component\\Mailer\\Bridge\\Sendgrid\\": "" }, "exclude-from-classmap": [ diff --git a/src/Symfony/Component/Mailer/Bridge/Sendinblue/Tests/Transport/SendinblueApiTransportTest.php b/src/Symfony/Component/Mailer/Bridge/Sendinblue/Tests/Transport/SendinblueApiTransportTest.php index 37a5fd92e4d9..610d0af73f98 100644 --- a/src/Symfony/Component/Mailer/Bridge/Sendinblue/Tests/Transport/SendinblueApiTransportTest.php +++ b/src/Symfony/Component/Mailer/Bridge/Sendinblue/Tests/Transport/SendinblueApiTransportTest.php @@ -130,7 +130,6 @@ public function testSend() $transport = new SendinblueApiTransport('ACCESS_KEY', $client); $transport->setPort(8984); - $dataPart = new DataPart('body'); $mail = new Email(); $mail->subject('Hello!') ->to(new Address('saif.gmati@symfony.com', 'Saif Eddin')) @@ -140,7 +139,7 @@ public function testSend() ->addCc('foo@bar.fr') ->addBcc('foo@bar.fr') ->addReplyTo('foo@bar.fr') - ->attachPart($dataPart) + ->addPart(new DataPart('body')) ; $message = $transport->send($mail); diff --git a/src/Symfony/Component/Mailer/Bridge/Sendinblue/composer.json b/src/Symfony/Component/Mailer/Bridge/Sendinblue/composer.json index ae969ab54e46..053caa9fb46c 100644 --- a/src/Symfony/Component/Mailer/Bridge/Sendinblue/composer.json +++ b/src/Symfony/Component/Mailer/Bridge/Sendinblue/composer.json @@ -22,6 +22,9 @@ "require-dev": { "symfony/http-client": "^5.4|^6.0" }, + "conflict": { + "symfony/mime": "<6.2" + }, "autoload": { "psr-4": { "Symfony\\Component\\Mailer\\Bridge\\Sendinblue\\": "" }, "exclude-from-classmap": [ diff --git a/src/Symfony/Component/Mailer/Tests/Transport/Smtp/SmtpTransportTest.php b/src/Symfony/Component/Mailer/Tests/Transport/Smtp/SmtpTransportTest.php index 1fe745b81cc6..42a76e6d80a2 100644 --- a/src/Symfony/Component/Mailer/Tests/Transport/Smtp/SmtpTransportTest.php +++ b/src/Symfony/Component/Mailer/Tests/Transport/Smtp/SmtpTransportTest.php @@ -21,6 +21,8 @@ use Symfony\Component\Mime\Address; use Symfony\Component\Mime\Email; use Symfony\Component\Mime\Exception\InvalidArgumentException; +use Symfony\Component\Mime\Part\BodyFile; +use Symfony\Component\Mime\Part\DataPart; use Symfony\Component\Mime\RawMessage; /** @@ -103,7 +105,7 @@ public function testSendInvalidMessage() $message = new Email(); $message->to('recipient@example.org'); $message->from('sender@example.org'); - $message->attachFromPath('/does_not_exists'); + $message->addPart(new DataPart(new BodyFile('/does_not_exists'))); try { $transport->send($message); diff --git a/src/Symfony/Component/Mailer/composer.json b/src/Symfony/Component/Mailer/composer.json index d77448de3d46..85465f21306b 100644 --- a/src/Symfony/Component/Mailer/composer.json +++ b/src/Symfony/Component/Mailer/composer.json @@ -31,7 +31,8 @@ }, "conflict": { "symfony/http-kernel": "<5.4", - "symfony/messenger": "<6.2" + "symfony/messenger": "<6.2", + "symfony/mime": "<6.2" }, "autoload": { "psr-4": { "Symfony\\Component\\Mailer\\": "" }, diff --git a/src/Symfony/Component/Mime/Email.php b/src/Symfony/Component/Mime/Email.php index 697c71ced812..36464fc03e9e 100644 --- a/src/Symfony/Component/Mime/Email.php +++ b/src/Symfony/Component/Mime/Email.php @@ -327,7 +327,7 @@ public function getHtmlCharset(): ?string */ public function attach($body, string $name = null, string $contentType = null): static { - return $this->attachPart(new DataPart($body, $name, $contentType)); + return $this->addPart(new DataPart($body, $name, $contentType)); } /** @@ -335,7 +335,7 @@ public function attach($body, string $name = null, string $contentType = null): */ public function attachFromPath(string $path, string $name = null, string $contentType = null): static { - return $this->attachPart(new DataPart(new BodyFile($path), $name, $contentType)); + return $this->addPart(new DataPart(new BodyFile($path), $name, $contentType)); } /** @@ -345,7 +345,7 @@ public function attachFromPath(string $path, string $name = null, string $conten */ public function embed($body, string $name = null, string $contentType = null): static { - return $this->attachPart((new DataPart($body, $name, $contentType))->asInline()); + return $this->addPart((new DataPart($body, $name, $contentType))->asInline()); } /** @@ -353,13 +353,25 @@ public function embed($body, string $name = null, string $contentType = null): s */ public function embedFromPath(string $path, string $name = null, string $contentType = null): static { - return $this->attachPart((new DataPart(new BodyFile($path), $name, $contentType))->asInline()); + return $this->addPart((new DataPart(new BodyFile($path), $name, $contentType))->asInline()); } /** * @return $this + * + * @deprecated since Symfony 6.2, use addPart() instead */ public function attachPart(DataPart $part): static + { + @trigger_deprecation('symfony/mime', '6.2', 'The "%s()" method is deprecated, use "addPart()" instead.', __METHOD__); + + return $this->addPart($part); + } + + /** + * @return $this + */ + public function addPart(DataPart $part): static { $this->cachedBody = null; $this->attachments[] = $part; diff --git a/src/Symfony/Component/Mime/MessageConverter.php b/src/Symfony/Component/Mime/MessageConverter.php index 5436e4a9a663..4d86afc316af 100644 --- a/src/Symfony/Component/Mime/MessageConverter.php +++ b/src/Symfony/Component/Mime/MessageConverter.php @@ -58,7 +58,7 @@ public static function toEmail(Message $message): Email throw new RuntimeException(sprintf('Unable to create an Email from an instance of "%s" as the body is too complex.', get_debug_type($message))); } - return self::attachParts($email, \array_slice($parts, 1)); + return self::addParts($email, \array_slice($parts, 1)); } throw new RuntimeException(sprintf('Unable to create an Email from an instance of "%s" as the body is too complex.', get_debug_type($message))); @@ -104,17 +104,17 @@ private static function createEmailFromRelatedPart(Message $message, RelatedPart throw new RuntimeException(sprintf('Unable to create an Email from an instance of "%s" as the body is too complex.', get_debug_type($message))); } - return self::attachParts($email, \array_slice($parts, 1)); + return self::addParts($email, \array_slice($parts, 1)); } - private static function attachParts(Email $email, array $parts): Email + private static function addParts(Email $email, array $parts): Email { foreach ($parts as $part) { if (!$part instanceof DataPart) { throw new RuntimeException(sprintf('Unable to create an Email from an instance of "%s" as the body is too complex.', get_debug_type($email))); } - $email->attachPart($part); + $email->addPart($part); } return $email; diff --git a/src/Symfony/Component/Mime/Tests/Crypto/SMimeSignerTest.php b/src/Symfony/Component/Mime/Tests/Crypto/SMimeSignerTest.php index 297b3cce874d..3da13a2b2fc2 100644 --- a/src/Symfony/Component/Mime/Tests/Crypto/SMimeSignerTest.php +++ b/src/Symfony/Component/Mime/Tests/Crypto/SMimeSignerTest.php @@ -16,6 +16,7 @@ use Symfony\Component\Mime\Email; use Symfony\Component\Mime\Header\Headers; use Symfony\Component\Mime\Message; +use Symfony\Component\Mime\Part\DataPart; use Symfony\Component\Mime\Part\TextPart; /** @@ -120,8 +121,8 @@ public function testSignedMessageWithAttachments() ); $message->html('html content '); $message->text('text content'); - $message->attach(fopen(__DIR__.'/../Fixtures/mimetypes/test', 'r')); - $message->attach(fopen(__DIR__.'/../Fixtures/mimetypes/test.gif', 'r'), 'test.gif'); + $message->addPart(new DataPart(fopen(__DIR__.'/../Fixtures/mimetypes/test', 'r'))); + $message->addPart(new DataPart(fopen(__DIR__.'/../Fixtures/mimetypes/test.gif', 'r'), 'test.gif')); $signer = new SMimeSigner($this->samplesDir.'sign.crt', $this->samplesDir.'sign.key'); diff --git a/src/Symfony/Component/Mime/Tests/EmailTest.php b/src/Symfony/Component/Mime/Tests/EmailTest.php index cc89d6fdec9e..b71fe9e2234c 100644 --- a/src/Symfony/Component/Mime/Tests/EmailTest.php +++ b/src/Symfony/Component/Mime/Tests/EmailTest.php @@ -15,6 +15,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Mime\Address; use Symfony\Component\Mime\Email; +use Symfony\Component\Mime\Part\BodyFile; use Symfony\Component\Mime\Part\DataPart; use Symfony\Component\Mime\Part\Multipart\AlternativePart; use Symfony\Component\Mime\Part\Multipart\MixedPart; @@ -295,7 +296,7 @@ public function testGenerateBodyWithTextContentAndAttachedFile() { [$text, $html, $filePart, $file, $imagePart, $image] = $this->generateSomeParts(); $e = (new Email())->from('me@example.com')->to('you@example.com'); - $e->attach($file); + $e->addPart(new DataPart($file)); $e->text('text content'); $this->assertEquals(new MixedPart($text, $filePart), $e->getBody()); } @@ -304,7 +305,7 @@ public function testGenerateBodyWithHtmlContentAndAttachedFile() { [$text, $html, $filePart, $file, $imagePart, $image] = $this->generateSomeParts(); $e = (new Email())->from('me@example.com')->to('you@example.com'); - $e->attach($file); + $e->addPart(new DataPart($file)); $e->html('html content'); $this->assertEquals(new MixedPart($html, $filePart), $e->getBody()); } @@ -315,7 +316,7 @@ public function testGenerateBodyWithHtmlContentAndInlineImageNotreferenced() $imagePart = new DataPart($image = fopen(__DIR__.'/Fixtures/mimetypes/test.gif', 'r')); $imagePart->asInline(); $e = (new Email())->from('me@example.com')->to('you@example.com'); - $e->embed($image); + $e->addPart((new DataPart($image))->asInline()); $e->html('html content'); $this->assertEquals(new MixedPart($html, $imagePart), $e->getBody()); } @@ -324,7 +325,7 @@ public function testGenerateBodyWithAttachedFileOnly() { [$text, $html, $filePart, $file, $imagePart, $image] = $this->generateSomeParts(); $e = (new Email())->from('me@example.com')->to('you@example.com'); - $e->attach($file); + $e->addPart(new DataPart($file)); $this->assertEquals(new MixedPart($filePart), $e->getBody()); } @@ -333,7 +334,7 @@ public function testGenerateBodyWithInlineImageOnly() $imagePart = new DataPart($image = fopen(__DIR__.'/Fixtures/mimetypes/test.gif', 'r')); $imagePart->asInline(); $e = (new Email())->from('me@example.com')->to('you@example.com'); - $e->embed($image); + $e->addPart((new DataPart($image))->asInline()); $this->assertEquals(new MixedPart($imagePart), $e->getBody()); } @@ -341,7 +342,7 @@ public function testGenerateBodyWithEmbeddedImageOnly() { $imagePart = new DataPart($image = fopen(__DIR__.'/Fixtures/mimetypes/test.gif', 'r')); $e = (new Email())->from('me@example.com')->to('you@example.com'); - $e->embed($image); + $e->addPart((new DataPart($image))->asInline()); $imagePart->asInline(); $this->assertEquals(new MixedPart($imagePart), $e->getBody()); } @@ -352,7 +353,7 @@ public function testGenerateBodyWithTextAndHtmlContentAndAttachedFile() $e = (new Email())->from('me@example.com')->to('you@example.com'); $e->html('html content'); $e->text('text content'); - $e->attach($file); + $e->addPart(new DataPart($file)); $this->assertEquals(new MixedPart(new AlternativePart($text, $html), $filePart), $e->getBody()); } @@ -362,8 +363,8 @@ public function testGenerateBodyWithTextAndHtmlAndAttachedFileAndAttachedImageNo $e = (new Email())->from('me@example.com')->to('you@example.com'); $e->html('html content'); $e->text('text content'); - $e->attach($file); - $e->attach($image, 'test.gif'); + $e->addPart(new DataPart($file)); + $e->addPart(new DataPart($image, 'test.gif')); $this->assertEquals(new MixedPart(new AlternativePart($text, $html), $filePart, $imagePart), $e->getBody()); } @@ -372,8 +373,8 @@ public function testGenerateBodyWithTextAndAttachedFileAndAttachedImageNotRefere [$text, $html, $filePart, $file, $imagePart, $image] = $this->generateSomeParts(); $e = (new Email())->from('me@example.com')->to('you@example.com'); $e->text('text content'); - $e->attach($file); - $e->attach($image, 'test.gif'); + $e->addPart(new DataPart($file)); + $e->addPart(new DataPart($image, 'test.gif')); $this->assertEquals(new MixedPart($text, $filePart, $imagePart), $e->getBody()); } @@ -383,8 +384,8 @@ public function testGenerateBodyWithTextAndHtmlAndAttachedFileAndAttachedImageNo $e = (new Email())->from('me@example.com')->to('you@example.com'); $e->html($content = 'html content '); $e->text('text content'); - $e->attach($file); - $e->attach($image, 'test.gif'); + $e->addPart(new DataPart($file)); + $e->addPart(new DataPart($image, 'test.gif')); $fullhtml = new TextPart($content, 'utf-8', 'html'); $this->assertEquals(new MixedPart(new AlternativePart($text, $fullhtml), $filePart, $imagePart), $e->getBody()); } @@ -395,27 +396,8 @@ public function testGenerateBodyWithTextAndHtmlAndAttachedFileAndAttachedImageRe $e = (new Email())->from('me@example.com')->to('you@example.com'); $e->html($content = 'html content '); $e->text('text content'); - $e->attach($file); - $e->attach($image, 'test.gif'); - $body = $e->getBody(); - $this->assertInstanceOf(MixedPart::class, $body); - $this->assertCount(2, $related = $body->getParts()); - $this->assertInstanceOf(RelatedPart::class, $related[0]); - $this->assertEquals($filePart, $related[1]); - $this->assertCount(2, $parts = $related[0]->getParts()); - $this->assertInstanceOf(AlternativePart::class, $parts[0]); - $generatedHtml = $parts[0]->getParts()[1]; - $this->assertStringContainsString('cid:'.$parts[1]->getContentId(), $generatedHtml->getBody()); - } - - public function testGenerateBodyWithTextAndHtmlAndAttachedFileAndAttachedImagePartAsInlineReferencedViaCid() - { - [$text, $html, $filePart, $file, $imagePart, $image] = $this->generateSomeParts(); - $e = (new Email())->from('me@example.com')->to('you@example.com'); - $e->html($content = 'html content '); - $e->text('text content'); - $e->attach($file); - $e->attachPart((new DataPart($image, 'test.gif'))->asInline()); + $e->addPart(new DataPart($file)); + $e->addPart(new DataPart($image, 'test.gif')); $body = $e->getBody(); $this->assertInstanceOf(MixedPart::class, $body); $this->assertCount(2, $related = $body->getParts()); @@ -439,8 +421,8 @@ public function testGenerateBodyWithHtmlAndInlinedImageTwiceReferencedViaCid() $e->html($r); // embedding the same image twice results in one image only in the email $image = fopen(__DIR__.'/Fixtures/mimetypes/test.gif', 'r'); - $e->embed($image, 'test.gif'); - $e->embed($image, 'test.gif'); + $e->addPart((new DataPart($image, 'test.gif'))->asInline()); + $e->addPart((new DataPart($image, 'test.gif'))->asInline()); $body = $e->getBody(); $this->assertInstanceOf(RelatedPart::class, $body); // 2 parts only, not 3 (text + embedded image once) @@ -449,7 +431,7 @@ public function testGenerateBodyWithHtmlAndInlinedImageTwiceReferencedViaCid() $e = (new Email())->from('me@example.com')->to('you@example.com'); $e->html('
'); - $e->embed($image, 'test.gif'); + $e->addPart((new DataPart($image, 'test.gif'))->asInline()); $body = $e->getBody(); $this->assertInstanceOf(RelatedPart::class, $body); $this->assertCount(2, $parts = $body->getParts()); @@ -473,16 +455,16 @@ public function testAttachments() $att = new DataPart($file = fopen($name, 'r'), 'test'); $inline = (new DataPart($contents, 'test'))->asInline(); $e = new Email(); - $e->attach($file, 'test'); - $e->embed($contents, 'test'); + $e->addPart(new DataPart($file, 'test')); + $e->addPart((new DataPart($contents, 'test'))->asInline()); $this->assertEquals([$att, $inline], $e->getAttachments()); // inline part from path $att = DataPart::fromPath($name, 'test'); $inline = DataPart::fromPath($name, 'test')->asInline(); $e = new Email(); - $e->attachFromPath($name); - $e->embedFromPath($name); + $e->addPart(new DataPart(new BodyFile($name))); + $e->addPart((new DataPart(new BodyFile($name)))->asInline()); $this->assertEquals([$att->bodyToString(), $inline->bodyToString()], array_map(function (DataPart $a) { return $a->bodyToString(); }, $e->getAttachments())); $this->assertEquals([$att->getPreparedHeaders(), $inline->getPreparedHeaders()], array_map(function (DataPart $a) { return $a->getPreparedHeaders(); }, $e->getAttachments())); } @@ -500,7 +482,7 @@ public function testSerialize() $e->html($r); $name = __DIR__.'/Fixtures/mimetypes/test'; $file = fopen($name, 'r'); - $e->attach($file, 'test'); + $e->addPart(new DataPart($file, 'test')); $expected = clone $e; $n = unserialize(serialize($e)); $this->assertEquals($expected->getHeaders(), $n->getHeaders()); @@ -516,7 +498,7 @@ public function testSymfonySerialize() $e->to('you@example.com'); $e->text('Text content'); $e->html('HTML content'); - $e->attach('Some Text file', 'test.txt'); + $e->addPart(new DataPart('Some Text file', 'test.txt')); $expected = clone $e; $expectedJson = <<evaluate($e); } - public function testAttachBodyExpectStringOrResource() - { - $this->expectException(\TypeError::class); - $this->expectExceptionMessage('The body of "Symfony\Component\Mime\Part\TextPart" must be a string, a resource, or an instance of "Symfony\Component\Mime\Part\BodyFile" (got "bool").'); - - (new Email())->attach(false); - } - - public function testEmbedBodyExpectStringOrResource() - { - $this->expectException(\TypeError::class); - $this->expectExceptionMessage('The body of "Symfony\Component\Mime\Part\TextPart" must be a string, a resource, or an instance of "Symfony\Component\Mime\Part\BodyFile" (got "bool").'); - - (new Email())->embed(false); - } - public function testHtmlBodyExpectStringOrResourceOrNull() { $this->expectException(\TypeError::class); diff --git a/src/Symfony/Component/Mime/Tests/MessageConverterTest.php b/src/Symfony/Component/Mime/Tests/MessageConverterTest.php index aa93afc0053e..a3e5599baa52 100644 --- a/src/Symfony/Component/Mime/Tests/MessageConverterTest.php +++ b/src/Symfony/Component/Mime/Tests/MessageConverterTest.php @@ -15,6 +15,7 @@ use Symfony\Component\Mime\Email; use Symfony\Component\Mime\Message; use Symfony\Component\Mime\MessageConverter; +use Symfony\Component\Mime\Part\DataPart; class MessageConverterTest extends TestCase { @@ -33,34 +34,34 @@ public function testToEmail() $this->assertConversion((clone $email) ->text('text content') ->html('HTML content ') - ->embed($file, 'test.jpg', 'image/gif') + ->addPart((new DataPart($file, 'test.jpg', 'image/gif'))->asInline()) ); $this->assertConversion((clone $email) ->text('text content') ->html('HTML content ') - ->attach($file, 'test_attached.jpg', 'image/gif') + ->addPart(new DataPart($file, 'test_attached.jpg', 'image/gif')) ); $this->assertConversion((clone $email) ->text('text content') ->html('HTML content ') - ->embed($file, 'test.jpg', 'image/gif') - ->attach($file, 'test_attached.jpg', 'image/gif') + ->addPart((new DataPart($file, 'test.jpg', 'image/gif'))->asInline()) + ->addPart(new DataPart($file, 'test_attached.jpg', 'image/gif')) ); $this->assertConversion((clone $email) ->text('text content') - ->attach($file, 'test_attached.jpg', 'image/gif') + ->addPart(new DataPart($file, 'test_attached.jpg', 'image/gif')) ); $this->assertConversion((clone $email) ->html('HTML content ') - ->attach($file, 'test_attached.jpg', 'image/gif') + ->addPart(new DataPart($file, 'test_attached.jpg', 'image/gif')) ); $this->assertConversion((clone $email) ->html('HTML content ') - ->embed($file, 'test.jpg', 'image/gif') + ->addPart((new DataPart($file, 'test.jpg', 'image/gif'))->asInline()) ); $this->assertConversion((clone $email) ->text('text content') - ->embed($file, 'test_attached.jpg', 'image/gif') + ->addPart((new DataPart($file, 'test_attached.jpg', 'image/gif'))->asInline()) ); } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy