From 86675dfd4fa4634955de7a96e262f6c62ade0b01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jakes=CC=8C?= Date: Tue, 24 Sep 2019 16:16:51 +0200 Subject: [PATCH] Move Swiftmailer to vendor-prefixed [MAILPOET-2363] --- composer.json | 1 - composer.lock | 56 +------------------ lib/Config/RequirementsChecker.php | 3 - lib/Mailer/Methods/AmazonSES.php | 5 +- .../Methods/ErrorMappers/AmazonSESMapper.php | 3 +- .../Methods/ErrorMappers/SMTPMapper.php | 3 +- lib/Mailer/Methods/SMTP.php | 15 +++-- prefixer/composer.json | 4 +- prefixer/composer.lock | 56 ++++++++++++++++++- prefixer/fix-swiftmailer.php | 29 ++++++++++ .../Methods/ErrorMappers/SMTPMapperTest.php | 3 +- 11 files changed, 107 insertions(+), 71 deletions(-) create mode 100755 prefixer/fix-swiftmailer.php diff --git a/composer.json b/composer.json index 90fdcca655..86e37681e3 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,6 @@ "mtdowling/cron-expression": "^1.1", "nesbot/carbon": "^1.21", "soundasleep/html2text": "dev-master", - "swiftmailer/swiftmailer": "5.4.12", "tburry/pquery": "^1.1.1" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 8aa49f2028..65a1d71187 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c641885578d3d2bb8a3853d01d0827fe", + "content-hash": "f65ddd571e509c0289261f02e514f883", "packages": [ { "name": "cerdic/css-tidy", @@ -325,60 +325,6 @@ }, "time": "2019-04-24T12:03:33+00:00" }, - { - "name": "swiftmailer/swiftmailer", - "version": "v5.4.12", - "source": { - "type": "git", - "url": "https://github.com/swiftmailer/swiftmailer.git", - "reference": "181b89f18a90f8925ef805f950d47a7190e9b950" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/181b89f18a90f8925ef805f950d47a7190e9b950", - "reference": "181b89f18a90f8925ef805f950d47a7190e9b950", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "mockery/mockery": "~0.9.1", - "symfony/phpunit-bridge": "~3.2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "5.4-dev" - } - }, - "autoload": { - "files": [ - "lib/swift_required.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Chris Corbyn" - }, - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - } - ], - "description": "Swiftmailer, free feature-rich PHP mailer", - "homepage": "https://swiftmailer.symfony.com", - "keywords": [ - "email", - "mail", - "mailer" - ], - "time": "2018-07-31T09:26:32+00:00" - }, { "name": "symfony/polyfill-mbstring", "version": "v1.12.0", diff --git a/lib/Config/RequirementsChecker.php b/lib/Config/RequirementsChecker.php index abda4325b8..b3e5b6fbfe 100644 --- a/lib/Config/RequirementsChecker.php +++ b/lib/Config/RequirementsChecker.php @@ -17,9 +17,6 @@ class RequirementsChecker { public $vendor_classes = [ '\ORM', '\Model', - '\Swift_Mailer', - '\Swift_SmtpTransport', - '\Swift_Message', '\Carbon\Carbon', '\Sudzy\ValidModel', '\Sudzy\ValidationException', diff --git a/lib/Mailer/Methods/AmazonSES.php b/lib/Mailer/Methods/AmazonSES.php index f8d57d0551..4ffb31019e 100644 --- a/lib/Mailer/Methods/AmazonSES.php +++ b/lib/Mailer/Methods/AmazonSES.php @@ -6,6 +6,7 @@ use MailPoet\Mailer\Mailer; use MailPoet\Mailer\Methods\Common\BlacklistCheck; use MailPoet\Mailer\Methods\ErrorMappers\AmazonSESMapper; use MailPoet\WP\Functions as WPFunctions; +use MailPoetVendor\Swift_Message; class AmazonSES { public $aws_access_key; @@ -108,7 +109,7 @@ class AmazonSES { } function createMessage($newsletter, $subscriber, $extra_params = []) { - $message = \Swift_Message::newInstance() + $message = Swift_Message::newInstance() ->setTo($this->processSubscriber($subscriber)) ->setFrom([ $this->sender['from_email'] => $this->sender['from_name'], @@ -132,7 +133,7 @@ class AmazonSES { return $message; } - function encodeMessage(\Swift_Message $message) { + function encodeMessage(Swift_Message $message) { return base64_encode($message->toString()); } diff --git a/lib/Mailer/Methods/ErrorMappers/AmazonSESMapper.php b/lib/Mailer/Methods/ErrorMappers/AmazonSESMapper.php index bf9cadeaae..14b2aaeec6 100644 --- a/lib/Mailer/Methods/ErrorMappers/AmazonSESMapper.php +++ b/lib/Mailer/Methods/ErrorMappers/AmazonSESMapper.php @@ -6,6 +6,7 @@ use MailPoet\Mailer\Mailer; use MailPoet\Mailer\MailerError; use MailPoet\Mailer\SubscriberError; use MailPoet\WP\Functions as WPFunctions; +use MailPoetVendor\Swift_RfcComplianceException; class AmazonSESMapper { use BlacklistErrorMapperTrait; @@ -15,7 +16,7 @@ class AmazonSESMapper { function getErrorFromException(\Exception $e, $subscriber) { $level = MailerError::LEVEL_HARD; - if ($e instanceof \Swift_RfcComplianceException) { + if ($e instanceof Swift_RfcComplianceException) { $level = MailerError::LEVEL_SOFT; } $subscriber_errors = [new SubscriberError($subscriber, null)]; diff --git a/lib/Mailer/Methods/ErrorMappers/SMTPMapper.php b/lib/Mailer/Methods/ErrorMappers/SMTPMapper.php index 3207e2a035..26e536e639 100644 --- a/lib/Mailer/Methods/ErrorMappers/SMTPMapper.php +++ b/lib/Mailer/Methods/ErrorMappers/SMTPMapper.php @@ -6,6 +6,7 @@ use MailPoet\Mailer\Mailer; use MailPoet\Mailer\MailerError; use MailPoet\Mailer\SubscriberError; use MailPoet\WP\Functions as WPFunctions; +use MailPoetVendor\Swift_RfcComplianceException; class SMTPMapper { use BlacklistErrorMapperTrait; @@ -22,7 +23,7 @@ class SMTPMapper { $message = explode(PHP_EOL, $e->getMessage()); $level = MailerError::LEVEL_HARD; - if ($e instanceof \Swift_RfcComplianceException) { + if ($e instanceof Swift_RfcComplianceException) { $level = MailerError::LEVEL_SOFT; } $subscriber_errors = [new SubscriberError($subscriber, null)]; diff --git a/lib/Mailer/Methods/SMTP.php b/lib/Mailer/Methods/SMTP.php index 1c3a269591..f4677c5628 100644 --- a/lib/Mailer/Methods/SMTP.php +++ b/lib/Mailer/Methods/SMTP.php @@ -6,6 +6,11 @@ use MailPoet\Mailer\Mailer; use MailPoet\Mailer\Methods\Common\BlacklistCheck; use MailPoet\Mailer\Methods\ErrorMappers\SMTPMapper; use MailPoet\WP\Functions as WPFunctions; +use MailPoetVendor\Swift_Mailer; +use MailPoetVendor\Swift_Message; +use MailPoetVendor\Swift_Plugins_LoggerPlugin; +use MailPoetVendor\Swift_Plugins_Loggers_ArrayLogger; +use MailPoetVendor\Swift_SmtpTransport; class SMTP { public $host; @@ -45,8 +50,8 @@ class SMTP { $return_path : $this->sender['from_email']; $this->mailer = $this->buildMailer(); - $this->mailer_logger = new \Swift_Plugins_Loggers_ArrayLogger(); - $this->mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($this->mailer_logger)); + $this->mailer_logger = new Swift_Plugins_Loggers_ArrayLogger(); + $this->mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($this->mailer_logger)); $this->error_mapper = $error_mapper; $this->blacklist = new BlacklistCheck(); } @@ -73,7 +78,7 @@ class SMTP { } function buildMailer() { - $transport = \Swift_SmtpTransport::newInstance( + $transport = Swift_SmtpTransport::newInstance( $this->host, $this->port, $this->encryption); $connection_timeout = $this->wp->applyFilters('mailpoet_mailer_smtp_connection_timeout', self::SMTP_CONNECTION_TIMEOUT); $transport->setTimeout($connection_timeout); @@ -83,11 +88,11 @@ class SMTP { ->setPassword($this->password); } $transport = $this->wp->applyFilters('mailpoet_mailer_smtp_transport_agent', $transport); - return \Swift_Mailer::newInstance($transport); + return Swift_Mailer::newInstance($transport); } function createMessage($newsletter, $subscriber, $extra_params = []) { - $message = \Swift_Message::newInstance() + $message = Swift_Message::newInstance() ->setTo($this->processSubscriber($subscriber)) ->setFrom( [ diff --git a/prefixer/composer.json b/prefixer/composer.json index 905dd36f0a..00548e6580 100644 --- a/prefixer/composer.json +++ b/prefixer/composer.json @@ -7,6 +7,7 @@ "gregwar/captcha": "^1.1", "monolog/monolog": "^1.23", "sabberworm/php-css-parser": "^8.1", + "swiftmailer/swiftmailer": "5.4.12", "symfony/dependency-injection": "3.4.26", "symfony/polyfill-mbstring": "^1.11", "symfony/polyfill-php72": "^1.11", @@ -21,7 +22,8 @@ "../tools/vendor/php-scoper.phar add-prefix", "mv ./build/* ../vendor-prefixed", "php fix-twig.php", - "php fix-doctrine.php" + "php fix-doctrine.php", + "php fix-swiftmailer.php" ] }, "config": { diff --git a/prefixer/composer.lock b/prefixer/composer.lock index 3b5345178e..7e948cf790 100644 --- a/prefixer/composer.lock +++ b/prefixer/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "74021a12e7237e4a9994dff6fc888b6e", + "content-hash": "3c34a814f0565a78f75d50814f8a165d", "packages": [ { "name": "doctrine/annotations", @@ -883,6 +883,60 @@ ], "time": "2018-07-13T13:23:56+00:00" }, + { + "name": "swiftmailer/swiftmailer", + "version": "v5.4.12", + "source": { + "type": "git", + "url": "https://github.com/swiftmailer/swiftmailer.git", + "reference": "181b89f18a90f8925ef805f950d47a7190e9b950" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/181b89f18a90f8925ef805f950d47a7190e9b950", + "reference": "181b89f18a90f8925ef805f950d47a7190e9b950", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "mockery/mockery": "~0.9.1", + "symfony/phpunit-bridge": "~3.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.4-dev" + } + }, + "autoload": { + "files": [ + "lib/swift_required.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Chris Corbyn" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "Swiftmailer, free feature-rich PHP mailer", + "homepage": "https://swiftmailer.symfony.com", + "keywords": [ + "email", + "mail", + "mailer" + ], + "time": "2018-07-31T09:26:32+00:00" + }, { "name": "symfony/console", "version": "v3.4.29", diff --git a/prefixer/fix-swiftmailer.php b/prefixer/fix-swiftmailer.php new file mode 100755 index 0000000000..3774ae98bb --- /dev/null +++ b/prefixer/fix-swiftmailer.php @@ -0,0 +1,29 @@ +mapper->getErrorFromException(new \Swift_RfcComplianceException($message), 'john@rambo.com'); + $error = $this->mapper->getErrorFromException(new Swift_RfcComplianceException($message), 'john@rambo.com'); expect($error->getLevel())->equals(MailerError::LEVEL_SOFT); }