Skip to content

Commit

Permalink
[5.5] Upgrade to SwiftMailer 6 (#19356)
Browse files Browse the repository at this point in the history
*    swiftmailer6 upgrade

*    fix style

*    fix style
  • Loading branch information
themsaid authored and taylorotwell committed May 26, 2017
1 parent eee8c84 commit 21f7240
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 48 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"mtdowling/cron-expression": "~1.0",
"nesbot/carbon": "~1.20",
"ramsey/uuid": "~3.0",
"swiftmailer/swiftmailer": "~5.4",
"swiftmailer/swiftmailer": "~6.0",
"symfony/console": "~3.2",
"symfony/debug": "~3.2",
"symfony/finder": "~3.2",
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Mail/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public function attachData($data, $name, array $options = [])
*/
protected function createAttachmentFromData($data, $name)
{
return Swift_Attachment::newInstance($data, $name);
return new Swift_Attachment($data, $name);
}

/**
Expand Down Expand Up @@ -266,7 +266,7 @@ public function embed($file)
*/
public function embedData($data, $name, $contentType = null)
{
$image = Swift_Image::newInstance($data, $name, $contentType);
$image = new Swift_Image($data, $name, $contentType);

return $this->swift->embed($image);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Mail/Transport/ArrayTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Illuminate\Mail\Transport;

use Swift_Mime_Message;
use Swift_Mime_SimpleMessage;
use Illuminate\Support\Collection;

class ArrayTransport extends Transport
Expand All @@ -27,7 +27,7 @@ public function __construct()
/**
* {@inheritdoc}
*/
public function send(Swift_Mime_Message $message, &$failedRecipients = null)
public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null)
{
$this->beforeSendPerformed($message);

Expand Down
10 changes: 5 additions & 5 deletions src/Illuminate/Mail/Transport/LogTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Illuminate\Mail\Transport;

use Swift_Mime_Message;
use Swift_Mime_MimeEntity;
use Psr\Log\LoggerInterface;
use Swift_Mime_SimpleMessage;
use Swift_Mime_SimpleMimeEntity;

class LogTransport extends Transport
{
Expand All @@ -29,7 +29,7 @@ public function __construct(LoggerInterface $logger)
/**
* {@inheritdoc}
*/
public function send(Swift_Mime_Message $message, &$failedRecipients = null)
public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null)
{
$this->beforeSendPerformed($message);

Expand All @@ -43,10 +43,10 @@ public function send(Swift_Mime_Message $message, &$failedRecipients = null)
/**
* Get a loggable string out of a Swiftmailer entity.
*
* @param \Swift_Mime_MimeEntity $entity
* @param \Swift_Mime_SimpleMimeEntity $entity
* @return string
*/
protected function getMimeEntityString(Swift_Mime_MimeEntity $entity)
protected function getMimeEntityString(Swift_Mime_SimpleMimeEntity $entity)
{
$string = (string) $entity->getHeaders().PHP_EOL.$entity->getBody();

Expand Down
16 changes: 8 additions & 8 deletions src/Illuminate/Mail/Transport/MailgunTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Illuminate\Mail\Transport;

use Swift_Mime_Message;
use Swift_Mime_SimpleMessage;
use GuzzleHttp\ClientInterface;

class MailgunTransport extends Transport
Expand Down Expand Up @@ -53,7 +53,7 @@ public function __construct(ClientInterface $client, $key, $domain)
/**
* {@inheritdoc}
*/
public function send(Swift_Mime_Message $message, &$failedRecipients = null)
public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null)
{
$this->beforeSendPerformed($message);

Expand All @@ -71,11 +71,11 @@ public function send(Swift_Mime_Message $message, &$failedRecipients = null)
/**
* Get the HTTP payload for sending the Mailgun message.
*
* @param \Swift_Mime_Message $message
* @param \Swift_Mime_SimpleMessage $message
* @param string $to
* @return array
*/
protected function payload(Swift_Mime_Message $message, $to)
protected function payload(Swift_Mime_SimpleMessage $message, $to)
{
return [
'auth' => [
Expand All @@ -99,10 +99,10 @@ protected function payload(Swift_Mime_Message $message, $to)
/**
* Get the "to" payload field for the API request.
*
* @param \Swift_Mime_Message $message
* @param \Swift_Mime_SimpleMessage $message
* @return string
*/
protected function getTo(Swift_Mime_Message $message)
protected function getTo(Swift_Mime_SimpleMessage $message)
{
return collect($this->allContacts($message))->map(function ($display, $address) {
return $display ? $display." <{$address}>" : $address;
Expand All @@ -112,10 +112,10 @@ protected function getTo(Swift_Mime_Message $message)
/**
* Get all of the contacts for the message.
*
* @param \Swift_Mime_Message $message
* @param \Swift_Mime_SimpleMessage $message
* @return array
*/
protected function allContacts(Swift_Mime_Message $message)
protected function allContacts(Swift_Mime_SimpleMessage $message)
{
return array_merge(
(array) $message->getTo(), (array) $message->getCc(), (array) $message->getBcc()
Expand Down
8 changes: 4 additions & 4 deletions src/Illuminate/Mail/Transport/MandrillTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Illuminate\Mail\Transport;

use Swift_Mime_Message;
use Swift_Mime_SimpleMessage;
use GuzzleHttp\ClientInterface;

class MandrillTransport extends Transport
Expand Down Expand Up @@ -37,7 +37,7 @@ public function __construct(ClientInterface $client, $key)
/**
* {@inheritdoc}
*/
public function send(Swift_Mime_Message $message, &$failedRecipients = null)
public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null)
{
$this->beforeSendPerformed($message);

Expand All @@ -60,10 +60,10 @@ public function send(Swift_Mime_Message $message, &$failedRecipients = null)
*
* Note that Mandrill still respects CC, BCC headers in raw message itself.
*
* @param \Swift_Mime_Message $message
* @param \Swift_Mime_SimpleMessage $message
* @return array
*/
protected function getTo(Swift_Mime_Message $message)
protected function getTo(Swift_Mime_SimpleMessage $message)
{
$to = [];

Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Mail/Transport/SesTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Illuminate\Mail\Transport;

use Aws\Ses\SesClient;
use Swift_Mime_Message;
use Swift_Mime_SimpleMessage;

class SesTransport extends Transport
{
Expand All @@ -28,7 +28,7 @@ public function __construct(SesClient $ses)
/**
* {@inheritdoc}
*/
public function send(Swift_Mime_Message $message, &$failedRecipients = null)
public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null)
{
$this->beforeSendPerformed($message);

Expand Down
8 changes: 4 additions & 4 deletions src/Illuminate/Mail/Transport/SparkPostTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Illuminate\Mail\Transport;

use Swift_Mime_Message;
use Swift_Mime_SimpleMessage;
use GuzzleHttp\ClientInterface;

class SparkPostTransport extends Transport
Expand Down Expand Up @@ -46,7 +46,7 @@ public function __construct(ClientInterface $client, $key, $options = [])
/**
* {@inheritdoc}
*/
public function send(Swift_Mime_Message $message, &$failedRecipients = null)
public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null)
{
$this->beforeSendPerformed($message);

Expand Down Expand Up @@ -80,10 +80,10 @@ public function send(Swift_Mime_Message $message, &$failedRecipients = null)
*
* Note that SparkPost still respects CC, BCC headers in raw message itself.
*
* @param \Swift_Mime_Message $message
* @param \Swift_Mime_SimpleMessage $message
* @return array
*/
protected function getRecipients(Swift_Mime_Message $message)
protected function getRecipients(Swift_Mime_SimpleMessage $message)
{
$recipients = [];

Expand Down
22 changes: 15 additions & 7 deletions src/Illuminate/Mail/Transport/Transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Illuminate\Mail\Transport;

use Swift_Transport;
use Swift_Mime_Message;
use Swift_Events_SendEvent;
use Swift_Mime_SimpleMessage;
use Swift_Events_EventListener;

abstract class Transport implements Swift_Transport
Expand Down Expand Up @@ -40,6 +40,14 @@ public function stop()
return true;
}

/**
* {@inheritdoc}
*/
public function ping()
{
return true;
}

/**
* Register a plug-in with the transport.
*
Expand All @@ -54,10 +62,10 @@ public function registerPlugin(Swift_Events_EventListener $plugin)
/**
* Iterate through registered plugins and execute plugins' methods.
*
* @param \Swift_Mime_Message $message
* @param \Swift_Mime_SimpleMessage $message
* @return void
*/
protected function beforeSendPerformed(Swift_Mime_Message $message)
protected function beforeSendPerformed(Swift_Mime_SimpleMessage $message)
{
$event = new Swift_Events_SendEvent($this, $message);

Expand All @@ -71,10 +79,10 @@ protected function beforeSendPerformed(Swift_Mime_Message $message)
/**
* Iterate through registered plugins and execute plugins' methods.
*
* @param \Swift_Mime_Message $message
* @param \Swift_Mime_SimpleMessage $message
* @return void
*/
protected function sendPerformed(Swift_Mime_Message $message)
protected function sendPerformed(Swift_Mime_SimpleMessage $message)
{
$event = new Swift_Events_SendEvent($this, $message);

Expand All @@ -88,10 +96,10 @@ protected function sendPerformed(Swift_Mime_Message $message)
/**
* Get the number of recipients.
*
* @param \Swift_Mime_Message $message
* @param \Swift_Mime_SimpleMessage $message
* @return int
*/
protected function numberOfRecipients(Swift_Mime_Message $message)
protected function numberOfRecipients(Swift_Mime_SimpleMessage $message)
{
return count(array_merge(
(array) $message->getTo(), (array) $message->getCc(), (array) $message->getBcc()
Expand Down
14 changes: 5 additions & 9 deletions src/Illuminate/Mail/TransportManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
use Psr\Log\LoggerInterface;
use Illuminate\Support\Manager;
use GuzzleHttp\Client as HttpClient;
use Swift_MailTransport as MailTransport;
use Swift_SmtpTransport as SmtpTransport;
use Illuminate\Mail\Transport\LogTransport;
use Illuminate\Mail\Transport\SesTransport;
use Illuminate\Mail\Transport\ArrayTransport;
use Swift_SendmailTransport as MailTransport;
use Illuminate\Mail\Transport\MailgunTransport;
use Illuminate\Mail\Transport\MandrillTransport;
use Illuminate\Mail\Transport\SparkPostTransport;
Expand All @@ -31,9 +31,7 @@ protected function createSmtpDriver()
// The Swift SMTP transport instance will allow us to use any SMTP backend
// for delivering mail such as Sendgrid, Amazon SES, or a custom server
// a developer has available. We will just pass this configured host.
$transport = SmtpTransport::newInstance(
$config['host'], $config['port']
);
$transport = new SmtpTransport($config['host'], $config['port']);

if (isset($config['encryption'])) {
$transport->setEncryption($config['encryption']);
Expand Down Expand Up @@ -65,9 +63,7 @@ protected function createSmtpDriver()
*/
protected function createSendmailDriver()
{
return SendmailTransport::newInstance(
$this->app['config']['mail']['sendmail']
);
return new SendmailTransport($this->app['config']['mail']['sendmail']);
}

/**
Expand Down Expand Up @@ -104,11 +100,11 @@ protected function addSesCredentials(array $config)
/**
* Create an instance of the Mail Swift Transport driver.
*
* @return \Swift_MailTransport
* @return \Swift_SendmailTransport
*/
protected function createMailDriver()
{
return MailTransport::newInstance();
return new MailTransport();
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/Mail/MailMailerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function testMailerSendSendsMessageWithProperViewContent()
{
unset($_SERVER['__mailer.test']);
$mailer = $this->getMockBuilder('Illuminate\Mail\Mailer')->setMethods(['createMessage'])->setConstructorArgs($this->getMocks())->getMock();
$message = m::mock('Swift_Mime_Message');
$message = m::mock('Swift_Mime_SimpleMessage');
$mailer->expects($this->once())->method('createMessage')->will($this->returnValue($message));
$view = m::mock('StdClass');
$mailer->getViewFactory()->shouldReceive('make')->once()->with('foo', ['data', 'message' => $message])->andReturn($view);
Expand All @@ -38,7 +38,7 @@ public function testMailerSendSendsMessageWithProperViewContentUsingHtmlStrings(
{
unset($_SERVER['__mailer.test']);
$mailer = $this->getMockBuilder('Illuminate\Mail\Mailer')->setMethods(['createMessage'])->setConstructorArgs($this->getMocks())->getMock();
$message = m::mock('Swift_Mime_Message');
$message = m::mock('Swift_Mime_SimpleMessage');
$mailer->expects($this->once())->method('createMessage')->will($this->returnValue($message));
$view = m::mock('StdClass');
$mailer->getViewFactory()->shouldReceive('make')->never();
Expand All @@ -59,7 +59,7 @@ public function testMailerSendSendsMessageWithProperPlainViewContent()
{
unset($_SERVER['__mailer.test']);
$mailer = $this->getMockBuilder('Illuminate\Mail\Mailer')->setMethods(['createMessage'])->setConstructorArgs($this->getMocks())->getMock();
$message = m::mock('Swift_Mime_Message');
$message = m::mock('Swift_Mime_SimpleMessage');
$mailer->expects($this->once())->method('createMessage')->will($this->returnValue($message));
$view = m::mock('StdClass');
$mailer->getViewFactory()->shouldReceive('make')->once()->with('foo', ['data', 'message' => $message])->andReturn($view);
Expand All @@ -81,7 +81,7 @@ public function testMailerSendSendsMessageWithProperPlainViewContentWhenExplicit
{
unset($_SERVER['__mailer.test']);
$mailer = $this->getMockBuilder('Illuminate\Mail\Mailer')->setMethods(['createMessage'])->setConstructorArgs($this->getMocks())->getMock();
$message = m::mock('Swift_Mime_Message');
$message = m::mock('Swift_Mime_SimpleMessage');
$mailer->expects($this->once())->method('createMessage')->will($this->returnValue($message));
$view = m::mock('StdClass');
$mailer->getViewFactory()->shouldReceive('make')->once()->with('foo', ['data', 'message' => $message])->andReturn($view);
Expand Down

0 comments on commit 21f7240

Please sign in to comment.