From 83764556ea36e5c2c13bac17c3d37a895f7a08f5 Mon Sep 17 00:00:00 2001 From: "christian.charzewski.riv" Date: Mon, 5 Oct 2020 16:40:19 +0200 Subject: [PATCH 1/3] Setting fixed composer version because symfony/config > 3.4 breaks all tests --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 050bf91..7541f88 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ }, "require-dev": { "phpunit/phpunit": "^5.7", - "symfony/config": ">=2.0|~3.0" + "symfony/config": "^3.4" }, "license": "MIT", "authors": [ From 6b4256762397fce82dfe41c517803eca1f979135 Mon Sep 17 00:00:00 2001 From: "christian.charzewski.riv" Date: Mon, 5 Oct 2020 16:41:08 +0200 Subject: [PATCH 2/3] Added swift image as possible inline attachment type --- .../MessageFormat/MessagePayloadV3.php | 19 +++++++++--------- .../MessageFormat/MessagePayloadV31.php | 20 ++++++++++--------- Tests/SwiftMailer/MailjetTransportv31Test.php | 18 +++++++++++++++++ 3 files changed, 39 insertions(+), 18 deletions(-) diff --git a/SwiftMailer/MessageFormat/MessagePayloadV3.php b/SwiftMailer/MessageFormat/MessagePayloadV3.php index 6a90b0f..3af4d99 100644 --- a/SwiftMailer/MessageFormat/MessagePayloadV3.php +++ b/SwiftMailer/MessageFormat/MessagePayloadV3.php @@ -5,6 +5,7 @@ use \Swift_Mime_SimpleMessage; use \Swift_Attachment; use \Swift_MimePart; +use \Swift_Image; class MessagePayloadV3 extends BaseMessagePayload { @@ -41,7 +42,15 @@ public function getMailjetMessage(Swift_Mime_SimpleMessage $message) { // Handle attachments foreach ($message->getChildren() as $child) { - if ($child instanceof Swift_Attachment) { + if (($child instanceof Swift_Attachment || $child instanceof Swift_Image) + && $child->getDisposition() === "inline" + ) { + $inline_attachments[] = array( + 'Content-type' => $child->getContentType(), + 'Filename' => $child->getFilename(), + 'content' => base64_encode($child->getBody()) + ); + } elseif ($child instanceof Swift_Attachment) { //Handle regular attachments if ($child->getDisposition() === "attachment") { $attachments[] = array( @@ -50,14 +59,6 @@ public function getMailjetMessage(Swift_Mime_SimpleMessage $message) { 'content' => base64_encode($child->getBody()) ); } - //Handle inline attachments - elseif ($child->getDisposition() === "inline") { - $inline_attachments[] = array( - 'Content-type' => $child->getContentType(), - 'Filename' => $child->getFilename(), - 'content' => base64_encode($child->getBody()) - ); - } } elseif ($child instanceof Swift_MimePart && $this->supportsContentType($child->getContentType())) { if ($child->getContentType() == "text/html") { $bodyHtml = $child->getBody(); diff --git a/SwiftMailer/MessageFormat/MessagePayloadV31.php b/SwiftMailer/MessageFormat/MessagePayloadV31.php index e25385d..5d08f52 100644 --- a/SwiftMailer/MessageFormat/MessagePayloadV31.php +++ b/SwiftMailer/MessageFormat/MessagePayloadV31.php @@ -4,6 +4,7 @@ use \Swift_Mime_SimpleMessage; use \Swift_Attachment; +use \Swift_Image; use \Swift_MimePart; class MessagePayloadV31 extends BaseMessagePayload { @@ -72,7 +73,16 @@ public function getMailjetMessage(Swift_Mime_SimpleMessage $message) { // Handle attachments foreach ($message->getChildren() as $child) { - if ($child instanceof Swift_Attachment) { + if (($child instanceof Swift_Attachment || $child instanceof Swift_Image) + && $child->getDisposition() === "inline" + ) { + $inline_attachments[] = array( + 'ContentType' => $child->getContentType(), + 'Filename' => $child->getFilename(), + 'ContentID' => $child->getId(), + 'Base64Content' => base64_encode($child->getBody()) + ); + } elseif ($child instanceof Swift_Attachment) { //Handle regular attachments if ($child->getDisposition() === "attachment") { $attachments[] = array( @@ -82,14 +92,6 @@ public function getMailjetMessage(Swift_Mime_SimpleMessage $message) { ); } //Handle inline attachments - elseif ($child->getDisposition() === "inline") { - $inline_attachments[] = array( - 'ContentType' => $child->getContentType(), - 'Filename' => $child->getFilename(), - 'ContentID' => $child->getId(), - 'Base64Content' => base64_encode($child->getBody()) - ); - } } elseif ($child instanceof Swift_MimePart && $this->supportsContentType($child->getContentType())) { if ($child->getContentType() == "text/html") { $bodyHtml = $child->getBody(); diff --git a/Tests/SwiftMailer/MailjetTransportv31Test.php b/Tests/SwiftMailer/MailjetTransportv31Test.php index 65293cf..6e6ccb9 100644 --- a/Tests/SwiftMailer/MailjetTransportv31Test.php +++ b/Tests/SwiftMailer/MailjetTransportv31Test.php @@ -209,6 +209,24 @@ public function testMessage() { $this->assertMessageSendable($message); } + public function testInlineImage() { + $transport = $this->createTransport(); + $message = new \Swift_Message('Test Subject', '

Foo bar

', 'text/html'); + $inline_image = new \Swift_Image($this->createPngContent(), 'filename.png', 'image/png'); + $message->attach($inline_image); + $message + ->addTo('to@example.com', 'To Name') + ->addFrom('from@example.com', 'From Name') + ; + $mailjetMessage = $transport->messageFormat->getMailjetMessage($message)['Messages'][0]; + + $transport->send($message); + + $this->assertMailjetMessageContainsInlineAttachment('image/png', 'filename.png', $this->createPngContent(), $mailjetMessage); + + $this->assertMessageSendable($message); + } + public function testBulkSendMessages() { $transport = $this->createTransport(); From 88ceb3ec31456136f1c9d801046d166be2158809 Mon Sep 17 00:00:00 2001 From: "christian.charzewski.riv" Date: Thu, 12 Aug 2021 14:13:48 +0200 Subject: [PATCH 3/3] Combined if statement --- SwiftMailer/MessageFormat/MessagePayloadV3.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/SwiftMailer/MessageFormat/MessagePayloadV3.php b/SwiftMailer/MessageFormat/MessagePayloadV3.php index 3af4d99..b65af3e 100644 --- a/SwiftMailer/MessageFormat/MessagePayloadV3.php +++ b/SwiftMailer/MessageFormat/MessagePayloadV3.php @@ -50,15 +50,12 @@ public function getMailjetMessage(Swift_Mime_SimpleMessage $message) { 'Filename' => $child->getFilename(), 'content' => base64_encode($child->getBody()) ); - } elseif ($child instanceof Swift_Attachment) { - //Handle regular attachments - if ($child->getDisposition() === "attachment") { - $attachments[] = array( - 'Content-type' => $child->getContentType(), - 'Filename' => $child->getFilename(), - 'content' => base64_encode($child->getBody()) - ); - } + } elseif ($child instanceof Swift_Attachment && $child->getDisposition() === "attachment") { + $attachments[] = array( + 'Content-type' => $child->getContentType(), + 'Filename' => $child->getFilename(), + 'content' => base64_encode($child->getBody()) + ); } elseif ($child instanceof Swift_MimePart && $this->supportsContentType($child->getContentType())) { if ($child->getContentType() == "text/html") { $bodyHtml = $child->getBody();