Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addding support for Swift_Image Inline attachments #31

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions SwiftMailer/MessageFormat/MessagePayloadV3.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use \Swift_Mime_SimpleMessage;
use \Swift_Attachment;
use \Swift_MimePart;
use \Swift_Image;

class MessagePayloadV3 extends BaseMessagePayload {

Expand Down Expand Up @@ -41,23 +42,20 @@ public function getMailjetMessage(Swift_Mime_SimpleMessage $message) {

// Handle attachments
foreach ($message->getChildren() as $child) {
if ($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())
);
}
//Handle inline attachments
elseif ($child->getDisposition() === "inline") {
$inline_attachments[] = array(
'Content-type' => $child->getContentType(),
'Filename' => $child->getFilename(),
'content' => base64_encode($child->getBody())
);
}
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 && $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();
Expand Down
20 changes: 11 additions & 9 deletions SwiftMailer/MessageFormat/MessagePayloadV31.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use \Swift_Mime_SimpleMessage;
use \Swift_Attachment;
use \Swift_Image;
use \Swift_MimePart;

class MessagePayloadV31 extends BaseMessagePayload {
Expand Down Expand Up @@ -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(
Expand All @@ -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();
Expand Down
18 changes: 18 additions & 0 deletions Tests/SwiftMailer/MailjetTransportv31Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,24 @@ public function testMessage() {
$this->assertMessageSendable($message);
}

public function testInlineImage() {
$transport = $this->createTransport();
$message = new \Swift_Message('Test Subject', '<p>Foo bar</p>', 'text/html');
$inline_image = new \Swift_Image($this->createPngContent(), 'filename.png', 'image/png');
$message->attach($inline_image);
$message
->addTo('[email protected]', 'To Name')
->addFrom('[email protected]', '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();

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"require-dev": {
"phpunit/phpunit": "^5.7",
"symfony/config": ">=2.0|~3.0"
"symfony/config": "^3.4"
},
"license": "MIT",
"authors": [
Expand Down