jenkins-bot has submitted this change and it was merged.

Change subject: Add Alternative Mailer support for Amazon Simple Email Service.
......................................................................


Add Alternative Mailer support for Amazon Simple Email Service.

Change-Id: I2d5d14020e23da90709614cabce8ec57a640ad7d
---
M AWS.php
M composer.json
M composer.lock
A ses/AmazonSesAlternateUserMailer.php
4 files changed, 236 insertions(+), 77 deletions(-)

Approvals:
  Parent5446: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/AWS.php b/AWS.php
index c9c67b2..d058518 100644
--- a/AWS.php
+++ b/AWS.php
@@ -30,7 +30,10 @@
        'name'           => 'AWS',
        'url'            => 'https://www.mediawiki.org/wiki/Extension:AWS',
        'version'        => '0.6.0',
-       'author'         => 'Tyler Romeo',
+       'author'         => array(
+               'Tyler Romeo',
+               'Daniel Friesen @ Redwerks',
+       ),
        'descriptionmsg' => 'aws-desc'
 );
 
@@ -48,6 +51,11 @@
 $wgAWSRegion = false;
 
 /**
+ * Use SES as a mailer
+ */
+$wgAWSSES = null;
+
+/**
  * Whether to use HTTPS with AWS
  */
 $wgAWSUseHTTPS = true;
@@ -58,6 +66,9 @@
 $wgAutoloadClasses['AmazonS3FileBackend'] = __DIR__ . 
'/s3/AmazonS3FileBackend.php';
 $wgAutoloadClasses['AmazonS3FileIterator'] = __DIR__ . 
'/s3/AmazonS3FileBackend.php';
 $wgAutoloadClasses['AmazonS3DirectoryIterator'] = __DIR__ . 
'/s3/AmazonS3FileBackend.php';
+$wgAutoloadClasses['AmazonSesAlternateUserMailer'] = __DIR__ . 
'/ses/AmazonSesAlternateUserMailer.php';
+
+$wgHooks['AlternateUserMailer'][] = 'AmazonSesAlternateUserMailer::hook';
 
 $wgJobTypeConf['sqs'] = array(
        'class' => 'JobQueueAmazonSqs',
diff --git a/composer.json b/composer.json
index 2fac41e..67bb37b 100644
--- a/composer.json
+++ b/composer.json
@@ -4,7 +4,7 @@
        "type": "mediawiki-extension",
        "license": "GPL-2.0+",
        "require": {
-               "aws/aws-sdk-php": ">=2.1.1",
+               "aws/aws-sdk-php": "^2.8.20",
                "composer/installers": "~1.0"
        }
 }
diff --git a/composer.lock b/composer.lock
index 8dce841..c920345 100644
--- a/composer.lock
+++ b/composer.lock
@@ -1,38 +1,45 @@
 {
-    "hash": "558822d599154c989db6b8b4a599eaa4",
+    "_readme": [
+        "This file locks the dependencies of your project to a known state",
+        "Read more about it at 
https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file";,
+        "This file is @generated automatically"
+    ],
+    "hash": "edaccf8417fd6d3feb8e6d6edc3b1294",
     "packages": [
         {
             "name": "aws/aws-sdk-php",
-            "version": "2.1.2",
+            "version": "2.8.20",
             "source": {
                 "type": "git",
                 "url": "https://github.com/aws/aws-sdk-php.git";,
-                "reference": "2.1.2"
+                "reference": "e01825efad025dbe6d88997e02bd32ec80814381"
             },
             "dist": {
                 "type": "zip",
-                "url": 
"https://api.github.com/repos/aws/aws-sdk-php/zipball/2.1.2";,
-                "reference": "2.1.2",
+                "url": 
"https://api.github.com/repos/aws/aws-sdk-php/zipball/e01825efad025dbe6d88997e02bd32ec80814381";,
+                "reference": "e01825efad025dbe6d88997e02bd32ec80814381",
                 "shasum": ""
             },
             "require": {
-                "guzzle/guzzle": ">=3.2,<3.3",
+                "guzzle/guzzle": "~3.7",
                 "php": ">=5.3.3"
             },
             "require-dev": {
-                "doctrine/common": "2.3.*",
-                "ext-apc": "*",
-                "monolog/monolog": "1.2.*",
-                "phpunit/phpunit": "3.7.*",
-                "symfony/class-loader": "2.*"
+                "doctrine/cache": "~1.0",
+                "ext-openssl": "*",
+                "monolog/monolog": "~1.4",
+                "phpunit/phpunit": "~4.0",
+                "phpunit/phpunit-mock-objects": "2.3.1",
+                "symfony/yaml": "~2.1"
             },
-            "time": "2013-02-19 01:30:36",
+            "suggest": {
+                "doctrine/cache": "Adds support for caching of credentials and 
responses",
+                "ext-apc": "Allows service description opcode caching, request 
and response caching, and credentials caching",
+                "ext-openssl": "Allows working with CloudFront private 
distributions and verifying received SNS messages",
+                "monolog/monolog": "Adds support for logging HTTP requests and 
responses",
+                "symfony/yaml": "Eases the ability to write manifests for 
creating jobs in AWS Import/Export"
+            },
             "type": "library",
-            "extra": {
-                "branch-alias": {
-                    "dev-master": "2.1.x-dev"
-                }
-            },
             "autoload": {
                 "psr-0": {
                     "Aws": "src/"
@@ -48,39 +55,42 @@
                     "homepage": "http://aws.amazon.com";
                 }
             ],
-            "description": "AWS SDK for PHP",
-            "homepage": "http://aws.amazon.com/sdkforphp2";,
+            "description": "AWS SDK for PHP - Use Amazon Web Services in your 
PHP project",
+            "homepage": "http://aws.amazon.com/sdkforphp";,
             "keywords": [
                 "amazon",
                 "aws",
+                "cloud",
                 "dynamodb",
                 "ec2",
+                "glacier",
                 "s3",
                 "sdk"
-            ]
+            ],
+            "time": "2015-09-03 22:25:15"
         },
         {
             "name": "composer/installers",
-            "version": "v1.0.2",
+            "version": "v1.0.21",
             "source": {
                 "type": "git",
                 "url": "https://github.com/composer/installers.git";,
-                "reference": "v1.0.2"
+                "reference": "d64e23fce42a4063d63262b19b8e7c0f3b5e4c45"
             },
             "dist": {
                 "type": "zip",
-                "url": 
"https://api.github.com/repos/composer/installers/zipball/v1.0.2";,
-                "reference": "v1.0.2",
+                "url": 
"https://api.github.com/repos/composer/installers/zipball/d64e23fce42a4063d63262b19b8e7c0f3b5e4c45";,
+                "reference": "d64e23fce42a4063d63262b19b8e7c0f3b5e4c45",
                 "shasum": ""
             },
             "replace": {
+                "roundcube/plugin-installer": "*",
                 "shama/baton": "*"
             },
             "require-dev": {
                 "composer/composer": "1.0.*@dev",
-                "phpunit/phpunit": "3.7.*"
+                "phpunit/phpunit": "4.1.*"
             },
-            "time": "2013-02-18 00:51:06",
             "type": "composer-installer",
             "extra": {
                 "class": "Composer\\Installers\\Installer",
@@ -101,53 +111,77 @@
                 {
                     "name": "Kyle Robinson Young",
                     "email": "[email protected]",
-                    "homepage": "http://dontkry.com";,
-                    "role": "Developer"
+                    "homepage": "https://github.com/shama";
                 }
             ],
             "description": "A multi-framework Composer library installer",
             "homepage": "http://composer.github.com/installers/";,
             "keywords": [
-                "TYPO3 Flow",
-                "TYPO3 Neos",
+                "Craft",
+                "Dolibarr",
+                "Hurad",
+                "MODX Evo",
+                "OXID",
+                "SMF",
+                "Thelia",
+                "WolfCMS",
                 "agl",
+                "aimeos",
+                "annotatecms",
+                "bitrix",
                 "cakephp",
+                "chef",
                 "codeigniter",
+                "concrete5",
+                "croogo",
+                "dokuwiki",
                 "drupal",
+                "elgg",
                 "fuelphp",
+                "grav",
                 "installer",
                 "joomla",
                 "kohana",
                 "laravel",
-                "li3",
                 "lithium",
+                "magento",
                 "mako",
+                "mediawiki",
+                "modulework",
+                "moodle",
                 "phpbb",
+                "piwik",
                 "ppi",
+                "puppet",
+                "roundcube",
+                "shopware",
                 "silverstripe",
                 "symfony",
+                "typo3",
                 "wordpress",
-                "zend"
-            ]
+                "zend",
+                "zikula"
+            ],
+            "time": "2015-02-18 17:17:01"
         },
         {
             "name": "guzzle/guzzle",
-            "version": "v3.2.0",
+            "version": "v3.9.3",
             "source": {
                 "type": "git",
-                "url": "https://github.com/guzzle/guzzle.git";,
-                "reference": "v3.2.0"
+                "url": "https://github.com/guzzle/guzzle3.git";,
+                "reference": "0645b70d953bc1c067bbc8d5bc53194706b628d9"
             },
             "dist": {
                 "type": "zip",
-                "url": 
"https://api.github.com/repos/guzzle/guzzle/zipball/v3.2.0";,
-                "reference": "v3.2.0",
+                "url": 
"https://api.github.com/repos/guzzle/guzzle3/zipball/0645b70d953bc1c067bbc8d5bc53194706b628d9";,
+                "reference": "0645b70d953bc1c067bbc8d5bc53194706b628d9",
                 "shasum": ""
             },
             "require": {
                 "ext-curl": "*",
-                "php": ">=5.3.2",
-                "symfony/event-dispatcher": ">=2.1"
+                "php": ">=5.3.3",
+                "symfony/event-dispatcher": "~2.1"
             },
             "replace": {
                 "guzzle/batch": "self.version",
@@ -164,6 +198,7 @@
                 "guzzle/plugin-cache": "self.version",
                 "guzzle/plugin-cookie": "self.version",
                 "guzzle/plugin-curlauth": "self.version",
+                "guzzle/plugin-error-response": "self.version",
                 "guzzle/plugin-history": "self.version",
                 "guzzle/plugin-log": "self.version",
                 "guzzle/plugin-md5": "self.version",
@@ -173,26 +208,27 @@
                 "guzzle/stream": "self.version"
             },
             "require-dev": {
-                "doctrine/common": "*",
-                "monolog/monolog": "1.*",
+                "doctrine/cache": "~1.3",
+                "monolog/monolog": "~1.0",
                 "phpunit/phpunit": "3.7.*",
-                "symfony/class-loader": "*",
-                "zend/zend-cache1": "1.12",
-                "zend/zend-log1": "1.12",
-                "zendframework/zend-cache": "2.0.*",
-                "zendframework/zend-log": "2.0.*"
+                "psr/log": "~1.0",
+                "symfony/class-loader": "~2.1",
+                "zendframework/zend-cache": "2.*,<2.3",
+                "zendframework/zend-log": "2.*,<2.3"
             },
-            "time": "2013-02-15 01:33:10",
+            "suggest": {
+                "guzzlehttp/guzzle": "Guzzle 5 has moved to a new package 
name. The package you have installed, Guzzle 3, is deprecated."
+            },
             "type": "library",
             "extra": {
                 "branch-alias": {
-                    "dev-master": "3.1-dev"
+                    "dev-master": "3.9-dev"
                 }
             },
             "autoload": {
                 "psr-0": {
-                    "Guzzle\\Tests": "tests/",
-                    "Guzzle": "src/"
+                    "Guzzle": "src/",
+                    "Guzzle\\Tests": "tests/"
                 }
             },
             "notification-url": "https://packagist.org/downloads/";,
@@ -210,7 +246,7 @@
                     "homepage": "https://github.com/guzzle/guzzle/contributors";
                 }
             ],
-            "description": "Guzzle is a PHP HTTP client library and framework 
for building RESTful web service clients",
+            "description": "PHP HTTP client. This library is deprecated in 
favor of https://packagist.org/packages/guzzlehttp/guzzle";,
             "homepage": "http://guzzlephp.org/";,
             "keywords": [
                 "client",
@@ -220,38 +256,47 @@
                 "http client",
                 "rest",
                 "web service"
-            ]
+            ],
+            "time": "2015-03-18 18:23:50"
         },
         {
             "name": "symfony/event-dispatcher",
-            "version": "v2.1.7",
-            "target-dir": "Symfony/Component/EventDispatcher",
+            "version": "v2.7.3",
             "source": {
                 "type": "git",
-                "url": "https://github.com/symfony/EventDispatcher";,
-                "reference": "v2.1.7"
+                "url": "https://github.com/symfony/EventDispatcher.git";,
+                "reference": "9310b5f9a87ec2ea75d20fec0b0017c77c66dac3"
             },
             "dist": {
                 "type": "zip",
-                "url": 
"https://github.com/symfony/EventDispatcher/archive/v2.1.7.zip";,
-                "reference": "v2.1.7",
+                "url": 
"https://api.github.com/repos/symfony/EventDispatcher/zipball/9310b5f9a87ec2ea75d20fec0b0017c77c66dac3";,
+                "reference": "9310b5f9a87ec2ea75d20fec0b0017c77c66dac3",
                 "shasum": ""
             },
             "require": {
-                "php": ">=5.3.3"
+                "php": ">=5.3.9"
             },
             "require-dev": {
-                "symfony/dependency-injection": "2.1.*"
+                "psr/log": "~1.0",
+                "symfony/config": "~2.0,>=2.0.5",
+                "symfony/dependency-injection": "~2.6",
+                "symfony/expression-language": "~2.6",
+                "symfony/phpunit-bridge": "~2.7",
+                "symfony/stopwatch": "~2.3"
             },
             "suggest": {
-                "symfony/dependency-injection": "2.1.*",
-                "symfony/http-kernel": "2.1.*"
+                "symfony/dependency-injection": "",
+                "symfony/http-kernel": ""
             },
-            "time": "2013-01-11 00:31:43",
             "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "2.7-dev"
+                }
+            },
             "autoload": {
-                "psr-0": {
-                    "Symfony\\Component\\EventDispatcher": ""
+                "psr-4": {
+                    "Symfony\\Component\\EventDispatcher\\": ""
                 }
             },
             "notification-url": "https://packagist.org/downloads/";,
@@ -265,19 +310,20 @@
                 },
                 {
                     "name": "Symfony Community",
-                    "homepage": "http://symfony.com/contributors";
+                    "homepage": "https://symfony.com/contributors";
                 }
             ],
             "description": "Symfony EventDispatcher Component",
-            "homepage": "http://symfony.com";
+            "homepage": "https://symfony.com";,
+            "time": "2015-06-18 19:21:56"
         }
     ],
-    "packages-dev": null,
-    "aliases": [
-
-    ],
+    "packages-dev": [],
+    "aliases": [],
     "minimum-stability": "stable",
-    "stability-flags": [
-
-    ]
+    "stability-flags": [],
+    "prefer-stable": false,
+    "prefer-lowest": false,
+    "platform": [],
+    "platform-dev": []
 }
diff --git a/ses/AmazonSesAlternateUserMailer.php 
b/ses/AmazonSesAlternateUserMailer.php
new file mode 100644
index 0000000..bf4502b
--- /dev/null
+++ b/ses/AmazonSesAlternateUserMailer.php
@@ -0,0 +1,102 @@
+<?php
+
+/**
+ * Implements the AWS extension for MediaWiki.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+use Aws\Ses\SesClient;
+use Aws\Ses\Exception\SesException;
+
+/**
+ * Mailer for Amazon Simple Email Service
+ *
+ * @author Daniel Friesen <[email protected]>
+ */
+abstract class AmazonSesAlternateUserMailer {
+
+       static function hook( $headers, $to, $from, $subject, $body ) {
+               global $wgAWSSES;
+               if ( $wgAWSSES ) {
+                       try {
+                               self::send( $headers, $to, $from, $subject, 
$body );
+                       } catch ( MWException $e ) {
+                               return $e->getMessage();
+                       }
+
+                       return false;
+               }
+
+               return true;
+       }
+
+       private static function send( $headers, $to, $from, $subject, $body ) {
+               global $wgAWSSES, $wgAWSCredentials, $wgAWSRegion, 
$wgAWSUseHTTPS, $wgEnotifMaxRecips;
+               $params = $wgAWSSES === true ? array() : $wgAWSSES;
+
+               wfDebug( "Sending mail via Aws\\Ses\\SesClient\n" );
+
+               if ( isset( $params['aws-https'] ) ) {
+                       $useHTTPS = (bool)$params['aws-https'];
+               } else {
+                       $useHTTPS = (bool)$wgAWSUseHTTPS;
+               }
+
+               $client = SesClient::factory( array(
+                       'key' => isset( $params['aws-key'] ) ? 
$params['aws-key'] : $wgAWSCredentials['key'],
+                       'secret' => isset( $params['aws-secret'] ) ? 
$params['aws-secret'] : $wgAWSCredentials['secret'],
+                       'region' => isset( $params['aws-region'] ) ? 
$params['aws-region'] : $wgAWSRegion,
+                       'scheme' => $useHTTPS ? 'https' : 'http',
+                       'ssl.certificate_authority' => $useHTTPS ?: null
+               ) );
+
+               if ( wfIsWindows() ) {
+                       $endl = "\r\n";
+               } else {
+                       $endl = "\n";
+               }
+
+               $headers['Subject'] = UserMailer::quotedPrintable( $subject );
+
+               # When sending only to one recipient, shows it its email using 
To:
+               if ( count( $to ) == 1 ) {
+                       $headers['To'] = $to[0]->toString();
+               }
+
+               $headers = UserMailer::arrayToHeaderString( $headers, $endl );
+               $rawMessage = $headers . $endl . $endl . $body;
+
+               $chunks = array_chunk( $to, min( 50, $wgEnotifMaxRecips ) );
+               foreach ( $chunks as $chunk ) {
+                       try {
+                               $client->sendRawEmail( array(
+                                       'Destinations' => $chunk,
+                                       'RawMessage' => array(
+                                               'Data' => 
base64_encode($rawMessage)
+                                       )
+                               ) );
+                       } catch ( SesException $e ) {
+                               # FIXME : some chunks might be sent while 
others are not!
+                               throw new MWException( "Amazon SQS error: 
{$e->getMessage()}", 0, $e );
+                       }
+               }
+
+               return true;
+       }
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/236227
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I2d5d14020e23da90709614cabce8ec57a640ad7d
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/AWS
Gerrit-Branch: master
Gerrit-Owner: Daniel Friesen <[email protected]>
Gerrit-Reviewer: Daniel Friesen <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Parent5446 <[email protected]>
Gerrit-Reviewer: Thaiphan <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to