Update composer dependencies and add SES transport

This commit is contained in:
Kijin Sung 2016-05-06 17:33:43 +09:00
parent 7cb194439f
commit a12722ad79
97 changed files with 1516 additions and 409 deletions

View file

@ -23,6 +23,7 @@
"ezyang/htmlpurifier": "4.7.*", "ezyang/htmlpurifier": "4.7.*",
"hautelook/phpass": "0.3.*", "hautelook/phpass": "0.3.*",
"jbbcode/jbbcode": "1.3.*", "jbbcode/jbbcode": "1.3.*",
"jmhobbs/swiftmailer-transport-aws-ses": "0.9.*",
"leafo/lessphp": "0.5.*", "leafo/lessphp": "0.5.*",
"leafo/scssphp": "0.6.*", "leafo/scssphp": "0.6.*",
"league/html-to-markdown": "4.2.*", "league/html-to-markdown": "4.2.*",

70
composer.lock generated
View file

@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"hash": "ff1a5bab9497b1e5f25dd3069ffbbf13", "hash": "64d8278cd705dec01a94208e378716f8",
"content-hash": "9478a148fd56f1f50543063e3971a777", "content-hash": "fa544ace96d8d80c11db9dafb2c49753",
"packages": [ "packages": [
{ {
"name": "defuse/php-encryption", "name": "defuse/php-encryption",
@ -186,6 +186,49 @@
], ],
"time": "2014-07-06 05:48:20" "time": "2014-07-06 05:48:20"
}, },
{
"name": "jmhobbs/swiftmailer-transport-aws-ses",
"version": "0.9.2",
"source": {
"type": "git",
"url": "https://github.com/jmhobbs/Swiftmailer-Transport--AWS-SES.git",
"reference": "10110a450225a19b5095e7313a5c7c4b43bba3b6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/jmhobbs/Swiftmailer-Transport--AWS-SES/zipball/10110a450225a19b5095e7313a5c7c4b43bba3b6",
"reference": "10110a450225a19b5095e7313a5c7c4b43bba3b6",
"shasum": ""
},
"require": {
"php": ">=5.2.0",
"swiftmailer/swiftmailer": ">=4.0.0"
},
"type": "library",
"autoload": {
"psr-0": {
"": "classes/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "John Hobbs",
"email": "john@velvetcache.org"
}
],
"description": "Add AWS SES support to Swiftmailer",
"keywords": [
"aws",
"email",
"ses",
"swiftmailer"
],
"time": "2014-11-12 23:51:28"
},
{ {
"name": "leafo/lessphp", "name": "leafo/lessphp",
"version": "v0.5.0", "version": "v0.5.0",
@ -402,16 +445,16 @@
}, },
{ {
"name": "matthiasmullie/path-converter", "name": "matthiasmullie/path-converter",
"version": "1.0.7", "version": "1.0.8",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/matthiasmullie/path-converter.git", "url": "https://github.com/matthiasmullie/path-converter.git",
"reference": "83609c1bb251b2540eba912615571a501a0a06a6" "reference": "7c36e5cafa95dd20008d19b153b506cffa8c2848"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/matthiasmullie/path-converter/zipball/83609c1bb251b2540eba912615571a501a0a06a6", "url": "https://api.github.com/repos/matthiasmullie/path-converter/zipball/7c36e5cafa95dd20008d19b153b506cffa8c2848",
"reference": "83609c1bb251b2540eba912615571a501a0a06a6", "reference": "7c36e5cafa95dd20008d19b153b506cffa8c2848",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -419,8 +462,7 @@
"php": ">=5.3.0" "php": ">=5.3.0"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "~4.8", "phpunit/phpunit": "~4.8"
"satooshi/php-coveralls": "~1.0"
}, },
"type": "library", "type": "library",
"autoload": { "autoload": {
@ -448,7 +490,7 @@
"paths", "paths",
"relative" "relative"
], ],
"time": "2016-01-07 00:41:13" "time": "2016-04-27 10:38:05"
}, },
{ {
"name": "michelf/php-markdown", "name": "michelf/php-markdown",
@ -650,16 +692,16 @@
}, },
{ {
"name": "swiftmailer/swiftmailer", "name": "swiftmailer/swiftmailer",
"version": "v5.4.1", "version": "v5.4.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/swiftmailer/swiftmailer.git", "url": "https://github.com/swiftmailer/swiftmailer.git",
"reference": "0697e6aa65c83edf97bb0f23d8763f94e3f11421" "reference": "d8db871a54619458a805229a057ea2af33c753e8"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/0697e6aa65c83edf97bb0f23d8763f94e3f11421", "url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/d8db871a54619458a805229a057ea2af33c753e8",
"reference": "0697e6aa65c83edf97bb0f23d8763f94e3f11421", "reference": "d8db871a54619458a805229a057ea2af33c753e8",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -699,7 +741,7 @@
"mail", "mail",
"mailer" "mailer"
], ],
"time": "2015-06-06 14:19:39" "time": "2016-05-01 08:45:47"
}, },
{ {
"name": "true/punycode", "name": "true/punycode",

View file

@ -1,4 +1,4 @@
Copyright (c) 2015 Nils Adermann, Jordi Boggiano Copyright (c) 2016 Nils Adermann, Jordi Boggiano
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View file

@ -6,6 +6,10 @@ $vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir); $baseDir = dirname($vendorDir);
return array( return array(
'AWSConnectionError' => $vendorDir . '/jmhobbs/swiftmailer-transport-aws-ses/classes/Swift/AWSTransport.php',
'AWSEmptyResponseException' => $vendorDir . '/jmhobbs/swiftmailer-transport-aws-ses/classes/Swift/AWSTransport.php',
'AWSResponse' => $vendorDir . '/jmhobbs/swiftmailer-transport-aws-ses/classes/Swift/AWSTransport.php',
'ChunkedTransferSocket' => $vendorDir . '/jmhobbs/swiftmailer-transport-aws-ses/classes/Swift/AWSTransport.php',
'HTMLPurifier' => $vendorDir . '/ezyang/htmlpurifier/library/HTMLPurifier.php', 'HTMLPurifier' => $vendorDir . '/ezyang/htmlpurifier/library/HTMLPurifier.php',
'HTMLPurifier_Arborize' => $vendorDir . '/ezyang/htmlpurifier/library/HTMLPurifier/Arborize.php', 'HTMLPurifier_Arborize' => $vendorDir . '/ezyang/htmlpurifier/library/HTMLPurifier/Arborize.php',
'HTMLPurifier_AttrCollections' => $vendorDir . '/ezyang/htmlpurifier/library/HTMLPurifier/AttrCollections.php', 'HTMLPurifier_AttrCollections' => $vendorDir . '/ezyang/htmlpurifier/library/HTMLPurifier/AttrCollections.php',
@ -236,6 +240,8 @@ return array(
'HTMLPurifier_VarParser_Native' => $vendorDir . '/ezyang/htmlpurifier/library/HTMLPurifier/VarParser/Native.php', 'HTMLPurifier_VarParser_Native' => $vendorDir . '/ezyang/htmlpurifier/library/HTMLPurifier/VarParser/Native.php',
'HTMLPurifier_Zipper' => $vendorDir . '/ezyang/htmlpurifier/library/HTMLPurifier/Zipper.php', 'HTMLPurifier_Zipper' => $vendorDir . '/ezyang/htmlpurifier/library/HTMLPurifier/Zipper.php',
'Hautelook\\Phpass\\PasswordHash' => $vendorDir . '/hautelook/phpass/src/Hautelook/Phpass/PasswordHash.php', 'Hautelook\\Phpass\\PasswordHash' => $vendorDir . '/hautelook/phpass/src/Hautelook/Phpass/PasswordHash.php',
'InvalidHeaderException' => $vendorDir . '/jmhobbs/swiftmailer-transport-aws-ses/classes/Swift/AWSTransport.php',
'InvalidOperationException' => $vendorDir . '/jmhobbs/swiftmailer-transport-aws-ses/classes/Swift/AWSTransport.php',
'JBBCode\\CodeDefinition' => $vendorDir . '/jbbcode/jbbcode/JBBCode/CodeDefinition.php', 'JBBCode\\CodeDefinition' => $vendorDir . '/jbbcode/jbbcode/JBBCode/CodeDefinition.php',
'JBBCode\\CodeDefinitionBuilder' => $vendorDir . '/jbbcode/jbbcode/JBBCode/CodeDefinitionBuilder.php', 'JBBCode\\CodeDefinitionBuilder' => $vendorDir . '/jbbcode/jbbcode/JBBCode/CodeDefinitionBuilder.php',
'JBBCode\\CodeDefinitionSet' => $vendorDir . '/jbbcode/jbbcode/JBBCode/CodeDefinitionSet.php', 'JBBCode\\CodeDefinitionSet' => $vendorDir . '/jbbcode/jbbcode/JBBCode/CodeDefinitionSet.php',
@ -365,6 +371,11 @@ return array(
'Requests_Utility_CaseInsensitiveDictionary' => $vendorDir . '/rmccue/requests/library/Requests/Utility/CaseInsensitiveDictionary.php', 'Requests_Utility_CaseInsensitiveDictionary' => $vendorDir . '/rmccue/requests/library/Requests/Utility/CaseInsensitiveDictionary.php',
'Requests_Utility_FilteredIterator' => $vendorDir . '/rmccue/requests/library/Requests/Utility/FilteredIterator.php', 'Requests_Utility_FilteredIterator' => $vendorDir . '/rmccue/requests/library/Requests/Utility/FilteredIterator.php',
'Sunra\\PhpSimple\\HtmlDomParser' => $vendorDir . '/sunra/php-simple-html-dom-parser/Src/Sunra/PhpSimple/HtmlDomParser.php', 'Sunra\\PhpSimple\\HtmlDomParser' => $vendorDir . '/sunra/php-simple-html-dom-parser/Src/Sunra/PhpSimple/HtmlDomParser.php',
'Swift_AWSInputByteStream' => $vendorDir . '/jmhobbs/swiftmailer-transport-aws-ses/classes/Swift/AWSInputByteStream.php',
'Swift_AWSTransport' => $vendorDir . '/jmhobbs/swiftmailer-transport-aws-ses/classes/Swift/AWSTransport.php',
'Swift_Events_ResponseReceivedListener' => $vendorDir . '/jmhobbs/swiftmailer-transport-aws-ses/classes/Swift/Events/ResponseReceivedListener.php',
'Swift_Response_AWSResponse' => $vendorDir . '/jmhobbs/swiftmailer-transport-aws-ses/classes/Swift/Response/AWSResponse.php',
'Swift_Transport_AWSTransport' => $vendorDir . '/jmhobbs/swiftmailer-transport-aws-ses/classes/Swift/Transport/AWSTransport.php',
'TrueBV\\Punycode' => $vendorDir . '/true/punycode/src/Punycode.php', 'TrueBV\\Punycode' => $vendorDir . '/true/punycode/src/Punycode.php',
'lessc' => $vendorDir . '/leafo/lessphp/lessc.inc.php', 'lessc' => $vendorDir . '/leafo/lessphp/lessc.inc.php',
'lessc_formatter_classic' => $vendorDir . '/leafo/lessphp/lessc.inc.php', 'lessc_formatter_classic' => $vendorDir . '/leafo/lessphp/lessc.inc.php',

View file

@ -6,7 +6,7 @@ $vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir); $baseDir = dirname($vendorDir);
return array( return array(
'2c102faa651ef8ea5874edb585946bce' => $vendorDir . '/swiftmailer/swiftmailer/lib/swift_required.php',
'8170285c807a9f24f165f37b15bc9a36' => $vendorDir . '/defuse/php-encryption/Crypto.php', '8170285c807a9f24f165f37b15bc9a36' => $vendorDir . '/defuse/php-encryption/Crypto.php',
'2cffec82183ee1cea088009cef9a6fc3' => $vendorDir . '/ezyang/htmlpurifier/library/HTMLPurifier.composer.php', '2cffec82183ee1cea088009cef9a6fc3' => $vendorDir . '/ezyang/htmlpurifier/library/HTMLPurifier.composer.php',
'2c102faa651ef8ea5874edb585946bce' => $vendorDir . '/swiftmailer/swiftmailer/lib/swift_required.php',
); );

View file

@ -12,4 +12,5 @@ return array(
'JBBCode' => array($vendorDir . '/jbbcode/jbbcode'), 'JBBCode' => array($vendorDir . '/jbbcode/jbbcode'),
'Hautelook' => array($vendorDir . '/hautelook/phpass/src'), 'Hautelook' => array($vendorDir . '/hautelook/phpass/src'),
'HTMLPurifier' => array($vendorDir . '/ezyang/htmlpurifier/library'), 'HTMLPurifier' => array($vendorDir . '/ezyang/htmlpurifier/library'),
'' => array($vendorDir . '/jmhobbs/swiftmailer-transport-aws-ses/classes'),
); );

View file

@ -188,113 +188,6 @@
"sockets" "sockets"
] ]
}, },
{
"name": "matthiasmullie/path-converter",
"version": "1.0.7",
"version_normalized": "1.0.7.0",
"source": {
"type": "git",
"url": "https://github.com/matthiasmullie/path-converter.git",
"reference": "83609c1bb251b2540eba912615571a501a0a06a6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/matthiasmullie/path-converter/zipball/83609c1bb251b2540eba912615571a501a0a06a6",
"reference": "83609c1bb251b2540eba912615571a501a0a06a6",
"shasum": ""
},
"require": {
"ext-pcre": "*",
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": "~4.8",
"satooshi/php-coveralls": "~1.0"
},
"time": "2016-01-07 00:41:13",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-4": {
"MatthiasMullie\\PathConverter\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Matthias Mullie",
"email": "pathconverter@mullie.eu",
"homepage": "http://www.mullie.eu",
"role": "Developer"
}
],
"description": "Relative path converter",
"homepage": "http://github.com/matthiasmullie/path-converter",
"keywords": [
"converter",
"path",
"paths",
"relative"
]
},
{
"name": "swiftmailer/swiftmailer",
"version": "v5.4.1",
"version_normalized": "5.4.1.0",
"source": {
"type": "git",
"url": "https://github.com/swiftmailer/swiftmailer.git",
"reference": "0697e6aa65c83edf97bb0f23d8763f94e3f11421"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/0697e6aa65c83edf97bb0f23d8763f94e3f11421",
"reference": "0697e6aa65c83edf97bb0f23d8763f94e3f11421",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"mockery/mockery": "~0.9.1,<0.9.4"
},
"time": "2015-06-06 14:19:39",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "5.4-dev"
}
},
"installation-source": "dist",
"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": "http://swiftmailer.org",
"keywords": [
"email",
"mail",
"mailer"
]
},
{ {
"name": "true/punycode", "name": "true/punycode",
"version": "v2.0.2", "version": "v2.0.2",
@ -768,5 +661,156 @@
"scss", "scss",
"stylesheet" "stylesheet"
] ]
},
{
"name": "matthiasmullie/path-converter",
"version": "1.0.8",
"version_normalized": "1.0.8.0",
"source": {
"type": "git",
"url": "https://github.com/matthiasmullie/path-converter.git",
"reference": "7c36e5cafa95dd20008d19b153b506cffa8c2848"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/matthiasmullie/path-converter/zipball/7c36e5cafa95dd20008d19b153b506cffa8c2848",
"reference": "7c36e5cafa95dd20008d19b153b506cffa8c2848",
"shasum": ""
},
"require": {
"ext-pcre": "*",
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": "~4.8"
},
"time": "2016-04-27 10:38:05",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-4": {
"MatthiasMullie\\PathConverter\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Matthias Mullie",
"email": "pathconverter@mullie.eu",
"homepage": "http://www.mullie.eu",
"role": "Developer"
}
],
"description": "Relative path converter",
"homepage": "http://github.com/matthiasmullie/path-converter",
"keywords": [
"converter",
"path",
"paths",
"relative"
]
},
{
"name": "swiftmailer/swiftmailer",
"version": "v5.4.2",
"version_normalized": "5.4.2.0",
"source": {
"type": "git",
"url": "https://github.com/swiftmailer/swiftmailer.git",
"reference": "d8db871a54619458a805229a057ea2af33c753e8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/d8db871a54619458a805229a057ea2af33c753e8",
"reference": "d8db871a54619458a805229a057ea2af33c753e8",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"mockery/mockery": "~0.9.1,<0.9.4"
},
"time": "2016-05-01 08:45:47",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "5.4-dev"
}
},
"installation-source": "dist",
"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": "http://swiftmailer.org",
"keywords": [
"email",
"mail",
"mailer"
]
},
{
"name": "jmhobbs/swiftmailer-transport-aws-ses",
"version": "0.9.2",
"version_normalized": "0.9.2.0",
"source": {
"type": "git",
"url": "https://github.com/jmhobbs/Swiftmailer-Transport--AWS-SES.git",
"reference": "10110a450225a19b5095e7313a5c7c4b43bba3b6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/jmhobbs/Swiftmailer-Transport--AWS-SES/zipball/10110a450225a19b5095e7313a5c7c4b43bba3b6",
"reference": "10110a450225a19b5095e7313a5c7c4b43bba3b6",
"shasum": ""
},
"require": {
"php": ">=5.2.0",
"swiftmailer/swiftmailer": ">=4.0.0"
},
"time": "2014-11-12 23:51:28",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-0": {
"": "classes/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "John Hobbs",
"email": "john@velvetcache.org"
}
],
"description": "Add AWS SES support to Swiftmailer",
"keywords": [
"aws",
"email",
"ses",
"swiftmailer"
]
} }
] ]

View file

@ -0,0 +1,3 @@
composer.lock
vendor/*
example/config.php

View file

@ -0,0 +1,19 @@
Copyright (c) 2011 John Hobbs
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE

View file

@ -0,0 +1,67 @@
# What is it?
It's a simple transport for use with Swiftmailer to send mail over AWS SES.
As on December 2011, Amazon [provides an SMTP interface to SES](http://aws.amazon.com/ses/faqs/#21), so you may prefer to use Swiftmailer's built in SMTP transport.
# Where do I put it?
Whereever you want, so long as you include it in your code.
Otherwise Swift can autoload it if you put the files in this directory:
[swift library root]/classes/Swift/AWSTransport.php
# How do I use it?
Like any other Swiftmailer transport:
//Create the Transport
$transport = Swift_AWSTransport::newInstance( 'AWS_ACCESS_KEY', 'AWS_SECRET_KEY' );
//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
$mailer->send($message);
# Symfony1.X configuration
```yaml
# app/frontend/config/factories.yml
all:
mailer:
class: sfMailer
param:
transport:
class: Swift_AWSTransport
accessKeyId: your-access-key
secretKey: Y0uR-$3cr3t5-k3y
debug: false
endpoint: 'https://email.us-east-1.amazonaws.com/' # make sure to use trailing slash !
```
# How do I get the message ID on send?
You need to register the Swift_Events_ResponseReceivedListener plugin with a callback. See example/responseListener.php for details.
$transport->registerPlugin(
new Swift_Events_ResponseReceivedListener( function ( $message, $body ) {
echo sprintf( "Message-ID %s.\n", $body->SendRawEmailResult->MessageId );
})
);
# Swiftmailer Version
Please note that some users [have had issues with older versions of Swiftmailer](https://github.com/jmhobbs/Swiftmailer-Transport--AWS-SES/issues/13).
Versions 4.1.3 and up should work fine.
# Credits
* @jmhobbs - Original development
* @bertrandom - Bug fix
* @themouette - Plugins & Symfony compatible
* @jonatrey & @faz - Debugging and Testing issue #13
* @casconed - Made debug function more robust, issue #21
* @martijngastkemper - Added responseReceived event to get message id from AWS

View file

@ -0,0 +1,90 @@
<?php
class Swift_AWSInputByteStream implements Swift_InputByteStream {
public function __construct( $socket ) {
$this->socket = $socket;
$this->buffer = '';
$this->counter = 0;
}
/**
* Writes $bytes to the end of the stream.
*
* Writing may not happen immediately if the stream chooses to buffer. If
* you want to write these bytes with immediate effect, call {@link commit()}
* after calling write().
*
* This method returns the sequence ID of the write (i.e. 1 for first, 2 for
* second, etc etc).
*
* @param string $bytes
* @return int
*/
public function write($bytes) {
$block = $this->buffer . $bytes;
$block_size = strlen( $block );
$encoded = base64_encode( $block );
$setback = 0;
while( substr( $encoded, -1 ) === '=' ) {
++$setback;
if( $setback >= $block_size ) {
$this->buffer = $block;
return ++$this->counter;
}
$encoded = base64_encode( substr( $block, 0, $setback * -1 ) );
}
if( $setback > 0 ) {
$this->buffer = substr( $block, $setback * -1 );
}
else {
$this->buffer = '';
}
unset( $block );
$this->socket->write( urlencode( $encoded ) );
unset( $encoded );
return ++$this->counter;
}
/**
* For any bytes that are currently buffered inside the stream, force them
* off the buffer.
*/
public function commit() {
// NOP - Since we have a required packet offset (3-bytes), we can't commit arbitrarily.
}
public function flushBuffers() {
if( strlen( $this->buffer ) > 0 ) {
$this->socket->write( urlencode( base64_encode( $this->buffer ) ) );
}
$this->socket->finishWrite();
}
/**
* Attach $is to this stream.
* The stream acts as an observer, receiving all data that is written.
* All {@link write()} and {@link flushBuffers()} operations will be mirrored.
*
* @param Swift_InputByteStream $is
*/
public function bind(Swift_InputByteStream $is){}
/**
* Remove an already bound stream.
* If $is is not bound, no errors will be raised.
* If the stream currently has any buffered data it will be written to $is
* before unbinding occurs.
*
* @param Swift_InputByteStream $is
*/
public function unbind(Swift_InputByteStream $is){}
}

View file

@ -0,0 +1,356 @@
<?php
/*
* This file requires SwiftMailer.
* (c) 2011 John Hobbs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Sends Messages over AWS.
* @package Swift
* @subpackage Transport
* @author John Hobbs
*/
class Swift_AWSTransport extends Swift_Transport_AWSTransport {
/** the service access key */
private $AWSAccessKeyId;
/** the service secret key */
private $AWSSecretKey;
/** the service endpoint */
private $endpoint;
/**
* Debugging helper.
*
* If false, no debugging will be done.
* If true, debugging will be done with error_log.
* Otherwise, this should be a callable, and will recieve the debug message as the first argument.
*
* @seealso Swift_AWSTransport::setDebug()
*/
private $debug;
/** the response */
private $response;
/**
* Create a new AWSTransport.
* @param string $AWSAccessKeyId Your access key.
* @param string $AWSSecretKey Your secret key.
* @param boolean $debug Set to true to enable debug messages in error log.
* @param string $endpoint The AWS endpoint to use.
*/
public function __construct($AWSAccessKeyId = null , $AWSSecretKey = null, $debug = false, $endpoint = 'https://email.us-east-1.amazonaws.com/') {
call_user_func_array(
array($this, 'Swift_Transport_AWSTransport::__construct'),
Swift_DependencyContainer::getInstance()
->createDependenciesFor('transport.aws')
);
$this->AWSAccessKeyId = $AWSAccessKeyId;
$this->AWSSecretKey = $AWSSecretKey;
$this->endpoint = $endpoint;
$this->debug = $debug;
}
/**
* Create a new AWSTransport.
* @param string $AWSAccessKeyId Your access key.
* @param string $AWSSecretKey Your secret key.
*/
public static function newInstance( $AWSAccessKeyId , $AWSSecretKey ) {
return new Swift_AWSTransport( $AWSAccessKeyId , $AWSSecretKey );
}
public function setAccessKeyId($val) {
$this->AWSAccessKeyId = $val;
}
public function setSecretKey($val) {
$this->AWSSecretKey = $val;
}
public function setDebug($val) {
$this->debug = $val;
}
public function setEndpoint($val) {
$this->endpoint = $val;
}
public function getResponse() {
return $this->response;
}
protected function _debug ( $message ) {
if ( true === $this->debug ) {
error_log( $message );
} elseif ( is_callable($this->debug) ) {
call_user_func( $this->debug, $message );
}
}
/**
* Send the given Message.
*
* Recipient/sender data will be retreived from the Message API.
* The return value is the number of recipients who were accepted for delivery.
*
* @param Swift_Mime_Message $message
* @param string[] &$failedRecipients to collect failures by-reference
* @return int
* @throws AWSConnectionError
*/
public function send( Swift_Mime_Message $message, &$failedRecipients = null ) {
if ($evt = $this->_eventDispatcher->createSendEvent($this, $message))
{
$this->_eventDispatcher->dispatchEvent($evt, 'beforeSendPerformed');
if ($evt->bubbleCancelled())
{
return 0;
}
}
$this->response = $this->_doSend($message, $failedRecipients);
$this->_debug("=== Start AWS Response ===");
$this->_debug($this->response->body);
$this->_debug("=== End AWS Response ===");
$success = (200 == $this->response->code);
if ($respEvent = $this->_eventDispatcher->createResponseEvent($this, new Swift_Response_AWSResponse( $message, $this->response->xml ), $success))
$this->_eventDispatcher->dispatchEvent($respEvent, 'responseReceived');
if ($evt)
{
$evt->setResult($success ? Swift_Events_SendEvent::RESULT_SUCCESS : Swift_Events_SendEvent::RESULT_FAILED);
$this->_eventDispatcher->dispatchEvent($evt, 'sendPerformed');
}
if( $success ) {
return count((array) $message->getTo());
}
else {
return 0;
}
}
/**
* do send through the API
*
* @param Swift_Mime_Message $message
* @param string[] &$failedRecipients to collect failures by-reference
* @return AWSResponse
*/
protected function _doSend( Swift_Mime_Message $message, &$failedRecipients = null )
{
$date = date( 'D, j F Y H:i:s O' );
if( function_exists( 'hash_hmac' ) and in_array( 'sha1', hash_algos() ) ) {
$hmac = base64_encode( hash_hmac( 'sha1', $date, $this->AWSSecretKey, true ) );
}
else {
$hmac = $this->calculate_RFC2104HMAC( $date, $this->AWSSecretKey );
}
$auth = "AWS3-HTTPS AWSAccessKeyId=" . $this->AWSAccessKeyId . ", Algorithm=HmacSHA1, Signature=" . $hmac;
$host = parse_url( $this->endpoint, PHP_URL_HOST );
$path = parse_url( $this->endpoint, PHP_URL_PATH );
$fp = fsockopen( 'ssl://' . $host , 443, $errno, $errstr, 30 );
if( ! $fp ) {
throw new AWSConnectionError( "$errstr ($errno)" );
}
$socket = new ChunkedTransferSocket( $fp, $host, $path );
$socket->header("Date", $date);
$socket->header("X-Amzn-Authorization", $auth);
$socket->write("Action=SendRawEmail&RawMessage.Data=");
$ais = new Swift_AWSInputByteStream($socket);
$message->toByteStream($ais);
$ais->flushBuffers();
$result = $socket->read();
return $result;
}
/**
* Cribbed from php-aws - Thanks!
* https://github.com/tylerhall/php-aws/blob/master/class.awis.php
* (c) Tyler Hall
* MIT License
*/
protected function calculate_RFC2104HMAC($data, $key) {
return base64_encode (
pack("H*", sha1((str_pad($key, 64, chr(0x00))
^(str_repeat(chr(0x5c), 64))) .
pack("H*", sha1((str_pad($key, 64, chr(0x00))
^(str_repeat(chr(0x36), 64))) . $data))))
);
}
public function isStarted() {}
public function start() {}
public function stop() {}
/**
* Register a plugin.
*
* @param Swift_Events_EventListener $plugin
*/
public function registerPlugin(Swift_Events_EventListener $plugin)
{
$this->_eventDispatcher->bindEventListener($plugin);
}
} // AWSTransport
/**
* Convenience methods to use a socket for chunked transfer in HTTP
*/
class ChunkedTransferSocket {
/**
* @param $socket
* @param $host
* @param $path
* @param $method
*/
public function __construct( $socket, $host, $path, $method="POST" ) {
$this->socket = $socket;
$this->write_started = false;
$this->write_finished = false;
$this->read_started = false;
fwrite( $this->socket, "$method $path HTTP/1.1\r\n" );
$this->header( "Host", $host );
if( "POST" == $method ) {
$this->header( "Content-Type", "application/x-www-form-urlencoded" );
}
$this->header( "Connection", "close" );
$this->header( "Transfer-Encoding", "chunked" );
}
/**
* Add an HTTP header
*
* @param $header
* @param $value
*/
public function header ( $header, $value ) {
if( $this->write_started ) { throw new InvalidOperationException( "Can not write header, body writing has started." ); }
fwrite( $this->socket, "$header: $value\r\n" );
fflush( $this->socket );
}
/**
* Write a chunk of data
* @param $chunk
*/
public function write ( $chunk ) {
if( $this->write_finished ) { throw new InvalidOperationException( "Can not write, reading has started." ); }
if( ! $this->write_started ) {
fwrite( $this->socket, "\r\n" ); // Start message body
$this->write_started = true;
}
fwrite( $this->socket, sprintf( "%x\r\n", strlen( $chunk ) ) );
fwrite( $this->socket, $chunk . "\r\n" );
fflush( $this->socket );
}
/**
* Finish writing chunks and get ready to read.
*/
public function finishWrite () {
$this->write("");
$this->write_finished = true;
}
/**
* Read the socket for a response
*/
public function read () {
if( ! $this->write_finished ) { $this->finishWrite(); }
$this->read_started = true;
$response = new AWSResponse();
while( ! feof( $this->socket ) ) {
$response->line( fgets( $this->socket ) );
}
$response->complete();
fclose( $this->socket );
return $response;
}
}
/**
* A wrapper to parse an AWS HTTP response
*/
class AWSResponse {
public $headers = array();
public $code = 0;
public $message = '';
public $body = '';
public $xml = null;
const STATE_EMPTY = 0;
const STATE_HEADERS = 1;
const STATE_BODY = 2;
protected $state = self::STATE_EMPTY;
public function line ( $line ) {
switch( $this->state ) {
case self::STATE_EMPTY:
if( ! $line ) {
throw new AWSEmptyResponseException();
}
$split = explode( ' ', $line );
$this->code = $split[1];
$this->message = implode( array_slice( $split, 2 ), ' ' );
$this->state = self::STATE_HEADERS;
break;
case self::STATE_HEADERS:
if( "\r\n" == $line ) {
$this->state = self::STATE_BODY;
break;
}
$pos = strpos( $line, ':' );
if( false === $pos ) { throw new InvalidHeaderException( $line ); }
$key = substr( $line, 0, $pos );
$this->headers[$key] = substr( $line, $pos );
break;
case self::STATE_BODY:
$this->body .= $line;
break;
}
}
public function complete () {
$this->xml = simplexml_load_string( $this->body );
}
}
class AWSConnectionError extends Exception {}
class InvalidOperationException extends Exception {}
class InvalidHeaderException extends Exception {}
class AWSEmptyResponseException extends Exception {}

View file

@ -0,0 +1,19 @@
<?php
class Swift_Events_ResponseReceivedListener
implements Swift_Events_ResponseListener
{
private $callback;
public function __construct( callable $callback )
{
$this->callback = $callback;
}
public function responseReceived( \Swift_Events_ResponseEvent $event )
{
$callback = $this->callback;
$callback( $event->getResponse()->getMessage(), $event->getResponse()->getBody() );
}
}

View file

@ -0,0 +1,36 @@
<?php
class Swift_Response_AWSResponse {
protected $message;
protected $body;
public function __construct( Swift_Mime_Message $message, $body = null )
{
$this->message = $message;
$this->body = $body;
}
function getMessage()
{
return $this->message;
}
function getBody()
{
return $this->body;
}
function setMessage( $message )
{
$this->message = $message;
return $this;
}
function setBody( $body )
{
$this->body = $body;
return $this;
}
}

View file

@ -0,0 +1,35 @@
<?php
/**
* This file declare the Swist_Transport_AWSTransport class.
*
* @package Swift
* @subpackage Transport
* @author Julien Muetton <julien_muetton@carpe-hora.com>
* @copyright (c) Carpe Hora SARL 2011
* @since 2011-10-07
*/
/**
* the base class for aws transport
*/
abstract class Swift_Transport_AWSTransport implements Swift_Transport
{
/** The event dispatcher from the plugin API */
protected $_eventDispatcher;
/**
* Constructor.
*/
public function __construct(Swift_Events_EventDispatcher $eventDispatcher)
{
$this->_eventDispatcher = $eventDispatcher;
}
} // END OF Swist_Transport_AWSTransport
// now register dependancies
Swift_DependencyContainer::getInstance()
-> register('transport.aws')
-> withDependencies(array('transport.eventdispatcher'))
;

View file

@ -0,0 +1,20 @@
{
"name": "jmhobbs/swiftmailer-transport-aws-ses",
"type": "library",
"description": "Add AWS SES support to Swiftmailer",
"keywords": [ "email", "swiftmailer", "SES", "AWS" ],
"license": "MIT",
"authors": [
{
"name": "John Hobbs",
"email": "john@velvetcache.org"
}
],
"require": {
"php": ">=5.2.0",
"swiftmailer/swiftmailer": ">=4.0.0"
},
"autoload": {
"psr-0": { "": "classes/" }
}
}

View file

@ -0,0 +1,13 @@
<?php
// AWS Credentials
define( 'AWSAccessKeyId', 'your-access-key' );
define( 'AWSSecretKey', 'your-secret-key' );
// Email address to send test email from
define( 'FROM_ADDRESS', 'change-this@to-your-email.com' );
// Email address to send test email to
define( 'TO_ADDRESS', 'change-this@as-well-please.com' );
// Set the correct endpoint. http://docs.aws.amazon.com/general/latest/gr/rande.html#ses_region
define( 'AWSSESEndpoint', 'https://email.us-east-1.amazonaws.com/' );

View file

@ -0,0 +1,38 @@
<?php
/*
* Example sending email with AWS.
*
* 1. Run composer.phar install in the root (next to compser.json)
* 2. Copy config.php.example to config.php and add your AWS credentials
* 3. Run this script!
*/
require_once(__DIR__ . '/../vendor/autoload.php');
require_once('./config.php');
$transport = Swift_AWSTransport::newInstance( AWSAccessKeyId, AWSSecretKey );
$transport->setEndpoint( AWSSESEndpoint );
$transport->setDebug( true ); // Print the response from AWS to the error log for debugging.
$transport->registerPlugin(
new Swift_Events_ResponseReceivedListener( function ( $message, $body ) {
echo sprintf( "Message \"%s\" sent by SES with Message-ID %s. Now you can store it in your database to handle bounces, complaints and deliveries.\n", $message->getSubject(), $body->SendRawEmailResult->MessageId );
})
);
//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance( $transport );
//Create the message
$message = Swift_Message::newInstance()
->setSubject( 'Testing Swiftmailer SES' )
->setFrom( array( FROM_ADDRESS ) )
->setTo( array( TO_ADDRESS ) )
->setBody( "<p>Dude, I'm <b>totally</b> sending you email via AWS.</p>", 'text/html' )
->addPart( "Dude, I'm _totally_ sending you email via AWS.", 'text/plain' );
echo "Sending\n";
try {
echo "Sent: " . $mailer->send( $message ) . "\n";
}
catch( AWSEmptyResponseException $e ) {
echo $e . "\n";
}

View file

@ -0,0 +1,32 @@
<?php
/*
* Example sending email with AWS.
*
* 1. Run composer.phar install in the root (next to compser.json)
* 2. Copy config.php.example to config.php and add your AWS credentials
* 3. Run this script!
*/
require_once(__DIR__ . '/../vendor/autoload.php');
require_once('./config.php');
$transport = Swift_AWSTransport::newInstance( AWSAccessKeyId, AWSSecretKey );
$transport->setDebug( true ); // Print the response from AWS to the error log for debugging.
//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance( $transport );
//Create the message
$message = Swift_Message::newInstance()
->setSubject( 'Testing Swiftmailer SES' )
->setFrom( array( FROM_ADDRESS ) )
->setTo( array( TO_ADDRESS ) )
->setBody( "<p>Dude, I'm <b>totally</b> sending you email via AWS.</p>", 'text/html' )
->addPart( "Dude, I'm _totally_ sending you email via AWS.", 'text/plain' );
echo "Sending\n";
try {
echo "Sent: " . $mailer->send( $message ) . "\n";
}
catch( AWSEmptyResponseException $e ) {
echo $e . "\n";
}

View file

@ -1,3 +0,0 @@
src_dir: src
coverage_clover: build/logs/clover.xml
json_path: build/logs/coveralls-upload.json

View file

@ -18,8 +18,7 @@
"ext-pcre": "*" "ext-pcre": "*"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "~4.8", "phpunit/phpunit": "~4.8"
"satooshi/php-coveralls": "~1.0"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

View file

@ -48,12 +48,12 @@ class Converter
$to = realpath($to) ?: $to; $to = realpath($to) ?: $to;
} }
$from = $this->normalize($from);
$to = $this->normalize($to);
$from = $this->dirname($from); $from = $this->dirname($from);
$to = $this->dirname($to); $to = $this->dirname($to);
$from = $this->normalize($from);
$to = $this->normalize($to);
$this->from = $from; $this->from = $from;
$this->to = $to; $this->to = $to;
} }

View file

@ -1,17 +1,13 @@
language: php language: php
php: sudo: false
- 5.3
- 5.4
- 5.5
- 5.6
- hhvm-nightly
before_script: before_script:
- cp tests/acceptance.conf.php.default tests/acceptance.conf.php - cp tests/acceptance.conf.php.default tests/acceptance.conf.php
- cp tests/smoke.conf.php.default tests/smoke.conf.php - cp tests/smoke.conf.php.default tests/smoke.conf.php
- composer self-update - composer self-update
- composer update --no-interaction --prefer-source - composer update --no-interaction --prefer-source
- gem install mime-types -v 2.99.1
- gem install mailcatcher - gem install mailcatcher
- mailcatcher --smtp-port 4456 - mailcatcher --smtp-port 4456
@ -19,7 +15,14 @@ script:
- phpunit --verbose - phpunit --verbose
matrix: matrix:
allow_failures: include:
- php: 5.6 - php: 5.3
- php: hhvm-nightly - php: 5.4
fast_finish: true - php: 5.5
- php: 5.6
- php: 7.0
- php: hhvm
allow_failures:
- php: 7.0
- php: hhvm
fast_finish: true

View file

@ -1,6 +1,21 @@
Changelog Changelog
========= =========
5.4.2 (2016-05-01)
------------------
* fixed support for IPv6 sockets
* added auto-retry when sending messages from the memory spool
* fixed consecutive read calls in Swift_ByteStream_FileByteStream
* added support for iso-8859-15 encoding
* fixed PHP mail extra params on missing reversePath
* added methods to set custom stream context options
* fixed charset changes in QpContentEncoderProxy
* added return-path header to the ignoredHeaders list of DKIMSigner
* fixed crlf for subject using mail
* fixed add soft line break only when necessary
* fixed escaping command-line args to Sendmail
5.4.1 (2015-06-06) 5.4.1 (2015-06-06)
------------------ ------------------

View file

@ -1,4 +1,4 @@
Copyright (c) 2013 Fabien Potencier Copyright (c) 2013-2016 Fabien Potencier
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View file

@ -6,7 +6,6 @@ It is released under the MIT license.
Homepage: http://swiftmailer.org Homepage: http://swiftmailer.org
Documentation: http://swiftmailer.org/docs Documentation: http://swiftmailer.org/docs
Mailing List: http://groups.google.com/group/swiftmailer
Bugs: https://github.com/swiftmailer/swiftmailer/issues Bugs: https://github.com/swiftmailer/swiftmailer/issues
Repository: https://github.com/swiftmailer/swiftmailer Repository: https://github.com/swiftmailer/swiftmailer

View file

@ -1 +1 @@
Swift-5.4.1 Swift-5.4.2

View file

@ -23,6 +23,11 @@
"autoload": { "autoload": {
"files": ["lib/swift_required.php"] "files": ["lib/swift_required.php"]
}, },
"autoload-dev": {
"psr-0": {
"Swift_": "tests/unit"
}
},
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "5.4-dev" "dev-master": "5.4-dev"

View file

@ -21,11 +21,11 @@ System Requirements
The basic requirements to operate Swift Mailer are extremely minimal and The basic requirements to operate Swift Mailer are extremely minimal and
easily achieved. Historically, Swift Mailer has supported both PHP 4 and PHP 5 easily achieved. Historically, Swift Mailer has supported both PHP 4 and PHP 5
by following a parallel development workflow. Now in it's fourth major by following a parallel development workflow. Now in it's fourth major
version, and Swift Mailer operates on servers running PHP 5.2 or higher. version, and Swift Mailer operates on servers running PHP 5.3.3 or higher.
The library aims to work with as many PHP 5 projects as possible: The library aims to work with as many PHP 5 projects as possible:
* PHP 5.2 or higher, with the SPL extension (standard) * PHP 5.3.3 or higher, with the SPL extension (standard)
* Limited network access to connect to remote SMTP servers * Limited network access to connect to remote SMTP servers

View file

@ -22,6 +22,8 @@ abstract class Swift_ByteStream_AbstractFilterableInputStream implements Swift_I
/** /**
* StreamFilters. * StreamFilters.
*
* @var Swift_StreamFilter[]
*/ */
private $_filters = array(); private $_filters = array();

View file

@ -82,9 +82,7 @@ class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_O
// Don't use array slice // Don't use array slice
$end = $length + $this->_offset; $end = $length + $this->_offset;
$end = $this->_arraySize < $end $end = $this->_arraySize < $end ? $this->_arraySize : $end;
? $this->_arraySize
: $end;
$ret = ''; $ret = '';
for (; $this->_offset < $end; ++$this->_offset) { for (; $this->_offset < $end; ++$this->_offset) {
$ret .= $this->_array[$this->_offset]; $ret .= $this->_array[$this->_offset];

View file

@ -139,11 +139,13 @@ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterabl
private function _getReadHandle() private function _getReadHandle()
{ {
if (!isset($this->_reader)) { if (!isset($this->_reader)) {
if (!$this->_reader = fopen($this->_path, 'rb')) { $pointer = @fopen($this->_path, 'rb');
if (!$pointer) {
throw new Swift_IoException( throw new Swift_IoException(
'Unable to open file for reading ['.$this->_path.']' 'Unable to open file for reading ['.$this->_path.']'
); );
} }
$this->_reader = $pointer;
if ($this->_offset != 0) { if ($this->_offset != 0) {
$this->_getReadStreamSeekableStatus(); $this->_getReadStreamSeekableStatus();
$this->_seekReadStreamToPosition($this->_offset); $this->_seekReadStreamToPosition($this->_offset);

View file

@ -82,7 +82,7 @@ class Swift_CharacterReader_GenericFixedWidthReader implements Swift_CharacterRe
{ {
$needed = $this->_width - $size; $needed = $this->_width - $size;
return ($needed > -1) ? $needed : -1; return $needed > -1 ? $needed : -1;
} }
/** /**

View file

@ -67,9 +67,9 @@ class Swift_CharacterReader_UsAsciiReader implements Swift_CharacterReader
$byte = reset($bytes); $byte = reset($bytes);
if (1 == count($bytes) && $byte >= 0x00 && $byte <= 0x7F) { if (1 == count($bytes) && $byte >= 0x00 && $byte <= 0x7F) {
return 0; return 0;
} else {
return -1;
} }
return -1;
} }
/** /**

View file

@ -161,10 +161,7 @@ class Swift_CharacterReader_Utf8Reader implements Swift_CharacterReader
} }
$needed = self::$length_map[$bytes[0]] - $size; $needed = self::$length_map[$bytes[0]] - $size;
return ($needed > -1) return $needed > -1 ? $needed : -1;
? $needed
: -1
;
} }
/** /**

View file

@ -165,9 +165,7 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream
return false; return false;
} }
$ret = false; $ret = false;
$length = ($this->_currentPos + $length > $this->_charCount) $length = $this->_currentPos + $length > $this->_charCount ? $this->_charCount - $this->_currentPos : $length;
? $this->_charCount - $this->_currentPos
: $length;
switch ($this->_mapType) { switch ($this->_mapType) {
case Swift_CharacterReader::MAP_TYPE_FIXED_LEN: case Swift_CharacterReader::MAP_TYPE_FIXED_LEN:
$len = $length * $this->_map; $len = $length * $this->_map;
@ -178,10 +176,6 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream
break; break;
case Swift_CharacterReader::MAP_TYPE_INVALID: case Swift_CharacterReader::MAP_TYPE_INVALID:
$end = $this->_currentPos + $length;
$end = $end > $this->_charCount
? $this->_charCount
: $end;
$ret = ''; $ret = '';
for (; $this->_currentPos < $length; ++$this->_currentPos) { for (; $this->_currentPos < $length; ++$this->_currentPos) {
if (isset($this->_map[$this->_currentPos])) { if (isset($this->_map[$this->_currentPos])) {
@ -194,9 +188,7 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream
case Swift_CharacterReader::MAP_TYPE_POSITIONS: case Swift_CharacterReader::MAP_TYPE_POSITIONS:
$end = $this->_currentPos + $length; $end = $this->_currentPos + $length;
$end = $end > $this->_charCount $end = $end > $this->_charCount ? $this->_charCount : $end;
? $this->_charCount
: $end;
$ret = ''; $ret = '';
$start = 0; $start = 0;
if ($this->_currentPos > 0) { if ($this->_currentPos > 0) {

View file

@ -311,9 +311,9 @@ class Swift_DependencyContainer
return $reflector->newInstanceArgs( return $reflector->newInstanceArgs(
$this->createDependenciesFor($itemName) $this->createDependenciesFor($itemName)
); );
} else {
return $reflector->newInstance();
} }
return $reflector->newInstance();
} }
/** Create and register a shared instance of $itemName */ /** Create and register a shared instance of $itemName */
@ -366,8 +366,8 @@ class Swift_DependencyContainer
} }
return $collection; return $collection;
} else {
return $this->lookup($item);
} }
return $this->lookup($item);
} }
} }

View file

@ -198,14 +198,25 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder
} }
$enc = $this->_encodeByteSequence($bytes, $size); $enc = $this->_encodeByteSequence($bytes, $size);
if ($currentLine && $lineLen + $size >= $thisLineLength) {
$i = strpos($enc, '=0D=0A');
$newLineLength = $lineLen + ($i === false ? $size : $i);
if ($currentLine && $newLineLength >= $thisLineLength) {
$lines[$lNo] = ''; $lines[$lNo] = '';
$currentLine = &$lines[$lNo++]; $currentLine = &$lines[$lNo++];
$thisLineLength = $maxLineLength; $thisLineLength = $maxLineLength;
$lineLen = 0; $lineLen = 0;
} }
$lineLen += $size;
$currentLine .= $enc; $currentLine .= $enc;
if ($i === false) {
$lineLen += $size;
} else {
// 6 is the length of '=0D=0A'.
$lineLen = $size - strrpos($enc, '=0D=0A') - 6;
}
} }
return $this->_standardize(implode("=\r\n", $lines)); return $this->_standardize(implode("=\r\n", $lines));

View file

@ -39,7 +39,7 @@ class Swift_FileSpool extends Swift_ConfigurableSpool
if (!file_exists($this->_path)) { if (!file_exists($this->_path)) {
if (!mkdir($this->_path, 0777, true)) { if (!mkdir($this->_path, 0777, true)) {
throw new Swift_IoException('Unable to create Path ['.$this->_path.']'); throw new Swift_IoException(sprintf('Unable to create path "%s".', $this->_path));
} }
} }
} }
@ -108,7 +108,7 @@ class Swift_FileSpool extends Swift_ConfigurableSpool
} }
} }
throw new Swift_IoException('Unable to create a file for enqueuing Message'); throw new Swift_IoException(sprintf('Unable to create a file for enqueuing Message in "%s".', $this->_path));
} }
/** /**

View file

@ -289,10 +289,7 @@ class Swift_KeyCache_DiskKeyCache implements Swift_KeyCache
private function _getHandle($nsKey, $itemKey, $position) private function _getHandle($nsKey, $itemKey, $position)
{ {
if (!isset($this->_keys[$nsKey][$itemKey])) { if (!isset($this->_keys[$nsKey][$itemKey])) {
$openMode = $this->hasKey($nsKey, $itemKey) $openMode = $this->hasKey($nsKey, $itemKey) ? 'r+b' : 'w+b';
? 'r+b'
: 'w+b'
;
$fp = fopen($this->_path.'/'.$nsKey.'/'.$itemKey, $openMode); $fp = fopen($this->_path.'/'.$nsKey.'/'.$itemKey, $openMode);
$this->_keys[$nsKey][$itemKey] = $fp; $this->_keys[$nsKey][$itemKey] = $fp;
} }

View file

@ -69,7 +69,7 @@ class Swift_Mailer
* @param Swift_Mime_Message $message * @param Swift_Mime_Message $message
* @param array $failedRecipients An array of failures by-reference * @param array $failedRecipients An array of failures by-reference
* *
* @return int * @return int The number of successful recipients. Can be 0 which indicates failure
*/ */
public function send(Swift_Mime_Message $message, &$failedRecipients = null) public function send(Swift_Mime_Message $message, &$failedRecipients = null)
{ {

View file

@ -16,6 +16,7 @@
class Swift_MemorySpool implements Swift_Spool class Swift_MemorySpool implements Swift_Spool
{ {
protected $messages = array(); protected $messages = array();
private $flushRetries = 3;
/** /**
* Tests if this Transport mechanism has started. * Tests if this Transport mechanism has started.
@ -41,6 +42,14 @@ class Swift_MemorySpool implements Swift_Spool
{ {
} }
/**
* @param int $retries
*/
public function setFlushRetries($retries)
{
$this->flushRetries = $retries;
}
/** /**
* Stores a message in the queue. * Stores a message in the queue.
* *
@ -75,8 +84,25 @@ class Swift_MemorySpool implements Swift_Spool
} }
$count = 0; $count = 0;
while ($message = array_pop($this->messages)) { $retries = $this->flushRetries;
$count += $transport->send($message, $failedRecipients); while ($retries--) {
try {
while ($message = array_pop($this->messages)) {
$count += $transport->send($message, $failedRecipients);
}
} catch (Swift_TransportException $exception) {
if ($retries) {
// re-queue the message at the end of the queue to give a chance
// to the other messages to be sent, in case the failure was due to
// this message and not just the transport failing
array_unshift($this->messages, $message);
// wait half a second before we try again
usleep(500000);
} else {
throw $exception;
}
}
} }
return $count; return $count;

View file

@ -69,9 +69,7 @@ class Swift_Mime_Attachment extends Swift_Mime_SimpleMimeEntity
public function setDisposition($disposition) public function setDisposition($disposition)
{ {
if (!$this->_setHeaderFieldModel('Content-Disposition', $disposition)) { if (!$this->_setHeaderFieldModel('Content-Disposition', $disposition)) {
$this->getHeaders()->addParameterizedHeader( $this->getHeaders()->addParameterizedHeader('Content-Disposition', $disposition);
'Content-Disposition', $disposition
);
} }
return $this; return $this;
@ -139,9 +137,7 @@ class Swift_Mime_Attachment extends Swift_Mime_SimpleMimeEntity
$this->setFilename(basename($file->getPath())); $this->setFilename(basename($file->getPath()));
$this->setBody($file, $contentType); $this->setBody($file, $contentType);
if (!isset($contentType)) { if (!isset($contentType)) {
$extension = strtolower(substr( $extension = strtolower(substr($file->getPath(), strrpos($file->getPath(), '.') + 1));
$file->getPath(), strrpos($file->getPath(), '.') + 1
));
if (array_key_exists($extension, $this->_mimeTypes)) { if (array_key_exists($extension, $this->_mimeTypes)) {
$this->setContentType($this->_mimeTypes[$extension]); $this->setContentType($this->_mimeTypes[$extension]);

View file

@ -95,15 +95,26 @@ class Swift_Mime_ContentEncoder_QpContentEncoder extends Swift_Encoder_QpEncoder
} }
$enc = $this->_encodeByteSequence($bytes, $size); $enc = $this->_encodeByteSequence($bytes, $size);
if ($currentLine && $lineLen + $size >= $thisLineLength) {
$i = strpos($enc, '=0D=0A');
$newLineLength = $lineLen + ($i === false ? $size : $i);
if ($currentLine && $newLineLength >= $thisLineLength) {
$is->write($prepend.$this->_standardize($currentLine)); $is->write($prepend.$this->_standardize($currentLine));
$currentLine = ''; $currentLine = '';
$prepend = "=\r\n"; $prepend = "=\r\n";
$thisLineLength = $maxLineLength; $thisLineLength = $maxLineLength;
$lineLen = 0; $lineLen = 0;
} }
$lineLen += $size;
$currentLine .= $enc; $currentLine .= $enc;
if ($i === false) {
$lineLen += $size;
} else {
// 6 is the length of '=0D=0A'.
$lineLen = $size - strrpos($enc, '=0D=0A') - 6;
}
} }
if (strlen($currentLine)) { if (strlen($currentLine)) {
$is->write($prepend.$this->_standardize($currentLine)); $is->write($prepend.$this->_standardize($currentLine));

View file

@ -61,6 +61,7 @@ class Swift_Mime_ContentEncoder_QpContentEncoderProxy implements Swift_Mime_Cont
public function charsetChanged($charset) public function charsetChanged($charset)
{ {
$this->charset = $charset; $this->charset = $charset;
$this->safeEncoder->charsetChanged($charset);
} }
/** /**

View file

@ -129,11 +129,11 @@ class Swift_Mime_Grammar
{ {
if (array_key_exists($name, self::$_grammar)) { if (array_key_exists($name, self::$_grammar)) {
return self::$_grammar[$name]; return self::$_grammar[$name];
} else {
throw new Swift_RfcComplianceException(
"No such grammar '".$name."' defined."
);
} }
throw new Swift_RfcComplianceException(
"No such grammar '".$name."' defined."
);
} }
/** /**

View file

@ -98,9 +98,7 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct
{ {
$params = $this->getParameters(); $params = $this->getParameters();
return array_key_exists($parameter, $params) return array_key_exists($parameter, $params) ? $params[$parameter] : null;
? $params[$parameter]
: null;
} }
/** /**

View file

@ -128,9 +128,7 @@ class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity
*/ */
public function getDelSp() public function getDelSp()
{ {
return ($this->_getHeaderParameter('Content-Type', 'delsp') == 'yes') return 'yes' == $this->_getHeaderParameter('Content-Type', 'delsp') ? true : false;
? true
: false;
} }
/** /**
@ -196,7 +194,7 @@ class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity
protected function _convertString($string) protected function _convertString($string)
{ {
$charset = strtolower($this->getCharset()); $charset = strtolower($this->getCharset());
if (!in_array($charset, array('utf-8', 'iso-8859-1', ''))) { if (!in_array($charset, array('utf-8', 'iso-8859-1', 'iso-8859-15', ''))) {
// mb_convert_encoding must be the first one to check, since iconv cannot convert some words. // mb_convert_encoding must be the first one to check, since iconv cannot convert some words.
if (function_exists('mb_convert_encoding')) { if (function_exists('mb_convert_encoding')) {
$string = mb_convert_encoding($string, $charset, 'utf-8'); $string = mb_convert_encoding($string, $charset, 'utf-8');

View file

@ -112,12 +112,7 @@ class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_HeaderFactory
public function createParameterizedHeader($name, $value = null, public function createParameterizedHeader($name, $value = null,
$params = array()) $params = array())
{ {
$header = new Swift_Mime_Headers_ParameterizedHeader($name, $header = new Swift_Mime_Headers_ParameterizedHeader($name, $this->_encoder, strtolower($name) == 'content-disposition' ? $this->_paramEncoder : null, $this->_grammar);
$this->_encoder, (strtolower($name) == 'content-disposition')
? $this->_paramEncoder
: null,
$this->_grammar
);
if (isset($value)) { if (isset($value)) {
$header->setFieldBodyModel($value); $header->setFieldBodyModel($value);
} }

View file

@ -349,12 +349,13 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
{ {
$lowerA = strtolower($a); $lowerA = strtolower($a);
$lowerB = strtolower($b); $lowerB = strtolower($b);
$aPos = array_key_exists($lowerA, $this->_order) $aPos = array_key_exists($lowerA, $this->_order) ? $this->_order[$lowerA] : -1;
? $this->_order[$lowerA] $bPos = array_key_exists($lowerB, $this->_order) ? $this->_order[$lowerB] : -1;
: -1;
$bPos = array_key_exists($lowerB, $this->_order) if (-1 === $aPos && -1 === $bPos) {
? $this->_order[$lowerB] // just be sure to be determinist here
: -1; return $a > $b ? -1 : 1;
}
if ($aPos == -1) { if ($aPos == -1) {
return 1; return 1;
@ -362,7 +363,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
return -1; return -1;
} }
return ($aPos < $bPos) ? -1 : 1; return $aPos < $bPos ? -1 : 1;
} }
/** Test if the given Header is always displayed */ /** Test if the given Header is always displayed */

View file

@ -253,7 +253,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
* If $name is passed and the first parameter is a string, this name will be * If $name is passed and the first parameter is a string, this name will be
* associated with the address. * associated with the address.
* *
* @param string $addresses * @param mixed $addresses
* @param string $name optional * @param string $name optional
* *
* @return Swift_Mime_SimpleMessage * @return Swift_Mime_SimpleMessage

View file

@ -282,11 +282,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
{ {
// TODO: Try to refactor this logic // TODO: Try to refactor this logic
$compoundLevel = isset($compoundLevel) $compoundLevel = isset($compoundLevel) ? $compoundLevel : $this->_getCompoundLevel($children);
? $compoundLevel
: $this->_getCompoundLevel($children)
;
$immediateChildren = array(); $immediateChildren = array();
$grandchildren = array(); $grandchildren = array();
$newContentType = $this->_userContentType; $newContentType = $this->_userContentType;
@ -311,15 +307,15 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
} }
} }
if (!empty($immediateChildren)) { if ($immediateChildren) {
$lowestLevel = $this->_getNeededChildLevel($immediateChildren[0], $compoundLevel); $lowestLevel = $this->_getNeededChildLevel($immediateChildren[0], $compoundLevel);
// Determine which composite media type is needed to accommodate the // Determine which composite media type is needed to accommodate the
// immediate children // immediate children
foreach ($this->_compositeRanges as $mediaType => $range) { foreach ($this->_compositeRanges as $mediaType => $range) {
if ($lowestLevel > $range[0] if ($lowestLevel > $range[0] && $lowestLevel <= $range[1]) {
&& $lowestLevel <= $range[1]) {
$newContentType = $mediaType; $newContentType = $mediaType;
break; break;
} }
} }
@ -349,9 +345,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
*/ */
public function getBody() public function getBody()
{ {
return ($this->_body instanceof Swift_OutputByteStream) return $this->_body instanceof Swift_OutputByteStream ? $this->_readStream($this->_body) : $this->_body;
? $this->_readStream($this->_body)
: $this->_body;
} }
/** /**
@ -486,12 +480,8 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
if ($this->_cache->hasKey($this->_cacheKey, 'body')) { if ($this->_cache->hasKey($this->_cacheKey, 'body')) {
$body = $this->_cache->getString($this->_cacheKey, 'body'); $body = $this->_cache->getString($this->_cacheKey, 'body');
} else { } else {
$body = "\r\n".$this->_encoder->encodeString($this->getBody(), 0, $body = "\r\n".$this->_encoder->encodeString($this->getBody(), 0, $this->getMaxLineLength());
$this->getMaxLineLength() $this->_cache->setString($this->_cacheKey, 'body', $body, Swift_KeyCache::MODE_WRITE);
);
$this->_cache->setString($this->_cacheKey, 'body', $body,
Swift_KeyCache::MODE_WRITE
);
} }
$string .= $body; $string .= $body;
} }
@ -602,9 +592,9 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
$this->_headers->get($field)->setFieldBodyModel($model); $this->_headers->get($field)->setFieldBodyModel($model);
return true; return true;
} else {
return false;
} }
return false;
} }
/** /**
@ -626,9 +616,9 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
$this->_headers->get($field)->setParameter($parameter, $value); $this->_headers->get($field)->setParameter($parameter, $value);
return true; return true;
} else {
return false;
} }
return false;
} }
/** /**
@ -716,9 +706,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
private function _assertValidBoundary($boundary) private function _assertValidBoundary($boundary)
{ {
if (!preg_match( if (!preg_match('/^[a-z0-9\'\(\)\+_\-,\.\/:=\?\ ]{0,69}[a-z0-9\'\(\)\+_\-,\.\/:=\?]$/Di', $boundary)) {
'/^[a-z0-9\'\(\)\+_\-,\.\/:=\?\ ]{0,69}[a-z0-9\'\(\)\+_\-,\.\/:=\?]$/Di',
$boundary)) {
throw new Swift_RfcComplianceException('Mime boundary set is not RFC 2046 compliant.'); throw new Swift_RfcComplianceException('Mime boundary set is not RFC 2046 compliant.');
} }
} }
@ -757,18 +745,16 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
$realLevel = $child->getNestingLevel(); $realLevel = $child->getNestingLevel();
$lowercaseType = strtolower($child->getContentType()); $lowercaseType = strtolower($child->getContentType());
if (isset($filter[$realLevel]) if (isset($filter[$realLevel]) && isset($filter[$realLevel][$lowercaseType])) {
&& isset($filter[$realLevel][$lowercaseType])) {
return $filter[$realLevel][$lowercaseType]; return $filter[$realLevel][$lowercaseType];
} else {
return $realLevel;
} }
return $realLevel;
} }
private function _createChild() private function _createChild()
{ {
return new self($this->_headers->newInstance(), return new self($this->_headers->newInstance(), $this->_encoder, $this->_cache, $this->_grammar);
$this->_encoder, $this->_cache, $this->_grammar);
} }
private function _notifyEncoderChanged(Swift_Mime_ContentEncoder $encoder) private function _notifyEncoderChanged(Swift_Mime_ContentEncoder $encoder)
@ -807,17 +793,13 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
private function _childSortAlgorithm($a, $b) private function _childSortAlgorithm($a, $b)
{ {
$typePrefs = array(); $typePrefs = array();
$types = array( $types = array(strtolower($a->getContentType()), strtolower($b->getContentType()));
strtolower($a->getContentType()),
strtolower($b->getContentType()),
);
foreach ($types as $type) { foreach ($types as $type) {
$typePrefs[] = (array_key_exists($type, $this->_alternativePartOrder)) $typePrefs[] = array_key_exists($type, $this->_alternativePartOrder) ? $this->_alternativePartOrder[$type] : max($this->_alternativePartOrder) + 1;
? $this->_alternativePartOrder[$type]
: (max($this->_alternativePartOrder) + 1);
} }
return ($typePrefs[0] >= $typePrefs[1]) ? 1 : -1; return $typePrefs[0] >= $typePrefs[1] ? 1 : -1;
} }
// -- Destructor // -- Destructor
@ -839,14 +821,8 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
*/ */
private function _assertValidId($id) private function _assertValidId($id)
{ {
if (!preg_match( if (!preg_match('/^'.$this->_grammar->getDefinition('id-left').'@'.$this->_grammar->getDefinition('id-right').'$/D', $id)) {
'/^'.$this->_grammar->getDefinition('id-left').'@'. throw new Swift_RfcComplianceException('Invalid ID given <'.$id.'>');
$this->_grammar->getDefinition('id-right').'$/D',
$id
)) {
throw new Swift_RfcComplianceException(
'Invalid ID given <'.$id.'>'
);
} }
} }
@ -857,7 +833,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
{ {
$this->_headers = clone $this->_headers; $this->_headers = clone $this->_headers;
$this->_encoder = clone $this->_encoder; $this->_encoder = clone $this->_encoder;
$this->_cacheKey = uniqid(); $this->_cacheKey = md5(uniqid(getmypid().mt_rand(), true));
$children = array(); $children = array();
foreach ($this->_children as $pos => $child) { foreach ($this->_children as $pos => $child) {
$children[$pos] = clone $child; $children[$pos] = clone $child;

View file

@ -157,12 +157,9 @@ class Swift_Plugins_DecoratorPlugin implements Swift_Events_SendListener, Swift_
{ {
if ($this->_replacements instanceof Swift_Plugins_Decorator_Replacements) { if ($this->_replacements instanceof Swift_Plugins_Decorator_Replacements) {
return $this->_replacements->getReplacementsFor($address); return $this->_replacements->getReplacementsFor($address);
} else {
return isset($this->_replacements[$address])
? $this->_replacements[$address]
: null
;
} }
return isset($this->_replacements[$address]) ? $this->_replacements[$address] : null;
} }
/** /**

View file

@ -49,25 +49,13 @@ class Swift_Plugins_ReporterPlugin implements Swift_Events_SendListener
$message = $evt->getMessage(); $message = $evt->getMessage();
$failures = array_flip($evt->getFailedRecipients()); $failures = array_flip($evt->getFailedRecipients());
foreach ((array) $message->getTo() as $address => $null) { foreach ((array) $message->getTo() as $address => $null) {
$this->_reporter->notify( $this->_reporter->notify($message, $address, array_key_exists($address, $failures) ? Swift_Plugins_Reporter::RESULT_FAIL : Swift_Plugins_Reporter::RESULT_PASS);
$message, $address, (array_key_exists($address, $failures)
? Swift_Plugins_Reporter::RESULT_FAIL
: Swift_Plugins_Reporter::RESULT_PASS)
);
} }
foreach ((array) $message->getCc() as $address => $null) { foreach ((array) $message->getCc() as $address => $null) {
$this->_reporter->notify( $this->_reporter->notify($message, $address, array_key_exists($address, $failures) ? Swift_Plugins_Reporter::RESULT_FAIL : Swift_Plugins_Reporter::RESULT_PASS);
$message, $address, (array_key_exists($address, $failures)
? Swift_Plugins_Reporter::RESULT_FAIL
: Swift_Plugins_Reporter::RESULT_PASS)
);
} }
foreach ((array) $message->getBcc() as $address => $null) { foreach ((array) $message->getBcc() as $address => $null) {
$this->_reporter->notify( $this->_reporter->notify($message, $address, array_key_exists($address, $failures) ? Swift_Plugins_Reporter::RESULT_FAIL : Swift_Plugins_Reporter::RESULT_PASS);
$message, $address, (array_key_exists($address, $failures)
? Swift_Plugins_Reporter::RESULT_FAIL
: Swift_Plugins_Reporter::RESULT_PASS)
);
} }
} }
} }

View file

@ -151,9 +151,9 @@ class Swift_Plugins_ThrottlerPlugin extends Swift_Plugins_BandwidthMonitorPlugin
{ {
if (isset($this->_timer)) { if (isset($this->_timer)) {
return $this->_timer->getTimestamp(); return $this->_timer->getTimestamp();
} else {
return time();
} }
return time();
} }
/** /**

View file

@ -62,12 +62,12 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner
* *
* @var array * @var array
*/ */
protected $_ignoredHeaders = array(); protected $_ignoredHeaders = array('return-path' => true);
/** /**
* Signer identity. * Signer identity.
* *
* @var unknown_type * @var string
*/ */
protected $_signerIdentity; protected $_signerIdentity;
@ -143,13 +143,6 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner
*/ */
protected $_dkimHeader; protected $_dkimHeader;
/**
* Hash Handler.
*
* @var hash_ressource
*/
private $_headerHashHandler;
private $_bodyHashHandler; private $_bodyHashHandler;
private $_headerHash; private $_headerHash;
@ -206,7 +199,6 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner
{ {
$this->_headerHash = null; $this->_headerHash = null;
$this->_signedHeaders = array(); $this->_signedHeaders = array();
$this->_headerHashHandler = null;
$this->_bodyHash = null; $this->_bodyHash = null;
$this->_bodyHashHandler = null; $this->_bodyHashHandler = null;
$this->_bodyCanonIgnoreStart = 2; $this->_bodyCanonIgnoreStart = 2;
@ -381,7 +373,7 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner
$this->_showLen = true; $this->_showLen = true;
$this->_maxLen = PHP_INT_MAX; $this->_maxLen = PHP_INT_MAX;
} elseif ($len === false) { } elseif ($len === false) {
$this->showLen = false; $this->_showLen = false;
$this->_maxLen = PHP_INT_MAX; $this->_maxLen = PHP_INT_MAX;
} else { } else {
$this->_showLen = true; $this->_showLen = true;
@ -394,7 +386,7 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner
/** /**
* Set the signature timestamp. * Set the signature timestamp.
* *
* @param timestamp $time * @param int $time A timestamp
* *
* @return Swift_Signers_DKIMSigner * @return Swift_Signers_DKIMSigner
*/ */
@ -408,7 +400,7 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner
/** /**
* Set the signature expiration timestamp. * Set the signature expiration timestamp.
* *
* @param timestamp $time * @param int $time A timestamp
* *
* @return Swift_Signers_DKIMSigner * @return Swift_Signers_DKIMSigner
*/ */
@ -588,9 +580,13 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner
$this->_addToHeaderHash($header); $this->_addToHeaderHash($header);
} }
/**
* @deprecated This method is currently useless in this class but it must be
* kept for BC reasons due to its "protected" scope. This method
* might be overriden by custom client code.
*/
protected function _endOfHeaders() protected function _endOfHeaders()
{ {
//$this->_headerHash=hash_final($this->_headerHashHandler, true);
} }
protected function _canonicalizeBody($string) protected function _canonicalizeBody($string)

View file

@ -141,7 +141,7 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner
/** /**
* Resets internal states. * Resets internal states.
* *
* @return Swift_Signers_DomainKeysSigner * @return Swift_Signers_DomainKeySigner
*/ */
public function reset() public function reset()
{ {
@ -170,7 +170,7 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner
* @throws Swift_IoException * @throws Swift_IoException
* *
* @return int * @return int
* @return Swift_Signers_DomainKeysSigner * @return Swift_Signers_DomainKeySigner
*/ */
public function write($bytes) public function write($bytes)
{ {
@ -188,7 +188,7 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner
* *
* @throws Swift_IoException * @throws Swift_IoException
* *
* @return Swift_Signers_DomainKeysSigner * @return Swift_Signers_DomainKeySigner
*/ */
public function commit() public function commit()
{ {
@ -203,7 +203,7 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner
* *
* @param Swift_InputByteStream $is * @param Swift_InputByteStream $is
* *
* @return Swift_Signers_DomainKeysSigner * @return Swift_Signers_DomainKeySigner
*/ */
public function bind(Swift_InputByteStream $is) public function bind(Swift_InputByteStream $is)
{ {
@ -221,7 +221,7 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner
* *
* @param Swift_InputByteStream $is * @param Swift_InputByteStream $is
* *
* @return Swift_Signers_DomainKeysSigner * @return Swift_Signers_DomainKeySigner
*/ */
public function unbind(Swift_InputByteStream $is) public function unbind(Swift_InputByteStream $is)
{ {
@ -243,7 +243,7 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner
* *
* @throws Swift_IoException * @throws Swift_IoException
* *
* @return Swift_Signers_DomainKeysSigner * @return Swift_Signers_DomainKeySigner
*/ */
public function flushBuffers() public function flushBuffers()
{ {
@ -257,7 +257,7 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner
* *
* @param string $hash * @param string $hash
* *
* @return Swift_Signers_DomainKeysSigner * @return Swift_Signers_DomainKeySigner
*/ */
public function setHashAlgorithm($hash) public function setHashAlgorithm($hash)
{ {
@ -271,7 +271,7 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner
* *
* @param string $canon simple | nofws defaults to simple * @param string $canon simple | nofws defaults to simple
* *
* @return Swift_Signers_DomainKeysSigner * @return Swift_Signers_DomainKeySigner
*/ */
public function setCanon($canon) public function setCanon($canon)
{ {
@ -336,9 +336,9 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner
{ {
if ($this->_debugHeaders) { if ($this->_debugHeaders) {
return array('DomainKey-Signature', 'X-DebugHash'); return array('DomainKey-Signature', 'X-DebugHash');
} else {
return array('DomainKey-Signature');
} }
return array('DomainKey-Signature');
} }
/** /**
@ -502,7 +502,7 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner
$this->_hashHandler = hash_init('sha1'); $this->_hashHandler = hash_init('sha1');
break; break;
} }
$this->_canonLine = ''; $this->_bodyCanonLine = '';
} }
/** /**

View file

@ -29,11 +29,12 @@ class Swift_Signers_OpenDKIMSigner extends Swift_Signers_DKIMSigner
public function __construct($privateKey, $domainName, $selector) public function __construct($privateKey, $domainName, $selector)
{ {
if (extension_loaded('opendkim')) { if (!extension_loaded('opendkim')) {
$this->_peclLoaded = true;
} else {
throw new Swift_SwiftException('php-opendkim extension not found'); throw new Swift_SwiftException('php-opendkim extension not found');
} }
$this->_peclLoaded = true;
parent::__construct($privateKey, $domainName, $selector); parent::__construct($privateKey, $domainName, $selector);
} }
@ -61,9 +62,9 @@ class Swift_Signers_OpenDKIMSigner extends Swift_Signers_DKIMSigner
if (is_bool($bodyLen)) { if (is_bool($bodyLen)) {
$bodyLen = -1; $bodyLen = -1;
} }
$hash = ($this->_hashAlgorithm == 'rsa-sha1') ? OpenDKIMSign::ALG_RSASHA1 : OpenDKIMSign::ALG_RSASHA256; $hash = $this->_hashAlgorithm == 'rsa-sha1' ? OpenDKIMSign::ALG_RSASHA1 : OpenDKIMSign::ALG_RSASHA256;
$bodyCanon = ($this->_bodyCanon == 'simple') ? OpenDKIMSign::CANON_SIMPLE : OpenDKIMSign::CANON_RELAXED; $bodyCanon = $this->_bodyCanon == 'simple' ? OpenDKIMSign::CANON_SIMPLE : OpenDKIMSign::CANON_RELAXED;
$headerCanon = ($this->_headerCanon == 'simple') ? OpenDKIMSign::CANON_SIMPLE : OpenDKIMSign::CANON_RELAXED; $headerCanon = $this->_headerCanon == 'simple' ? OpenDKIMSign::CANON_SIMPLE : OpenDKIMSign::CANON_RELAXED;
$this->_dkimHandler = new OpenDKIMSign($this->_privateKey, $this->_selector, $this->_domainName, $headerCanon, $bodyCanon, $hash, $bodyLen); $this->_dkimHandler = new OpenDKIMSign($this->_privateKey, $this->_selector, $this->_domainName, $headerCanon, $bodyCanon, $hash, $bodyLen);
// Hardcode signature Margin for now // Hardcode signature Margin for now
$this->_dkimHandler->setMargin(78); $this->_dkimHandler->setMargin(78);
@ -130,7 +131,7 @@ class Swift_Signers_OpenDKIMSigner extends Swift_Signers_DKIMSigner
/** /**
* Set the signature timestamp. * Set the signature timestamp.
* *
* @param timestamp $time * @param int $time
* *
* @return Swift_Signers_DKIMSigner * @return Swift_Signers_DKIMSigner
*/ */
@ -144,7 +145,7 @@ class Swift_Signers_OpenDKIMSigner extends Swift_Signers_DKIMSigner
/** /**
* Set the signature expiration timestamp. * Set the signature expiration timestamp.
* *
* @param timestamp $time * @param int $time
* *
* @return Swift_Signers_DKIMSigner * @return Swift_Signers_DKIMSigner
*/ */

View file

@ -41,9 +41,9 @@ class Swift_Signers_SMimeSigner implements Swift_Signers_BodySigner
/** /**
* Constructor. * Constructor.
* *
* @param string $certificate * @param string|null $signCertificate
* @param string $privateKey * @param string|null $signPrivateKey
* @param string $encryptCertificate * @param string|null $encryptCertificate
*/ */
public function __construct($signCertificate = null, $signPrivateKey = null, $encryptCertificate = null) public function __construct($signCertificate = null, $signPrivateKey = null, $encryptCertificate = null)
{ {
@ -167,7 +167,7 @@ class Swift_Signers_SMimeSigner implements Swift_Signers_BodySigner
* But some older mail clients, namely Microsoft Outlook 2000 will work when the message first encrypted. * But some older mail clients, namely Microsoft Outlook 2000 will work when the message first encrypted.
* As this goes against the official specs, its recommended to only use 'encryption -> signing' when specifically targeting these 'broken' clients. * As this goes against the official specs, its recommended to only use 'encryption -> signing' when specifically targeting these 'broken' clients.
* *
* @param string $signThenEncrypt * @param bool $signThenEncrypt
* *
* @return Swift_Signers_SMimeSigner * @return Swift_Signers_SMimeSigner
*/ */
@ -400,7 +400,6 @@ class Swift_Signers_SMimeSigner implements Swift_Signers_BodySigner
} }
$boundary = trim($contentTypeData['1'], '"'); $boundary = trim($contentTypeData['1'], '"');
$boundaryLen = strlen($boundary);
// Skip the header and CRLF CRLF // Skip the header and CRLF CRLF
$fromStream->setReadPointer($headersPosEnd + 4); $fromStream->setReadPointer($headersPosEnd + 4);

View file

@ -417,7 +417,7 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport
foreach ($recipients as $forwardPath) { foreach ($recipients as $forwardPath) {
try { try {
$this->_doRcptToCommand($forwardPath); $this->_doRcptToCommand($forwardPath);
$sent++; ++$sent;
} catch (Swift_TransportException $e) { } catch (Swift_TransportException $e) {
$failedRecipients[] = $forwardPath; $failedRecipients[] = $forwardPath;
} }
@ -461,11 +461,17 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport
/** Try to determine the hostname of the server this is run on */ /** Try to determine the hostname of the server this is run on */
private function _lookupHostname() private function _lookupHostname()
{ {
if (!empty($_SERVER['SERVER_NAME']) if (!empty($_SERVER['SERVER_NAME']) && $this->_isFqdn($_SERVER['SERVER_NAME'])) {
&& $this->_isFqdn($_SERVER['SERVER_NAME'])) {
$this->_domain = $_SERVER['SERVER_NAME']; $this->_domain = $_SERVER['SERVER_NAME'];
} elseif (!empty($_SERVER['SERVER_ADDR'])) { } elseif (!empty($_SERVER['SERVER_ADDR'])) {
$this->_domain = sprintf('[%s]', $_SERVER['SERVER_ADDR']); // Set the address literal tag (See RFC 5321, section: 4.1.3)
if (false === strpos($_SERVER['SERVER_ADDR'], ':')) {
$prefix = ''; // IPv4 addresses are not tagged.
} else {
$prefix = 'IPv6:'; // Adding prefix in case of IPv6.
}
$this->_domain = sprintf('[%s%s]', $prefix, $_SERVER['SERVER_ADDR']);
} }
} }
@ -475,9 +481,9 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport
// We could do a really thorough check, but there's really no point // We could do a really thorough check, but there's really no point
if (false !== $dotPos = strpos($hostname, '.')) { if (false !== $dotPos = strpos($hostname, '.')) {
return ($dotPos > 0) && ($dotPos != strlen($hostname) - 1); return ($dotPos > 0) && ($dotPos != strlen($hostname) - 1);
} else {
return false;
} }
return false;
} }
/** /**

View file

@ -373,7 +373,7 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es
$binary = $this->si2bin($time, 64); // create 64 bit binary string $binary = $this->si2bin($time, 64); // create 64 bit binary string
$timestamp = ''; $timestamp = '';
for ($i = 0; $i < 8; $i++) { for ($i = 0; $i < 8; ++$i) {
$timestamp .= chr(bindec(substr($binary, -(($i + 1) * 8), 8))); $timestamp .= chr(bindec(substr($binary, -(($i + 1) * 8), 8)));
} }
@ -437,7 +437,7 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es
{ {
$material = array(bin2hex($key[0])); $material = array(bin2hex($key[0]));
$len = strlen($key); $len = strlen($key);
for ($i = 1; $i < $len; $i++) { for ($i = 1; $i < $len; ++$i) {
list($high, $low) = str_split(bin2hex($key[$i])); list($high, $low) = str_split(bin2hex($key[$i]));
$v = $this->castToByte(ord($key[$i - 1]) << (7 + 1 - $i) | $this->uRShift(hexdec(dechex(hexdec($high) & 0xf).dechex(hexdec($low) & 0xf)), $i)); $v = $this->castToByte(ord($key[$i - 1]) << (7 + 1 - $i) | $this->uRShift(hexdec(dechex(hexdec($high) & 0xf).dechex(hexdec($low) & 0xf)), $i));
$material[] = str_pad(substr(dechex($v), -2), 2, '0', STR_PAD_LEFT); // cast to byte $material[] = str_pad(substr(dechex($v), -2), 2, '0', STR_PAD_LEFT); // cast to byte

View file

@ -172,7 +172,7 @@ class Swift_Transport_Esmtp_AuthHandler implements Swift_Transport_EsmtpHandler
foreach ($this->_getAuthenticatorsForAgent() as $authenticator) { foreach ($this->_getAuthenticatorsForAgent() as $authenticator) {
if (in_array(strtolower($authenticator->getAuthKeyword()), if (in_array(strtolower($authenticator->getAuthKeyword()),
array_map('strtolower', $this->_esmtpParams))) { array_map('strtolower', $this->_esmtpParams))) {
$count++; ++$count;
if ($authenticator->authenticate($agent, $this->_username, $this->_password)) { if ($authenticator->authenticate($agent, $this->_username, $this->_password)) {
return; return;
} }

View file

@ -42,6 +42,7 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo
'blocking' => 1, 'blocking' => 1,
'tls' => false, 'tls' => false,
'type' => Swift_Transport_IoBuffer::TYPE_SOCKET, 'type' => Swift_Transport_IoBuffer::TYPE_SOCKET,
'stream_context_options' => array(),
); );
/** /**
@ -139,6 +140,7 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo
*/ */
public function setEncryption($encryption) public function setEncryption($encryption)
{ {
$encryption = strtolower($encryption);
if ('tls' == $encryption) { if ('tls' == $encryption) {
$this->_params['protocol'] = 'tcp'; $this->_params['protocol'] = 'tcp';
$this->_params['tls'] = true; $this->_params['tls'] = true;
@ -160,6 +162,30 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo
return $this->_params['tls'] ? 'tls' : $this->_params['protocol']; return $this->_params['tls'] ? 'tls' : $this->_params['protocol'];
} }
/**
* Sets the stream context options.
*
* @param array $options
*
* @return Swift_Transport_EsmtpTransport
*/
public function setStreamOptions($options)
{
$this->_params['stream_context_options'] = $options;
return $this;
}
/**
* Returns the stream context options.
*
* @return array
*/
public function getStreamOptions()
{
return $this->_params['stream_context_options'];
}
/** /**
* Sets the source IP. * Sets the source IP.
* *
@ -197,7 +223,8 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo
foreach ($handlers as $handler) { foreach ($handlers as $handler) {
$assoc[$handler->getHandledKeyword()] = $handler; $assoc[$handler->getHandledKeyword()] = $handler;
} }
uasort($assoc, array($this, '_sortHandlers'));
@uasort($assoc, array($this, '_sortHandlers'));
$this->_handlers = $assoc; $this->_handlers = $assoc;
$this->_setHandlerParams(); $this->_setHandlerParams();

View file

@ -22,9 +22,7 @@ class Swift_Transport_FailoverTransport extends Swift_Transport_LoadBalancedTran
*/ */
private $_currentTransport; private $_currentTransport;
/** // needed as __construct is called from elsewhere explicitly
* Creates a new FailoverTransport.
*/
public function __construct() public function __construct()
{ {
parent::__construct(); parent::__construct();
@ -45,6 +43,7 @@ class Swift_Transport_FailoverTransport extends Swift_Transport_LoadBalancedTran
{ {
$maxTransports = count($this->_transports); $maxTransports = count($this->_transports);
$sent = 0; $sent = 0;
$this->_lastUsedTransport = null;
for ($i = 0; $i < $maxTransports for ($i = 0; $i < $maxTransports
&& $transport = $this->_getNextTransport(); ++$i) { && $transport = $this->_getNextTransport(); ++$i) {
@ -53,7 +52,11 @@ class Swift_Transport_FailoverTransport extends Swift_Transport_LoadBalancedTran
$transport->start(); $transport->start();
} }
return $transport->send($message, $failedRecipients); if ($sent = $transport->send($message, $failedRecipients)) {
$this->_lastUsedTransport = $transport;
return $sent;
}
} catch (Swift_TransportException $e) { } catch (Swift_TransportException $e) {
$this->_killCurrentTransport(); $this->_killCurrentTransport();
} }

View file

@ -30,8 +30,13 @@ class Swift_Transport_LoadBalancedTransport implements Swift_Transport
protected $_transports = array(); protected $_transports = array();
/** /**
* Creates a new LoadBalancedTransport. * The Transport used in the last successful send operation.
*
* @var Swift_Transport
*/ */
protected $_lastUsedTransport = null;
// needed as __construct is called from elsewhere explicitly
public function __construct() public function __construct()
{ {
} }
@ -57,6 +62,16 @@ class Swift_Transport_LoadBalancedTransport implements Swift_Transport
return array_merge($this->_transports, $this->_deadTransports); return array_merge($this->_transports, $this->_deadTransports);
} }
/**
* Get the Transport used in the last successful send operation.
*
* @return Swift_Transport
*/
public function getLastUsedTransport()
{
return $this->_lastUsedTransport;
}
/** /**
* Test if this Transport mechanism has started. * Test if this Transport mechanism has started.
* *
@ -100,6 +115,7 @@ class Swift_Transport_LoadBalancedTransport implements Swift_Transport
{ {
$maxTransports = count($this->_transports); $maxTransports = count($this->_transports);
$sent = 0; $sent = 0;
$this->_lastUsedTransport = null;
for ($i = 0; $i < $maxTransports for ($i = 0; $i < $maxTransports
&& $transport = $this->_getNextTransport(); ++$i) { && $transport = $this->_getNextTransport(); ++$i) {
@ -108,6 +124,7 @@ class Swift_Transport_LoadBalancedTransport implements Swift_Transport
$transport->start(); $transport->start();
} }
if ($sent = $transport->send($message, $failedRecipients)) { if ($sent = $transport->send($message, $failedRecipients)) {
$this->_lastUsedTransport = $transport;
break; break;
} }
} catch (Swift_TransportException $e) { } catch (Swift_TransportException $e) {

View file

@ -156,15 +156,16 @@ class Swift_Transport_MailTransport implements Swift_Transport
if ("\r\n" != PHP_EOL) { if ("\r\n" != PHP_EOL) {
// Non-windows (not using SMTP) // Non-windows (not using SMTP)
$headers = str_replace("\r\n", PHP_EOL, $headers); $headers = str_replace("\r\n", PHP_EOL, $headers);
$subject = str_replace("\r\n", PHP_EOL, $subject);
$body = str_replace("\r\n", PHP_EOL, $body); $body = str_replace("\r\n", PHP_EOL, $body);
} else { } else {
// Windows, using SMTP // Windows, using SMTP
$headers = str_replace("\r\n.", "\r\n..", $headers); $headers = str_replace("\r\n.", "\r\n..", $headers);
$subject = str_replace("\r\n.", "\r\n..", $subject);
$body = str_replace("\r\n.", "\r\n..", $body); $body = str_replace("\r\n.", "\r\n..", $body);
} }
if ($this->_invoker->mail($to, $subject, $body, $headers, if ($this->_invoker->mail($to, $subject, $body, $headers, $this->_formatExtraParams($this->_extraParams, $reversePath))) {
sprintf($this->_extraParams, $reversePath))) {
if ($evt) { if ($evt) {
$evt->setResult(Swift_Events_SendEvent::RESULT_SUCCESS); $evt->setResult(Swift_Events_SendEvent::RESULT_SUCCESS);
$evt->setFailedRecipients($failedRecipients); $evt->setFailedRecipients($failedRecipients);
@ -234,4 +235,21 @@ class Swift_Transport_MailTransport implements Swift_Transport
return $path; return $path;
} }
/**
* Return php mail extra params to use for invoker->mail.
*
* @param $extraParams
* @param $reversePath
*
* @return string|null
*/
private function _formatExtraParams($extraParams, $reversePath)
{
if (false !== strpos($extraParams, '-f%s')) {
$extraParams = empty($reversePath) ? str_replace('-f%s', '', $extraParams) : sprintf($extraParams, escapeshellarg($reversePath));
}
return !empty($extraParams) ? $extraParams : null;
}
} }

View file

@ -102,6 +102,7 @@ class Swift_Transport_SendmailTransport extends Swift_Transport_AbstractSmtpTran
$failedRecipients = (array) $failedRecipients; $failedRecipients = (array) $failedRecipients;
$command = $this->getCommand(); $command = $this->getCommand();
$buffer = $this->getBuffer(); $buffer = $this->getBuffer();
$count = 0;
if (false !== strpos($command, ' -t')) { if (false !== strpos($command, ' -t')) {
if ($evt = $this->_eventDispatcher->createSendEvent($this, $message)) { if ($evt = $this->_eventDispatcher->createSendEvent($this, $message)) {

View file

@ -32,8 +32,8 @@ class Swift_Transport_SimpleMailInvoker implements Swift_Transport_MailInvoker
{ {
if (!ini_get('safe_mode')) { if (!ini_get('safe_mode')) {
return @mail($to, $subject, $body, $headers, $extraParams); return @mail($to, $subject, $body, $headers, $extraParams);
} else {
return @mail($to, $subject, $body, $headers);
} }
return @mail($to, $subject, $body, $headers);
} }
} }

View file

@ -260,7 +260,11 @@ class Swift_Transport_StreamBuffer extends Swift_ByteStream_AbstractFilterableIn
if (!empty($this->_params['sourceIp'])) { if (!empty($this->_params['sourceIp'])) {
$options['socket']['bindto'] = $this->_params['sourceIp'].':0'; $options['socket']['bindto'] = $this->_params['sourceIp'].':0';
} }
$this->_stream = @stream_socket_client($host.':'.$this->_params['port'], $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, stream_context_create($options)); if (isset($this->_params['stream_context_options'])) {
$options = array_merge($options, $this->_params['stream_context_options']);
}
$streamContext = stream_context_create($options);
$this->_stream = @stream_socket_client($host.':'.$this->_params['port'], $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $streamContext);
if (false === $this->_stream) { if (false === $this->_stream) {
throw new Swift_TransportException( throw new Swift_TransportException(
'Connection could not be established with host '.$this->_params['host']. 'Connection could not be established with host '.$this->_params['host'].

View file

View file

@ -32,6 +32,6 @@
</testsuites> </testsuites>
<listeners> <listeners>
<listener class="\Mockery\Adapter\Phpunit\TestListener"></listener> <listener class="Mockery\Adapter\Phpunit\TestListener"/>
</listeners> </listeners>
</phpunit> </phpunit>

View file

@ -36,6 +36,10 @@ class Swift_Encoder_QpEncoderAcceptanceTest extends \PHPUnit_Framework_TestCase
$text = file_get_contents($sampleDir.'/'.$sampleFile); $text = file_get_contents($sampleDir.'/'.$sampleFile);
$encodedText = $encoder->encodeString($text); $encodedText = $encoder->encodeString($text);
foreach (explode("\r\n", $encodedText) as $line) {
$this->assertLessThanOrEqual(76, strlen($line));
}
$this->assertEquals( $this->assertEquals(
quoted_printable_decode($encodedText), $text, quoted_printable_decode($encodedText), $text,
'%s: Encoded string should decode back to original string for sample '. '%s: Encoded string should decode back to original string for sample '.

View file

@ -2,6 +2,8 @@
class Swift_Mime_ContentEncoder_NativeQpContentEncoderAcceptanceTest extends \PHPUnit_Framework_TestCase class Swift_Mime_ContentEncoder_NativeQpContentEncoderAcceptanceTest extends \PHPUnit_Framework_TestCase
{ {
protected $_samplesDir;
/** /**
* @var Swift_Mime_ContentEncoder_NativeQpContentEncoder * @var Swift_Mime_ContentEncoder_NativeQpContentEncoder
*/ */

View file

@ -35,8 +35,8 @@ class Swift_Mime_EmbeddedFileAcceptanceTest extends \PHPUnit_Framework_TestCase
$this->assertEquals( $this->assertEquals(
'Content-Type: application/pdf'."\r\n". 'Content-Type: application/pdf'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n". 'Content-Transfer-Encoding: base64'."\r\n".
'Content-Disposition: inline'."\r\n". 'Content-ID: <foo@bar>'."\r\n".
'Content-ID: <foo@bar>'."\r\n", 'Content-Disposition: inline'."\r\n",
$file->toString() $file->toString()
); );
} }
@ -50,8 +50,8 @@ class Swift_Mime_EmbeddedFileAcceptanceTest extends \PHPUnit_Framework_TestCase
$this->assertEquals( $this->assertEquals(
'Content-Type: application/pdf'."\r\n". 'Content-Type: application/pdf'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n". 'Content-Transfer-Encoding: base64'."\r\n".
'Content-Disposition: attachment'."\r\n". 'Content-ID: <'.$id.'>'."\r\n".
'Content-ID: <'.$id.'>'."\r\n", 'Content-Disposition: attachment'."\r\n",
$file->toString() $file->toString()
); );
} }
@ -65,8 +65,8 @@ class Swift_Mime_EmbeddedFileAcceptanceTest extends \PHPUnit_Framework_TestCase
$this->assertEquals( $this->assertEquals(
'Content-Type: application/pdf; name=foo.pdf'."\r\n". 'Content-Type: application/pdf; name=foo.pdf'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n". 'Content-Transfer-Encoding: base64'."\r\n".
'Content-Disposition: inline; filename=foo.pdf'."\r\n". 'Content-ID: <'.$id.'>'."\r\n".
'Content-ID: <'.$id.'>'."\r\n", 'Content-Disposition: inline; filename=foo.pdf'."\r\n",
$file->toString() $file->toString()
); );
} }
@ -80,8 +80,8 @@ class Swift_Mime_EmbeddedFileAcceptanceTest extends \PHPUnit_Framework_TestCase
$this->assertEquals( $this->assertEquals(
'Content-Type: application/pdf'."\r\n". 'Content-Type: application/pdf'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n". 'Content-Transfer-Encoding: base64'."\r\n".
'Content-Disposition: inline; size=12340'."\r\n". 'Content-ID: <'.$id.'>'."\r\n".
'Content-ID: <'.$id.'>'."\r\n", 'Content-Disposition: inline; size=12340'."\r\n",
$file->toString() $file->toString()
); );
} }
@ -93,11 +93,12 @@ class Swift_Mime_EmbeddedFileAcceptanceTest extends \PHPUnit_Framework_TestCase
$file->setContentType('application/pdf'); $file->setContentType('application/pdf');
$file->setFilename('foo.pdf'); $file->setFilename('foo.pdf');
$file->setSize(12340); $file->setSize(12340);
$this->assertEquals( $this->assertEquals(
'Content-Type: application/pdf; name=foo.pdf'."\r\n". 'Content-Type: application/pdf; name=foo.pdf'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n". 'Content-Transfer-Encoding: base64'."\r\n".
'Content-Disposition: inline; filename=foo.pdf; size=12340'."\r\n". 'Content-ID: <'.$id.'>'."\r\n".
'Content-ID: <'.$id.'>'."\r\n", 'Content-Disposition: inline; filename=foo.pdf; size=12340'."\r\n",
$file->toString() $file->toString()
); );
} }
@ -113,8 +114,8 @@ class Swift_Mime_EmbeddedFileAcceptanceTest extends \PHPUnit_Framework_TestCase
$this->assertEquals( $this->assertEquals(
'Content-Type: application/pdf; name=foo.pdf'."\r\n". 'Content-Type: application/pdf; name=foo.pdf'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n". 'Content-Transfer-Encoding: base64'."\r\n".
'Content-Disposition: inline; filename=foo.pdf; size=12340'."\r\n".
'Content-ID: <'.$id.'>'."\r\n". 'Content-ID: <'.$id.'>'."\r\n".
'Content-Disposition: inline; filename=foo.pdf; size=12340'."\r\n".
"\r\n". "\r\n".
base64_encode('abcd'), base64_encode('abcd'),
$file->toString() $file->toString()

View file

@ -778,8 +778,8 @@ class Swift_Mime_SimpleMessageAcceptanceTest extends \PHPUnit_Framework_TestCase
'--\\2'."\r\n". '--\\2'."\r\n".
'Content-Type: image/jpeg; name=myimage.jpg'."\r\n". 'Content-Type: image/jpeg; name=myimage.jpg'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n". 'Content-Transfer-Encoding: base64'."\r\n".
'Content-Disposition: inline; filename=myimage.jpg'."\r\n".
'Content-ID: <'.$cid.'>'."\r\n". 'Content-ID: <'.$cid.'>'."\r\n".
'Content-Disposition: inline; filename=myimage.jpg'."\r\n".
"\r\n". "\r\n".
preg_quote(base64_encode('<image data>'), '~'). preg_quote(base64_encode('<image data>'), '~').
"\r\n\r\n". "\r\n\r\n".
@ -857,8 +857,8 @@ class Swift_Mime_SimpleMessageAcceptanceTest extends \PHPUnit_Framework_TestCase
'--\\1'."\r\n". '--\\1'."\r\n".
'Content-Type: image/jpeg; name=myimage.jpg'."\r\n". 'Content-Type: image/jpeg; name=myimage.jpg'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n". 'Content-Transfer-Encoding: base64'."\r\n".
'Content-Disposition: inline; filename=myimage.jpg'."\r\n".
'Content-ID: <'.$cid.'>'."\r\n". 'Content-ID: <'.$cid.'>'."\r\n".
'Content-Disposition: inline; filename=myimage.jpg'."\r\n".
"\r\n". "\r\n".
preg_quote(base64_encode('<image data>'), '~'). preg_quote(base64_encode('<image data>'), '~').
"\r\n\r\n". "\r\n\r\n".
@ -938,8 +938,8 @@ class Swift_Mime_SimpleMessageAcceptanceTest extends \PHPUnit_Framework_TestCase
'--\\1'."\r\n". '--\\1'."\r\n".
'Content-Type: image/jpeg; name=myimage.jpg'."\r\n". 'Content-Type: image/jpeg; name=myimage.jpg'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n". 'Content-Transfer-Encoding: base64'."\r\n".
'Content-Disposition: inline; filename=myimage.jpg'."\r\n".
'Content-ID: <'.$cid.'>'."\r\n". 'Content-ID: <'.$cid.'>'."\r\n".
'Content-Disposition: inline; filename=myimage.jpg'."\r\n".
"\r\n". "\r\n".
preg_quote(base64_encode('<image data>'), '~'). preg_quote(base64_encode('<image data>'), '~').
"\r\n\r\n". "\r\n\r\n".

View file

@ -29,6 +29,6 @@ class Swift_Transport_StreamBuffer_BasicSocketAcceptanceTest
'protocol' => 'tcp', 'protocol' => 'tcp',
'blocking' => 1, 'blocking' => 1,
'timeout' => 15, 'timeout' => 15,
)); ));
} }
} }

View file

@ -4,6 +4,8 @@ class Swift_Transport_StreamBuffer_SocketTimeoutTest extends \PHPUnit_Framework_
{ {
protected $_buffer; protected $_buffer;
protected $_randomHighPort;
protected $_server; protected $_server;
public function setUp() public function setUp()
@ -41,7 +43,7 @@ class Swift_Transport_StreamBuffer_SocketTimeoutTest extends \PHPUnit_Framework_
'protocol' => 'tcp', 'protocol' => 'tcp',
'blocking' => 1, 'blocking' => 1,
'timeout' => 1, 'timeout' => 1,
)); ));
} }
public function testTimeoutException() public function testTimeoutException()

View file

@ -36,6 +36,6 @@ class Swift_Transport_StreamBuffer_SslSocketAcceptanceTest
'protocol' => 'ssl', 'protocol' => 'ssl',
'blocking' => 1, 'blocking' => 1,
'timeout' => 15, 'timeout' => 15,
)); ));
} }
} }

View file

@ -1,11 +1,13 @@
<?php <?php
$autoloader = require_once dirname(__DIR__).'/vendor/autoload.php'; require_once dirname(__DIR__).'/vendor/autoload.php';
$autoloader->add('Swift_', __DIR__.'/unit');
// Disable garbage collector to prevent segfaults
gc_disable();
set_include_path(get_include_path().PATH_SEPARATOR.dirname(__DIR__).'/lib'); set_include_path(get_include_path().PATH_SEPARATOR.dirname(__DIR__).'/lib');
\Mockery::getConfiguration()->allowMockingNonExistentMethods(false); Mockery::getConfiguration()->allowMockingNonExistentMethods(false);
if (is_file(__DIR__.'/acceptance.conf.php')) { if (is_file(__DIR__.'/acceptance.conf.php')) {
require_once __DIR__.'/acceptance.conf.php'; require_once __DIR__.'/acceptance.conf.php';

View file

@ -2,14 +2,14 @@
class Swift_Bug274Test extends \PHPUnit_Framework_TestCase class Swift_Bug274Test extends \PHPUnit_Framework_TestCase
{ {
public function testEmptyFileNameAsAttachement() public function testEmptyFileNameAsAttachment()
{ {
$message = new Swift_Message(); $message = new Swift_Message();
$this->setExpectedException('Swift_IoException', 'The path cannot be empty'); $this->setExpectedException('Swift_IoException', 'The path cannot be empty');
$message->attach(Swift_Attachment::fromPath('')); $message->attach(Swift_Attachment::fromPath(''));
} }
public function testNonEmptyFileNameAsAttachement() public function testNonEmptyFileNameAsAttachment()
{ {
$message = new Swift_Message(); $message = new Swift_Message();
try { try {

View file

@ -60,8 +60,8 @@ class Swift_Bug34Test extends \PHPUnit_Framework_TestCase
'--\\1'."\r\n". '--\\1'."\r\n".
'Content-Type: image/gif; name=image.gif'."\r\n". 'Content-Type: image/gif; name=image.gif'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n". 'Content-Transfer-Encoding: base64'."\r\n".
'Content-Disposition: inline; filename=image.gif'."\r\n".
'Content-ID: <'.$cidVal.'>'."\r\n". 'Content-ID: <'.$cidVal.'>'."\r\n".
'Content-Disposition: inline; filename=image.gif'."\r\n".
"\r\n". "\r\n".
preg_quote(base64_encode('<image data>'), '~'). preg_quote(base64_encode('<image data>'), '~').
"\r\n\r\n". "\r\n\r\n".

View file

@ -57,8 +57,8 @@ class Swift_Bug38Test extends \PHPUnit_Framework_TestCase
'--'.$boundary."\r\n". '--'.$boundary."\r\n".
'Content-Type: image/gif; name=image.gif'."\r\n". 'Content-Type: image/gif; name=image.gif'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n". 'Content-Transfer-Encoding: base64'."\r\n".
'Content-Disposition: inline; filename=image.gif'."\r\n".
'Content-ID: <'.preg_quote($imgId, '~').'>'."\r\n". 'Content-ID: <'.preg_quote($imgId, '~').'>'."\r\n".
'Content-Disposition: inline; filename=image.gif'."\r\n".
"\r\n". "\r\n".
preg_quote(base64_encode('<data>'), '~'). preg_quote(base64_encode('<data>'), '~').
"\r\n\r\n". "\r\n\r\n".
@ -106,8 +106,8 @@ class Swift_Bug38Test extends \PHPUnit_Framework_TestCase
'--'.$boundary."\r\n". '--'.$boundary."\r\n".
'Content-Type: image/gif; name=image.gif'."\r\n". 'Content-Type: image/gif; name=image.gif'."\r\n".
'Content-Transfer-Encoding: base64'."\r\n". 'Content-Transfer-Encoding: base64'."\r\n".
'Content-Disposition: inline; filename=image.gif'."\r\n".
'Content-ID: <'.preg_quote($imgId, '~').'>'."\r\n". 'Content-ID: <'.preg_quote($imgId, '~').'>'."\r\n".
'Content-Disposition: inline; filename=image.gif'."\r\n".
"\r\n". "\r\n".
preg_quote(base64_encode('<data>'), '~'). preg_quote(base64_encode('<data>'), '~').
"\r\n\r\n". "\r\n\r\n".

View file

@ -0,0 +1,19 @@
<?php
class Swift_FileByteStreamConsecutiveReadCalls extends \PHPUnit_Framework_TestCase
{
/**
* @test
* @expectedException \Swift_IoException
*/
public function shouldThrowExceptionOnConsecutiveRead()
{
$fbs = new \Swift_ByteStream_FileByteStream('does not exist');
try {
$fbs->read(100);
} catch (\Swift_IoException $exc) {
$fbs->read(100);
}
}
}

View file

@ -1,10 +0,0 @@
<?php
class EsmtpTransportFixture extends Swift_Transport_EsmtpTransport
{
/** This is so Mockery doesn't throw a fit. */
private function _sortHandlers($a, $b)
{
return 1;
}
}

View file

@ -5,6 +5,8 @@
*/ */
class Swift_Smoke_AttachmentSmokeTest extends SwiftMailerSmokeTestCase class Swift_Smoke_AttachmentSmokeTest extends SwiftMailerSmokeTestCase
{ {
private $_attFile;
public function setUp() public function setUp()
{ {
$this->_attFile = __DIR__.'/../../../_samples/files/textfile.zip'; $this->_attFile = __DIR__.'/../../../_samples/files/textfile.zip';

View file

@ -5,6 +5,8 @@
*/ */
class Swift_Smoke_HtmlWithAttachmentSmokeTest extends SwiftMailerSmokeTestCase class Swift_Smoke_HtmlWithAttachmentSmokeTest extends SwiftMailerSmokeTestCase
{ {
private $_attFile;
public function setUp() public function setUp()
{ {
$this->_attFile = __DIR__.'/../../../_samples/files/textfile.zip'; $this->_attFile = __DIR__.'/../../../_samples/files/textfile.zip';

View file

@ -5,6 +5,8 @@
*/ */
class Swift_Smoke_InternationalSmokeTest extends SwiftMailerSmokeTestCase class Swift_Smoke_InternationalSmokeTest extends SwiftMailerSmokeTestCase
{ {
private $_attFile;
public function setUp() public function setUp()
{ {
$this->_attFile = __DIR__.'/../../../_samples/files/textfile.zip'; $this->_attFile = __DIR__.'/../../../_samples/files/textfile.zip';

View file

@ -54,9 +54,7 @@ class Swift_ByteStream_ArrayByteStreamTest extends \PHPUnit_Framework_TestCase
public function testResettingPointerAfterExhaustion() public function testResettingPointerAfterExhaustion()
{ {
$input = array('a', 'b', 'c'); $input = array('a', 'b', 'c');
$bs = $this->_createArrayStream($input); $bs = $this->_createArrayStream($input); while (false !== $bs->read(1));
while (false !== $bs->read(1));
$bs->setReadPointer(0); $bs->setReadPointer(0);
$this->assertEquals('a', $bs->read(1), $this->assertEquals('a', $bs->read(1),

View file

@ -372,10 +372,31 @@ class Swift_Encoder_QpEncoderTest extends \SwiftMailerTestCase
); );
} }
public function testTextIsPreWrapped()
{
$encoder = $this->createEncoder();
$input = str_repeat('a', 70)."\r\n".
str_repeat('a', 70)."\r\n".
str_repeat('a', 70);
$this->assertEquals(
$input, $encoder->encodeString($input)
);
}
// -- Creation methods // -- Creation methods
private function _createCharStream() private function _createCharStream()
{ {
return $this->getMockery('Swift_CharacterStream')->shouldIgnoreMissing(); return $this->getMockery('Swift_CharacterStream')->shouldIgnoreMissing();
} }
private function createEncoder()
{
$factory = new Swift_CharacterReaderFactory_SimpleCharacterReaderFactory();
$charStream = new Swift_CharacterStream_NgCharacterStream($factory, 'utf-8');
return new Swift_Encoder_QpEncoder($charStream);
}
} }

View file

@ -140,11 +140,6 @@ class Swift_MailerTest extends \SwiftMailerTestCase
return $this->getMockery('Swift_Mime_Message')->shouldIgnoreMissing(); return $this->getMockery('Swift_Mime_Message')->shouldIgnoreMissing();
} }
private function _createIterator()
{
return $this->getMockery('Swift_Mailer_RecipientIterator')->shouldIgnoreMissing();
}
private function _createMailer(Swift_Transport $transport) private function _createMailer(Swift_Transport $transport)
{ {
return new Swift_Mailer($transport); return new Swift_Mailer($transport);

View file

@ -379,7 +379,7 @@ abstract class Swift_Mime_AbstractMimeEntityTest extends \SwiftMailerTestCase
$this->_createEncoder(), $this->_createCache() $this->_createEncoder(), $this->_createCache()
); );
$firstBoundary = $entity->getBoundary(); $firstBoundary = $entity->getBoundary();
for ($i = 0; $i < 10; $i++) { for ($i = 0; $i < 10; ++$i) {
$this->assertEquals($firstBoundary, $entity->getBoundary()); $this->assertEquals($firstBoundary, $entity->getBoundary());
} }
} }
@ -540,13 +540,13 @@ abstract class Swift_Mime_AbstractMimeEntityTest extends \SwiftMailerTestCase
$child1 = new MimeEntityFixture(Swift_Mime_MimeEntity::LEVEL_ALTERNATIVE, $child1 = new MimeEntityFixture(Swift_Mime_MimeEntity::LEVEL_ALTERNATIVE,
"Content-Type: text/plain\r\n". "Content-Type: text/plain\r\n".
"\r\n". "\r\n".
'foobar' 'foobar', 'text/plain'
); );
$child2 = new MimeEntityFixture(Swift_Mime_MimeEntity::LEVEL_ALTERNATIVE, $child2 = new MimeEntityFixture(Swift_Mime_MimeEntity::LEVEL_ALTERNATIVE,
"Content-Type: text/html\r\n". "Content-Type: text/html\r\n".
"\r\n". "\r\n".
'<b>foobar</b>' '<b>foobar</b>', 'text/html'
); );
$headers->shouldReceive('toString') $headers->shouldReceive('toString')
@ -623,7 +623,7 @@ abstract class Swift_Mime_AbstractMimeEntityTest extends \SwiftMailerTestCase
"\r\n". "\r\n".
'data'. 'data'.
"\r\n\r\n--xxx--\r\n". "\r\n\r\n--xxx--\r\n".
"\$~", '$~',
$entity->toString() $entity->toString()
); );
} }

View file

@ -50,7 +50,7 @@ class Swift_Mime_ContentEncoder_PlainContentEncoderTest extends \SwiftMailerTest
$encoder = $this->_getEncoder('7bit'); $encoder = $this->_getEncoder('7bit');
$chars = array(); $chars = array();
for ($i = 0; $i < 50; $i++) { for ($i = 0; $i < 50; ++$i) {
$chars[] = 'a'; $chars[] = 'a';
} }
$input = implode(' ', $chars); //99 chars long $input = implode(' ', $chars); //99 chars long
@ -75,7 +75,7 @@ class Swift_Mime_ContentEncoder_PlainContentEncoderTest extends \SwiftMailerTest
->zeroOrMoreTimes() ->zeroOrMoreTimes()
->andReturnUsing($collection); ->andReturnUsing($collection);
for ($i = 0; $i < 50; $i++) { for ($i = 0; $i < 50; ++$i) {
$os->shouldReceive('read') $os->shouldReceive('read')
->once() ->once()
->andReturn('a '); ->andReturn('a ');

View file

@ -472,6 +472,25 @@ class Swift_Mime_ContentEncoder_QpContentEncoderTest extends \SwiftMailerTestCas
$encoder->charsetChanged('windows-1252'); $encoder->charsetChanged('windows-1252');
} }
public function testTextIsPreWrapped()
{
$encoder = $this->createEncoder();
$input = str_repeat('a', 70)."\r\n".
str_repeat('a', 70)."\r\n".
str_repeat('a', 70);
$os = new Swift_ByteStream_ArrayByteStream();
$is = new Swift_ByteStream_ArrayByteStream();
$is->write($input);
$encoder->encodeByteStream($is, $os);
$this->assertEquals(
$input, $os->read(PHP_INT_MAX)
);
}
// -- Creation Methods // -- Creation Methods
private function _createCharacterStream($stub = false) private function _createCharacterStream($stub = false)
@ -479,9 +498,12 @@ class Swift_Mime_ContentEncoder_QpContentEncoderTest extends \SwiftMailerTestCas
return $this->getMockery('Swift_CharacterStream')->shouldIgnoreMissing(); return $this->getMockery('Swift_CharacterStream')->shouldIgnoreMissing();
} }
private function _createEncoder($charStream) private function createEncoder()
{ {
return new Swift_Mime_HeaderEncoder_QpHeaderEncoder($charStream); $factory = new Swift_CharacterReaderFactory_SimpleCharacterReaderFactory();
$charStream = new Swift_CharacterStream_NgCharacterStream($factory, 'utf-8');
return new Swift_Mime_ContentEncoder_QpContentEncoder($charStream);
} }
private function _createOutputByteStream($stub = false) private function _createOutputByteStream($stub = false)

View file

@ -29,7 +29,7 @@ class Swift_Plugins_AntiFloodPluginTest extends \PHPUnit_Framework_TestCase
$evt = $this->_createSendEvent($transport); $evt = $this->_createSendEvent($transport);
$plugin = new Swift_Plugins_AntiFloodPlugin(10); $plugin = new Swift_Plugins_AntiFloodPlugin(10);
for ($i = 0; $i < 12; $i++) { for ($i = 0; $i < 12; ++$i) {
$plugin->sendPerformed($evt); $plugin->sendPerformed($evt);
} }
} }
@ -45,7 +45,7 @@ class Swift_Plugins_AntiFloodPluginTest extends \PHPUnit_Framework_TestCase
$evt = $this->_createSendEvent($transport); $evt = $this->_createSendEvent($transport);
$plugin = new Swift_Plugins_AntiFloodPlugin(2); $plugin = new Swift_Plugins_AntiFloodPlugin(2);
for ($i = 0; $i < 11; $i++) { for ($i = 0; $i < 11; ++$i) {
$plugin->sendPerformed($evt); $plugin->sendPerformed($evt);
} }
} }
@ -66,7 +66,7 @@ class Swift_Plugins_AntiFloodPluginTest extends \PHPUnit_Framework_TestCase
$evt = $this->_createSendEvent($transport); $evt = $this->_createSendEvent($transport);
$plugin = new Swift_Plugins_AntiFloodPlugin(99, 10, $sleeper); $plugin = new Swift_Plugins_AntiFloodPlugin(99, 10, $sleeper);
for ($i = 0; $i < 101; $i++) { for ($i = 0; $i < 101; ++$i) {
$plugin->sendPerformed($evt); $plugin->sendPerformed($evt);
} }
} }

View file

@ -2,6 +2,10 @@
class Swift_Plugins_BandwidthMonitorPluginTest extends \PHPUnit_Framework_TestCase class Swift_Plugins_BandwidthMonitorPluginTest extends \PHPUnit_Framework_TestCase
{ {
private $_monitor;
private $_bytes = 0;
public function setUp() public function setUp()
{ {
$this->_monitor = new Swift_Plugins_BandwidthMonitorPlugin(); $this->_monitor = new Swift_Plugins_BandwidthMonitorPlugin();
@ -117,7 +121,6 @@ class Swift_Plugins_BandwidthMonitorPluginTest extends \PHPUnit_Framework_TestCa
return $msg; return $msg;
} }
private $_bytes = 0;
public function _write($is) public function _write($is)
{ {
for ($i = 0; $i < $this->_bytes; ++$i) { for ($i = 0; $i < $this->_bytes; ++$i) {

View file

@ -1,7 +1,6 @@
<?php <?php
require_once dirname(__DIR__).'/EsmtpTransportTest.php'; require_once dirname(__DIR__).'/EsmtpTransportTest.php';
require_once dirname(dirname(dirname(dirname(__DIR__)))).'/fixtures/EsmtpTransportFixture.php';
interface Swift_Transport_EsmtpHandlerMixin extends Swift_Transport_EsmtpHandler interface Swift_Transport_EsmtpHandlerMixin extends Swift_Transport_EsmtpHandler
{ {
@ -9,8 +8,7 @@ interface Swift_Transport_EsmtpHandlerMixin extends Swift_Transport_EsmtpHandler
public function setPassword($pass); public function setPassword($pass);
} }
class Swift_Transport_EsmtpTransport_ExtensionSupportTest class Swift_Transport_EsmtpTransport_ExtensionSupportTest extends Swift_Transport_EsmtpTransportTest
extends Swift_Transport_EsmtpTransportTest
{ {
public function testExtensionHandlersAreSortedAsNeeded() public function testExtensionHandlersAreSortedAsNeeded()
{ {
@ -25,7 +23,7 @@ class Swift_Transport_EsmtpTransport_ExtensionSupportTest
$ext1->shouldReceive('getPriorityOver') $ext1->shouldReceive('getPriorityOver')
->zeroOrMoreTimes() ->zeroOrMoreTimes()
->with('STARTTLS') ->with('STARTTLS')
->andReturn(0); ->andReturn(1);
$ext2->shouldReceive('getHandledKeyword') $ext2->shouldReceive('getHandledKeyword')
->zeroOrMoreTimes() ->zeroOrMoreTimes()
->andReturn('STARTTLS'); ->andReturn('STARTTLS');
@ -142,7 +140,7 @@ class Swift_Transport_EsmtpTransport_ExtensionSupportTest
{ {
$buf = $this->_getBuffer(); $buf = $this->_getBuffer();
$dispatcher = $this->_createEventDispatcher(); $dispatcher = $this->_createEventDispatcher();
$smtp = new EsmtpTransportFixture($buf, array(), $dispatcher); $smtp = new Swift_Transport_EsmtpTransport($buf, array(), $dispatcher);
$ext1 = $this->getMockery('Swift_Transport_EsmtpHandler')->shouldIgnoreMissing(); $ext1 = $this->getMockery('Swift_Transport_EsmtpHandler')->shouldIgnoreMissing();
$ext2 = $this->getMockery('Swift_Transport_EsmtpHandler')->shouldIgnoreMissing(); $ext2 = $this->getMockery('Swift_Transport_EsmtpHandler')->shouldIgnoreMissing();
$ext3 = $this->getMockery('Swift_Transport_EsmtpHandler')->shouldIgnoreMissing(); $ext3 = $this->getMockery('Swift_Transport_EsmtpHandler')->shouldIgnoreMissing();
@ -228,7 +226,7 @@ class Swift_Transport_EsmtpTransport_ExtensionSupportTest
{ {
$buf = $this->_getBuffer(); $buf = $this->_getBuffer();
$dispatcher = $this->_createEventDispatcher(); $dispatcher = $this->_createEventDispatcher();
$smtp = new EsmtpTransportFixture($buf, array(), $dispatcher); $smtp = new Swift_Transport_EsmtpTransport($buf, array(), $dispatcher);
$ext1 = $this->getMockery('Swift_Transport_EsmtpHandler')->shouldIgnoreMissing(); $ext1 = $this->getMockery('Swift_Transport_EsmtpHandler')->shouldIgnoreMissing();
$ext2 = $this->getMockery('Swift_Transport_EsmtpHandler')->shouldIgnoreMissing(); $ext2 = $this->getMockery('Swift_Transport_EsmtpHandler')->shouldIgnoreMissing();
$ext3 = $this->getMockery('Swift_Transport_EsmtpHandler')->shouldIgnoreMissing(); $ext3 = $this->getMockery('Swift_Transport_EsmtpHandler')->shouldIgnoreMissing();

View file

@ -84,6 +84,108 @@ class Swift_Transport_MailTransportTest extends \SwiftMailerTestCase
$transport->send($message); $transport->send($message);
} }
public function testTransportSettingUsingReturnPathForExtraParams()
{
$invoker = $this->_createInvoker();
$dispatcher = $this->_createEventDispatcher();
$transport = $this->_createTransport($invoker, $dispatcher);
$headers = $this->_createHeaders();
$message = $this->_createMessage($headers);
$message->shouldReceive('getReturnPath')
->zeroOrMoreTimes()
->andReturn(
'foo@bar'
);
$invoker->shouldReceive('mail')
->once()
->with(\Mockery::any(), \Mockery::any(), \Mockery::any(), \Mockery::any(), '-f\'foo@bar\'');
$transport->send($message);
}
public function testTransportSettingEmptyExtraParams()
{
$invoker = $this->_createInvoker();
$dispatcher = $this->_createEventDispatcher();
$transport = $this->_createTransport($invoker, $dispatcher);
$headers = $this->_createHeaders();
$message = $this->_createMessage($headers);
$message->shouldReceive('getReturnPath')
->zeroOrMoreTimes()
->andReturn(null);
$message->shouldReceive('getSender')
->zeroOrMoreTimes()
->andReturn(null);
$message->shouldReceive('getFrom')
->zeroOrMoreTimes()
->andReturn(null);
$invoker->shouldReceive('mail')
->once()
->with(\Mockery::any(), \Mockery::any(), \Mockery::any(), \Mockery::any(), null);
$transport->send($message);
}
public function testTransportSettingSettingExtraParamsWithF()
{
$invoker = $this->_createInvoker();
$dispatcher = $this->_createEventDispatcher();
$transport = $this->_createTransport($invoker, $dispatcher);
$transport->setExtraParams('-x\'foo\' -f%s');
$headers = $this->_createHeaders();
$message = $this->_createMessage($headers);
$message->shouldReceive('getReturnPath')
->zeroOrMoreTimes()
->andReturn(
'foo@bar'
);
$message->shouldReceive('getSender')
->zeroOrMoreTimes()
->andReturn(null);
$message->shouldReceive('getFrom')
->zeroOrMoreTimes()
->andReturn(null);
$invoker->shouldReceive('mail')
->once()
->with(\Mockery::any(), \Mockery::any(), \Mockery::any(), \Mockery::any(), '-x\'foo\' -f\'foo@bar\'');
$transport->send($message);
}
public function testTransportSettingSettingExtraParamsWithoutF()
{
$invoker = $this->_createInvoker();
$dispatcher = $this->_createEventDispatcher();
$transport = $this->_createTransport($invoker, $dispatcher);
$transport->setExtraParams('-x\'foo\'');
$headers = $this->_createHeaders();
$message = $this->_createMessage($headers);
$message->shouldReceive('getReturnPath')
->zeroOrMoreTimes()
->andReturn(
'foo@bar'
);
$message->shouldReceive('getSender')
->zeroOrMoreTimes()
->andReturn(null);
$message->shouldReceive('getFrom')
->zeroOrMoreTimes()
->andReturn(null);
$invoker->shouldReceive('mail')
->once()
->with(\Mockery::any(), \Mockery::any(), \Mockery::any(), \Mockery::any(), '-x\'foo\'');
$transport->send($message);
}
public function testTransportUsesHeadersFromMessage() public function testTransportUsesHeadersFromMessage()
{ {
$invoker = $this->_createInvoker(); $invoker = $this->_createInvoker();
@ -94,15 +196,15 @@ class Swift_Transport_MailTransportTest extends \SwiftMailerTestCase
$message = $this->_createMessage($headers); $message = $this->_createMessage($headers);
$message->shouldReceive('toString') $message->shouldReceive('toString')
->zeroOrMoreTimes() ->zeroOrMoreTimes()
->andReturn( ->andReturn(
"Subject: Stuff\r\n". "Subject: Stuff\r\n".
"\r\n". "\r\n".
'This body' 'This body'
); );
$invoker->shouldReceive('mail') $invoker->shouldReceive('mail')
->once() ->once()
->with(\Mockery::any(), \Mockery::any(), \Mockery::any(), 'Subject: Stuff'.PHP_EOL, \Mockery::any()); ->with(\Mockery::any(), \Mockery::any(), \Mockery::any(), 'Subject: Stuff'.PHP_EOL, \Mockery::any());
$transport->send($message); $transport->send($message);
} }
@ -249,6 +351,45 @@ class Swift_Transport_MailTransportTest extends \SwiftMailerTestCase
$transport->send($message); $transport->send($message);
} }
public function testMessageHeadersOnlyHavePHPEolsDuringSending()
{
$invoker = $this->_createInvoker();
$dispatcher = $this->_createEventDispatcher();
$transport = $this->_createTransport($invoker, $dispatcher);
$subject = $this->_createHeader();
$subject->shouldReceive('getFieldBody')->andReturn("Foo\r\nBar");
$headers = $this->_createHeaders(array(
'Subject' => $subject,
));
$message = $this->_createMessage($headers);
$message->shouldReceive('toString')
->zeroOrMoreTimes()
->andReturn(
"From: Foo\r\n<foo@bar>\r\n".
"\r\n".
"This\r\n".
'body'
);
if ("\r\n" != PHP_EOL) {
$expectedHeaders = "From: Foo\n<foo@bar>\n";
$expectedSubject = "Foo\nBar";
$expectedBody = "This\nbody";
} else {
$expectedHeaders = "From: Foo\r\n<foo@bar>\r\n";
$expectedSubject = "Foo\r\nBar";
$expectedBody = "This\r\nbody";
}
$invoker->shouldReceive('mail')
->once()
->with(\Mockery::any(), $expectedSubject, $expectedBody, $expectedHeaders, \Mockery::any());
$transport->send($message);
}
// -- Creation Methods // -- Creation Methods
private function _createTransport($invoker, $dispatcher) private function _createTransport($invoker, $dispatcher)