0
0
mirror of https://github.com/PHPMailer/PHPMailer.git synced 2024-09-19 17:42:14 +02:00

Big cleanup for Symfony coding style and php-cs-fixer, see #1148

This commit is contained in:
Marcus Bointon 2017-09-07 18:21:09 +02:00
parent eb9e7f5f0c
commit 31493b6732
No known key found for this signature in database
GPG Key ID: DE31CD6EB646AA24
21 changed files with 1252 additions and 582 deletions

View File

@ -29,7 +29,8 @@
"zendframework/zend-serializer": "2.7.*",
"doctrine/annotations": "1.2.*",
"zendframework/zend-eventmanager": "3.0.*",
"zendframework/zend-i18n": "2.7.3"
"zendframework/zend-i18n": "2.7.3",
"friendsofphp/php-cs-fixer": "^2.2"
},
"suggest": {
"psr/log": "For optional PSR-3 debug logging",

513
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "c83b5cea4ea6633422ee7d0ce4f621b2",
"content-hash": "8067184a7c98f5da35efc75d4cf96446",
"packages": [],
"packages-dev": [
{
@ -374,17 +374,145 @@
],
"time": "2017-03-29T16:04:15+00:00"
},
{
"name": "friendsofphp/php-cs-fixer",
"version": "v2.2.6",
"source": {
"type": "git",
"url": "https://github.com/FriendsOfPHP/PHP-CS-Fixer.git",
"reference": "c1cc52c242f17c4d52d9601159631da488fac7a4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/c1cc52c242f17c4d52d9601159631da488fac7a4",
"reference": "c1cc52c242f17c4d52d9601159631da488fac7a4",
"shasum": ""
},
"require": {
"doctrine/annotations": "^1.2",
"ext-json": "*",
"ext-tokenizer": "*",
"gecko-packages/gecko-php-unit": "^2.0",
"php": "^5.3.6 || >=7.0 <7.2",
"sebastian/diff": "^1.4",
"symfony/console": "^2.4 || ^3.0",
"symfony/event-dispatcher": "^2.1 || ^3.0",
"symfony/filesystem": "^2.4 || ^3.0",
"symfony/finder": "^2.2 || ^3.0",
"symfony/options-resolver": "^2.6 || ^3.0",
"symfony/polyfill-php54": "^1.0",
"symfony/polyfill-php55": "^1.3",
"symfony/polyfill-php70": "^1.0",
"symfony/polyfill-php72": "^1.4",
"symfony/process": "^2.3 || ^3.0",
"symfony/stopwatch": "^2.5 || ^3.0"
},
"conflict": {
"hhvm": "<3.18"
},
"require-dev": {
"johnkary/phpunit-speedtrap": "^1.0.1",
"justinrainbow/json-schema": "^5.0",
"phpunit/phpunit": "^4.8.35 || ^5.4.3",
"satooshi/php-coveralls": "^1.0",
"symfony/phpunit-bridge": "^3.2.2"
},
"suggest": {
"ext-mbstring": "For handling non-UTF8 characters in cache signature.",
"symfony/polyfill-mbstring": "When enabling `ext-mbstring` is not possible."
},
"bin": [
"php-cs-fixer"
],
"type": "application",
"extra": {
"branch-alias": {
"dev-master": "2.2-dev"
}
},
"autoload": {
"psr-4": {
"PhpCsFixer\\": "src/"
},
"classmap": [
"tests/Test/AbstractFixerTestCase.php",
"tests/Test/AbstractIntegrationTestCase.php",
"tests/Test/IntegrationCase.php",
"tests/Test/IntegrationCaseFactory.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Dariusz Rumiński",
"email": "dariusz.ruminski@gmail.com"
},
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
}
],
"description": "A tool to automatically fix PHP code style",
"time": "2017-08-22T14:08:16+00:00"
},
{
"name": "gecko-packages/gecko-php-unit",
"version": "v2.2",
"source": {
"type": "git",
"url": "https://github.com/GeckoPackages/GeckoPHPUnit.git",
"reference": "ab525fac9a9ffea219687f261b02008b18ebf2d1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/GeckoPackages/GeckoPHPUnit/zipball/ab525fac9a9ffea219687f261b02008b18ebf2d1",
"reference": "ab525fac9a9ffea219687f261b02008b18ebf2d1",
"shasum": ""
},
"require": {
"php": "^5.3.6 || ^7.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35 || ^5.4.3"
},
"suggest": {
"ext-dom": "When testing with xml.",
"ext-libxml": "When testing with xml.",
"phpunit/phpunit": "This is an extension for it so make sure you have it some way."
},
"type": "library",
"autoload": {
"psr-4": {
"GeckoPackages\\PHPUnit\\": "src/PHPUnit"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Additional PHPUnit asserts and constraints.",
"homepage": "https://github.com/GeckoPackages",
"keywords": [
"extension",
"filesystem",
"phpunit"
],
"time": "2017-08-23T07:39:54+00:00"
},
{
"name": "herrera-io/json",
"version": "1.0.3",
"source": {
"type": "git",
"url": "https://github.com/kherge-abandoned/php-json.git",
"url": "https://github.com/kherge-php/json.git",
"reference": "60c696c9370a1e5136816ca557c17f82a6fa83f1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/kherge-abandoned/php-json/zipball/60c696c9370a1e5136816ca557c17f82a6fa83f1",
"url": "https://api.github.com/repos/kherge-php/json/zipball/60c696c9370a1e5136816ca557c17f82a6fa83f1",
"reference": "60c696c9370a1e5136816ca557c17f82a6fa83f1",
"shasum": ""
},
@ -433,6 +561,7 @@
"schema",
"validate"
],
"abandoned": "kherge/json",
"time": "2013-10-30T16:51:34+00:00"
},
{
@ -491,8 +620,51 @@
"phar",
"update"
],
"abandoned": true,
"time": "2013-10-30T17:23:01+00:00"
},
{
"name": "ircmaxell/password-compat",
"version": "v1.0.4",
"source": {
"type": "git",
"url": "https://github.com/ircmaxell/password_compat.git",
"reference": "5c5cde8822a69545767f7c7f3058cb15ff84614c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/ircmaxell/password_compat/zipball/5c5cde8822a69545767f7c7f3058cb15ff84614c",
"reference": "5c5cde8822a69545767f7c7f3058cb15ff84614c",
"shasum": ""
},
"require-dev": {
"phpunit/phpunit": "4.*"
},
"type": "library",
"autoload": {
"files": [
"lib/password.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Anthony Ferrara",
"email": "ircmaxell@php.net",
"homepage": "http://blog.ircmaxell.com"
}
],
"description": "A compatibility library for the proposed simplified password hashing algorithm: https://wiki.php.net/rfc/password_hash",
"homepage": "https://github.com/ircmaxell/password_compat",
"keywords": [
"hashing",
"password"
],
"time": "2014-11-20T16:49:30+00:00"
},
{
"name": "jms/metadata",
"version": "1.6.0",
@ -765,6 +937,7 @@
],
"description": "A parsing and comparison library for semantic versioning.",
"homepage": "http://github.com/kherge/Version",
"abandoned": true,
"time": "2012-08-16T17:13:03+00:00"
},
{
@ -890,6 +1063,54 @@
],
"time": "2015-09-19T14:15:08+00:00"
},
{
"name": "paragonie/random_compat",
"version": "v2.0.10",
"source": {
"type": "git",
"url": "https://github.com/paragonie/random_compat.git",
"reference": "634bae8e911eefa89c1abfbf1b66da679ac8f54d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/paragonie/random_compat/zipball/634bae8e911eefa89c1abfbf1b66da679ac8f54d",
"reference": "634bae8e911eefa89c1abfbf1b66da679ac8f54d",
"shasum": ""
},
"require": {
"php": ">=5.2.0"
},
"require-dev": {
"phpunit/phpunit": "4.*|5.*"
},
"suggest": {
"ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes."
},
"type": "library",
"autoload": {
"files": [
"lib/random.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Paragon Initiative Enterprises",
"email": "security@paragonie.com",
"homepage": "https://paragonie.com"
}
],
"description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7",
"keywords": [
"csprng",
"pseudorandom",
"random"
],
"time": "2017-03-13T16:27:32+00:00"
},
{
"name": "phpcollection/phpcollection",
"version": "0.5.0",
@ -1738,7 +1959,9 @@
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
"email": "fabien@symfony.com",
"homepage": "http://fabien.potencier.org",
"role": "Lead Developer"
}
],
"description": "Pimple is a simple Dependency Injection Container for PHP 5.3",
@ -2598,6 +2821,60 @@
"homepage": "https://symfony.com",
"time": "2017-06-01T20:52:29+00:00"
},
{
"name": "symfony/options-resolver",
"version": "v3.3.8",
"source": {
"type": "git",
"url": "https://github.com/symfony/options-resolver.git",
"reference": "ee4e22978fe885b54ee5da8c7964f0a5301abfb6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/options-resolver/zipball/ee4e22978fe885b54ee5da8c7964f0a5301abfb6",
"reference": "ee4e22978fe885b54ee5da8c7964f0a5301abfb6",
"shasum": ""
},
"require": {
"php": "^5.5.9|>=7.0.8"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.3-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\OptionsResolver\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony OptionsResolver Component",
"homepage": "https://symfony.com",
"keywords": [
"config",
"configuration",
"options"
],
"time": "2017-07-29T21:54:42+00:00"
},
{
"name": "symfony/polyfill-mbstring",
"version": "v1.4.0",
@ -2657,6 +2934,234 @@
],
"time": "2017-06-09T14:24:12+00:00"
},
{
"name": "symfony/polyfill-php54",
"version": "v1.5.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php54.git",
"reference": "b7763422a5334c914ef0298ed21b253d25913a6e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-php54/zipball/b7763422a5334c914ef0298ed21b253d25913a6e",
"reference": "b7763422a5334c914ef0298ed21b253d25913a6e",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.5-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Polyfill\\Php54\\": ""
},
"files": [
"bootstrap.php"
],
"classmap": [
"Resources/stubs"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill backporting some PHP 5.4+ features to lower PHP versions",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"polyfill",
"portable",
"shim"
],
"time": "2017-06-14T15:44:48+00:00"
},
{
"name": "symfony/polyfill-php55",
"version": "v1.5.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php55.git",
"reference": "29b1381d66f16e0581aab0b9f678ccf073288f68"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-php55/zipball/29b1381d66f16e0581aab0b9f678ccf073288f68",
"reference": "29b1381d66f16e0581aab0b9f678ccf073288f68",
"shasum": ""
},
"require": {
"ircmaxell/password-compat": "~1.0",
"php": ">=5.3.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.5-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Polyfill\\Php55\\": ""
},
"files": [
"bootstrap.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill backporting some PHP 5.5+ features to lower PHP versions",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"polyfill",
"portable",
"shim"
],
"time": "2017-06-14T15:44:48+00:00"
},
{
"name": "symfony/polyfill-php70",
"version": "v1.5.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php70.git",
"reference": "b6482e68974486984f59449ecea1fbbb22ff840f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-php70/zipball/b6482e68974486984f59449ecea1fbbb22ff840f",
"reference": "b6482e68974486984f59449ecea1fbbb22ff840f",
"shasum": ""
},
"require": {
"paragonie/random_compat": "~1.0|~2.0",
"php": ">=5.3.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.5-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Polyfill\\Php70\\": ""
},
"files": [
"bootstrap.php"
],
"classmap": [
"Resources/stubs"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"polyfill",
"portable",
"shim"
],
"time": "2017-06-14T15:44:48+00:00"
},
{
"name": "symfony/polyfill-php72",
"version": "v1.5.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php72.git",
"reference": "8abc9097f5001d310f0edba727469c988acc6ea7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/8abc9097f5001d310f0edba727469c988acc6ea7",
"reference": "8abc9097f5001d310f0edba727469c988acc6ea7",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.5-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Polyfill\\Php72\\": ""
},
"files": [
"bootstrap.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"polyfill",
"portable",
"shim"
],
"time": "2017-07-11T13:25:55+00:00"
},
{
"name": "symfony/process",
"version": "v2.8.22",

View File

@ -40,7 +40,7 @@ if (file_exists($privatekeyfile)) {
[
'digest_alg' => 'sha256',
'private_key_bits' => 2048,
'private_key_type' => OPENSSL_KEYTYPE_RSA
'private_key_type' => OPENSSL_KEYTYPE_RSA,
]
);
//Save private key
@ -71,7 +71,7 @@ $publickey = str_replace(["\r", "\n"], '', $publickey);
$keyparts = str_split($publickey, 253); //Becomes 255 when quotes are included
//Quote each chunk
foreach ($keyparts as $keypart) {
$dnsvalue .= '"'.trim($keypart).'" ';
$dnsvalue .= '"' . trim($keypart) . '" ';
}
echo "\n\nDNS key:\n\n" . trim($dnskey);
echo "\n\nDNS value:\n\n" . trim($dnsvalue);

View File

@ -13,12 +13,13 @@ require '../vendor/autoload.php';
* Example PHPMailer callback function.
* This is a global function, but you can also pass a closure (or any other callable)
* to the `action_function` property.
* @param bool $result result of the send action
* @param array $to email address of the recipient
* @param array $cc cc email addresses
* @param array $bcc bcc email addresses
* @param string $subject the subject
* @param string $body the email body
*
* @param bool $result result of the send action
* @param array $to email address of the recipient
* @param array $cc cc email addresses
* @param array $bcc bcc email addresses
* @param string $subject the subject
* @param string $body the email body
*/
function callbackAction($result, $to, $cc, $bcc, $subject, $body)
{

View File

@ -20,8 +20,9 @@ class myPHPMailer extends PHPMailer
{
/**
* myPHPMailer constructor.
*
* @param bool|null $exceptions
* @param string $body A default HTML message body
* @param string $body A default HTML message body
*/
public function __construct($exceptions, $body = '')
{
@ -48,7 +49,8 @@ class myPHPMailer extends PHPMailer
{
$this->Subject = '[Yay for me!] ' . $this->Subject;
$r = parent::send();
echo "I sent a message with subject ". $this->Subject;
echo "I sent a message with subject " . $this->Subject;
return $r;
}
}
@ -64,5 +66,5 @@ try {
$mail->send(); //no need to check for errors - the exception handler will do it
} catch (Exception $e) {
//Note that this is catching the PHPMailer Exception class, not the global \Exception type!
echo "Caught a ".get_class($e).": " . $e->getMessage();
echo "Caught a " . get_class($e) . ": " . $e->getMessage();
}

View File

@ -83,7 +83,8 @@ if (!$mail->send()) {
//Function to call which uses the PHP imap_*() functions to save messages: https://php.net/manual/en/book.imap.php
//You can use imap_getmailboxes($imapStream, '/imap/ssl') to get a list of available folders or labels, this can
//be useful if you are trying to get this working on a non-Gmail IMAP server.
function save_mail($mail) {
function save_mail($mail)
{
//You can change 'Sent Mail' to any other folder or tag
$path = "{imap.gmail.com:993/imap/ssl}[Gmail]/Sent Mail";

View File

@ -56,20 +56,24 @@ $clientSecret = 'RANDOMCHARS-----lGyjPcRtvP';
$refreshToken = 'RANDOMCHARS-----DWxgOvPT003r-yFUV49TQYag7_Aod7y0';
//Create a new OAuth2 provider instance
$provider = new Google([
'clientId' => $clientId,
'clientSecret' => $clientSecret
]);
$provider = new Google(
[
'clientId' => $clientId,
'clientSecret' => $clientSecret,
]
);
//Pass the OAuth provider instance to PHPMailer
$mail->setOAuth(
new OAuth([
'provider' => $provider,
'clientId' => $clientId,
'clientSecret' => $clientSecret,
'refreshToken' => $refreshToken,
'userName' => $email
])
new OAuth(
[
'provider' => $provider,
'clientId' => $clientId,
'clientSecret' => $clientSecret,
'refreshToken' => $refreshToken,
'userName' => $email,
]
)
);
//Set who the message is to be sent from

View File

@ -39,7 +39,7 @@ $mail->AltBody = 'To view the message, please use an HTML compatible email viewe
//You'll need to alter this to match your database
$mysql = mysqli_connect('localhost', 'username', 'password');
mysqli_select_db($mysql, 'mydb');
$result = mysqli_query($mysql, 'SELECT full_name, email, photo FROM mailinglist WHERE sent = false');
$result = mysqli_query($mysql, 'SELECT full_name, email, photo FROM mailinglist WHERE sent = FALSE');
foreach ($result as $row) {
$mail->addAddress($row['email'], $row['full_name']);
@ -55,7 +55,7 @@ foreach ($result as $row) {
//Mark it as sent in the DB
mysqli_query(
$mysql,
"UPDATE mailinglist SET sent = true WHERE email = '" .
"UPDATE mailinglist SET sent = TRUE WHERE email = '" .
mysqli_real_escape_string($mysql, $row['email']) . "'"
);
}

View File

@ -38,8 +38,8 @@ if (array_key_exists('to', $_POST)) {
//Validate to address
//Never allow arbitrary input for the 'to' address as it will turn your form into a spam gateway!
//Substitute appropriate addresses from your own domain, or simply use a single, fixed address
if (array_key_exists('to', $_POST) and in_array($_POST['to'], ['sales','support','accounts'])) {
$to = $_POST['to'].'@example.com';
if (array_key_exists('to', $_POST) and in_array($_POST['to'], ['sales', 'support', 'accounts'])) {
$to = $_POST['to'] . '@example.com';
} else {
$to = 'support@example.com';
}
@ -59,7 +59,7 @@ if (array_key_exists('to', $_POST)) {
//It's important not to use the submitter's address as the from address as it's forgery,
//which will cause your messages to fail SPF checks.
//Use an address in your own domain as the from address, put the submitter's address in a reply-to
$mail->setFrom('contact@example.com', (empty($name)? 'Contact form': $name));
$mail->setFrom('contact@example.com', (empty($name) ? 'Contact form' : $name));
$mail->addAddress($to);
$mail->addReplyTo($email, $name);
$mail->Subject = 'Contact form: ' . $subject;
@ -70,7 +70,7 @@ if (array_key_exists('to', $_POST)) {
$msg .= "Message sent!";
}
}
}?>
} ?>
<!DOCTYPE html>
<html>
<head>
@ -96,6 +96,6 @@ if (array_key_exists('to', $_POST)) {
</form>
<?php } else {
echo $msg;
}?>
} ?>
</body>
</html>

View File

@ -104,6 +104,7 @@ class SMTPLowMemory extends SMTP
$result = $this->sendCommand('DATA END', '.', 250);
//Restore timelimit
$this->Timelimit = $savetimelimit;
return $result;
}
}
@ -123,6 +124,7 @@ class PHPMailerLowMemory extends PHPMailer
if (!is_object($this->smtp)) {
$this->smtp = new SMTPLowMemory;
}
return $this->smtp;
}
}

View File

@ -35,14 +35,14 @@ $mail->SMTPSecure = 'tls';
//Custom connection options
//Note that these settings are INSECURE
$mail->SMTPOptions = array (
$mail->SMTPOptions = array(
'ssl' => [
'verify_peer' => true,
'verify_peer' => true,
'verify_depth' => 3,
'allow_self_signed' => true,
'peer_name' => 'smtp.example.com',
'cafile' => '/etc/ssl/ca_cert.pem'
]
'cafile' => '/etc/ssl/ca_cert.pem',
],
);
//Whether to use SMTP authentication

View File

@ -8,7 +8,7 @@
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
* @author Brent R. Matzelle (original founder)
* @copyright 2012 - 2016 Marcus Bointon
* @copyright 2012 - 2017 Marcus Bointon
* @copyright 2010 - 2012 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License

View File

@ -1,15 +1,15 @@
<?php
/**
* PHPMailer Exception class.
* PHP Version 5.5
* PHP Version 5.5.
*
* @package PHPMailer
* @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
*
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
* @author Brent R. Matzelle (original founder)
* @copyright 2012 - 2016 Marcus Bointon
* @copyright 2012 - 2017 Marcus Bointon
* @copyright 2010 - 2012 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
@ -21,15 +21,14 @@
namespace PHPMailer\PHPMailer;
/**
* PHPMailer exception handler
* PHPMailer exception handler.
*
* @package PHPMailer
* @author Marcus Bointon <phpmailer@synchromedia.co.uk>
*/
class Exception extends \Exception
{
/**
* Prettify error message output
* Prettify error message output.
*
* @return string
*/

View File

@ -1,11 +1,10 @@
<?php
/**
* PHPMailer - PHP email creation and transport class.
* PHP Version 5.5
* PHP Version 5.5.
*
* @package PHPMailer
* @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
*
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
@ -22,15 +21,15 @@
namespace PHPMailer\PHPMailer;
use League\OAuth2\Client\Grant\RefreshToken;
use League\OAuth2\Client\Token\AccessToken;
use League\OAuth2\Client\Provider\AbstractProvider;
use League\OAuth2\Client\Token\AccessToken;
/**
* OAuth - OAuth2 authentication wrapper class.
* Uses the oauth2-client package from the League of Extraordinary Packages
* Uses the oauth2-client package from the League of Extraordinary Packages.
*
* @see http://oauth2-client.thephpleague.com
* @package PHPMailer
*
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
*/
class OAuth
@ -82,7 +81,7 @@ class OAuth
* OAuth constructor.
*
* @param array $options Associative array containing
* `provider`, `userName`, `clientSecret`, `clientId` and `refreshToken` elements
* `provider`, `userName`, `clientSecret`, `clientId` and `refreshToken` elements
*/
public function __construct($options)
{
@ -100,7 +99,7 @@ class OAuth
*/
protected function getGrant()
{
return new RefreshToken;
return new RefreshToken();
}
/**
@ -127,6 +126,7 @@ class OAuth
if (null === $this->oauthToken or $this->oauthToken->hasExpired()) {
$this->oauthToken = $this->getToken();
}
return base64_encode(
'user=' .
$this->oauthUserEmail .

File diff suppressed because it is too large Load Diff

View File

@ -1,15 +1,15 @@
<?php
/**
* PHPMailer POP-Before-SMTP Authentication Class.
* PHP Version 5.5
* PHP Version 5.5.
*
* @package PHPMailer
* @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
*
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
* @author Brent R. Matzelle (original founder)
* @copyright 2012 - 2016 Marcus Bointon
* @copyright 2012 - 2017 Marcus Bointon
* @copyright 2010 - 2012 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
@ -33,7 +33,6 @@ namespace PHPMailer\PHPMailer;
* enough to do authentication.
* If you want a more complete class there are other POP3 classes for PHP available.
*
* @package PHPMailer
* @author Richard Davey (original author) <rich@corephp.co.uk>
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
@ -64,7 +63,7 @@ class POP3
/**
* Debug display level.
* Options: 0 = no, 1+ = yes
* Options: 0 = no, 1+ = yes.
*
* @var int
*/
@ -92,7 +91,7 @@ class POP3
public $tval;
/**
* POP3 username
* POP3 username.
*
* @var string
*/
@ -127,19 +126,19 @@ class POP3
protected $errors = [];
/**
* Line break constant
* Line break constant.
*/
const LE = "\r\n";
/**
* Simple static wrapper for all-in-one POP before SMTP
* Simple static wrapper for all-in-one POP before SMTP.
*
* @param string $host
* @param int|bool $port The port number to connect to
* @param string $host
* @param int|bool $port The port number to connect to
* @param int|bool $timeout The timeout value
* @param string $username
* @param string $password
* @param int $debug_level
* @param string $username
* @param string $password
* @param int $debug_level
*
* @return bool
*/
@ -151,7 +150,8 @@ class POP3
$password = '',
$debug_level = 0
) {
$pop = new POP3;
$pop = new self();
return $pop->authorise($host, $port, $timeout, $username, $password, $debug_level);
}
@ -160,12 +160,12 @@ class POP3
* A connect, login, disconnect sequence
* appropriate for POP-before SMTP authorisation.
*
* @param string $host The hostname to connect to
* @param int|bool $port The port number to connect to
* @param string $host The hostname to connect to
* @param int|bool $port The port number to connect to
* @param int|bool $timeout The timeout value
* @param string $username
* @param string $password
* @param int $debug_level
* @param string $username
* @param string $password
* @param int $debug_level
*
* @return bool
*/
@ -176,13 +176,13 @@ class POP3
if (false === $port) {
$this->port = static::DEFAULT_PORT;
} else {
$this->port = (integer)$port;
$this->port = (int) $port;
}
// If no timeout value provided, use default
if (false === $timeout) {
$this->tval = static::DEFAULT_TIMEOUT;
} else {
$this->tval = (integer)$timeout;
$this->tval = (int) $timeout;
}
$this->do_debug = $debug_level;
$this->username = $username;
@ -195,20 +195,22 @@ class POP3
$login_result = $this->login($this->username, $this->password);
if ($login_result) {
$this->disconnect();
return true;
}
}
// We need to disconnect regardless of whether the login succeeded
$this->disconnect();
return false;
}
/**
* Connect to a POP3 server.
*
* @param string $host
* @param string $host
* @param int|bool $port
* @param int $tval
* @param int $tval
*
* @return bool
*/
@ -244,6 +246,7 @@ class POP3
$this->setError(
"Failed to connect to server $host on port $port. errno: $errno; errstr: $errstr"
);
return false;
}
@ -256,8 +259,10 @@ class POP3
if ($this->checkResponse($pop3_response)) {
// The connection is established and the POP3 server is talking
$this->connected = true;
return true;
}
return false;
}
@ -293,6 +298,7 @@ class POP3
return true;
}
}
return false;
}
@ -308,14 +314,13 @@ class POP3
@fclose($this->pop_conn);
} catch (Exception $e) {
//Do nothing
};
}
}
/**
* Get a response from the POP3 server.
* $size is the maximum number of bytes to retrieve
*
* @param int $size
* @param int $size The maximum number of bytes to retrieve
*
* @return string
*/
@ -325,6 +330,7 @@ class POP3
if ($this->do_debug >= 1) {
echo 'Server -> Client: ', $response;
}
return $response;
}
@ -341,8 +347,10 @@ class POP3
if ($this->do_debug >= 2) { //Show client messages when debug >= 2
echo 'Client -> Server: ', $string;
}
return fwrite($this->pop_conn, $string, strlen($string));
}
return 0;
}
@ -358,10 +366,11 @@ class POP3
{
if (substr($string, 0, 3) !== '+OK') {
$this->setError("Server reported an error: $string");
return false;
} else {
return true;
}
return true;
}
/**
@ -395,15 +404,15 @@ class POP3
/**
* POP3 connection error handler.
*
* @param int $errno
* @param int $errno
* @param string $errstr
* @param string $errfile
* @param int $errline
* @param int $errline
*/
protected function catchWarning($errno, $errstr, $errfile, $errline)
{
$this->setError(
'Connecting to the POP3 server raised a PHP warning:'.
'Connecting to the POP3 server raised a PHP warning:' .
"errno: $errno errstr: $errstr; errfile: $errfile; errline: $errline"
);
}

View File

@ -1,15 +1,14 @@
<?php
/**
* PHPMailer RFC821 SMTP email transport class.
* PHP Version 5.5
* PHP Version 5.5.
*
* @package PHPMailer
* @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
* @author Brent R. Matzelle (original founder)
* @copyright 2012 - 2016 Marcus Bointon
* @copyright 2012 - 2017 Marcus Bointon
* @copyright 2010 - 2012 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
@ -24,7 +23,6 @@ namespace PHPMailer\PHPMailer;
* PHPMailer RFC821 SMTP email transport class.
* Implements RFC 821 SMTP commands and provides some utility methods for sending mail to an SMTP server.
*
* @package PHPMailer
* @author Chris Ryan
* @author Marcus Bointon <phpmailer@synchromedia.co.uk>
*/
@ -52,34 +50,34 @@ class SMTP
const DEFAULT_PORT = 25;
/**
* The maximum line length allowed by RFC 2822 section 2.1.1
* The maximum line length allowed by RFC 2822 section 2.1.1.
*
* @var int
*/
const MAX_LINE_LENGTH = 998;
/**
* Debug level for no output
* Debug level for no output.
*/
const DEBUG_OFF = 0;
/**
* Debug level to show client -> server messages
* Debug level to show client -> server messages.
*/
const DEBUG_CLIENT = 1;
/**
* Debug level to show client -> server and server -> client messages
* Debug level to show client -> server and server -> client messages.
*/
const DEBUG_SERVER = 2;
/**
* Debug level to show connection status, client -> server and server -> client messages
* Debug level to show connection status, client -> server and server -> client messages.
*/
const DEBUG_CONNECTION = 3;
/**
* Debug level to show all messages
* Debug level to show all messages.
*/
const DEBUG_LOWLEVEL = 4;
@ -90,7 +88,7 @@ class SMTP
* * self::DEBUG_CLIENT (`1`) Client commands
* * self::DEBUG_SERVER (`2`) Client commands and server responses
* * self::DEBUG_CONNECTION (`3`) As DEBUG_SERVER plus connection status
* * self::DEBUG_LOWLEVEL (`4`) Low-level data output, all messages
* * self::DEBUG_LOWLEVEL (`4`) Low-level data output, all messages.
*
* @var int
*/
@ -121,23 +119,25 @@ class SMTP
*
* @see http://en.wikipedia.org/wiki/Variable_envelope_return_path
* @see http://www.postfix.org/VERP_README.html Info on VERP
*
* @var bool
*/
public $do_verp = false;
/**
* The timeout value for connection, in seconds.
* Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2
* Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2.
* This needs to be quite high to function correctly with hosts using greetdelay as an anti-spam measure.
*
* @see http://tools.ietf.org/html/rfc2821#section-4.5.3.2
*
* @var int
*/
public $Timeout = 300;
/**
* How long to wait for commands to complete, in seconds.
* Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2
* Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2.
*
* @var int
*/
@ -152,7 +152,7 @@ class SMTP
'exim' => '/[0-9]{3} OK id=(.*)/',
'sendmail' => '/[0-9]{3} 2.0.0 (.*) Message/',
'postfix' => '/[0-9]{3} 2.0.0 Ok: queued as (.*)/',
'Microsoft_ESMTP' => '/[0-9]{3} 2.[0-9].0 (.*)@(?:.*) Queued mail for delivery/'
'Microsoft_ESMTP' => '/[0-9]{3} 2.[0-9].0 (.*)@(?:.*) Queued mail for delivery/',
];
/**
@ -210,8 +210,8 @@ class SMTP
/**
* Output debugging info via a user-selected method.
*
* @param string $str Debug string to output
* @param int $level The debug level of this message; see DEBUG_* constants
* @param string $str Debug string to output
* @param int $level The debug level of this message; see DEBUG_* constants
*
* @see SMTP::$Debugoutput
* @see SMTP::$do_debug
@ -224,11 +224,13 @@ class SMTP
//Is this a PSR-3 logger?
if (is_a($this->Debugoutput, 'Psr\Log\LoggerInterface')) {
$this->Debugoutput->debug($str);
return;
}
//Avoid clash with built-in function names
if (!in_array($this->Debugoutput, ['error_log', 'html', 'echo']) and is_callable($this->Debugoutput)) {
call_user_func($this->Debugoutput, $str, $level);
return;
}
switch ($this->Debugoutput) {
@ -249,27 +251,27 @@ class SMTP
//Normalize line breaks
$str = preg_replace('/\r\n|\r/ms', "\n", $str);
echo gmdate('Y-m-d H:i:s'),
"\t",
"\t",
//Trim trailing space
trim(
//Indent for readability, except for trailing break
str_replace(
"\n",
"\n \t ",
trim($str)
)
),
"\n";
trim(
//Indent for readability, except for trailing break
str_replace(
"\n",
"\n \t ",
trim($str)
)
),
"\n";
}
}
/**
* Connect to an SMTP server.
*
* @param string $host SMTP server IP or host name
* @param int $port The port number to connect to
* @param int $timeout How long to wait for the connection to open
* @param array $options An array of options for stream_context_create()
* @param string $host SMTP server IP or host name
* @param int $port The port number to connect to
* @param int $timeout How long to wait for the connection to open
* @param array $options An array of options for stream_context_create()
*
* @return bool
*/
@ -287,6 +289,7 @@ class SMTP
if ($this->connected()) {
// Already connected, generate error
$this->setError('Already connected to a server');
return false;
}
if (empty($port)) {
@ -295,7 +298,7 @@ class SMTP
// Connect to the SMTP server
$this->edebug(
"Connection: opening to $host:$port, timeout=$timeout, options=" .
(count($options) > 0 ? var_export($options, true): 'array()'),
(count($options) > 0 ? var_export($options, true) : 'array()'),
self::DEBUG_CONNECTION
);
$errno = 0;
@ -304,7 +307,7 @@ class SMTP
$socket_context = stream_context_create($options);
set_error_handler([$this, 'errorHandler']);
$this->smtp_conn = stream_socket_client(
$host . ":" . $port,
$host . ':' . $port,
$errno,
$errstr,
$timeout,
@ -315,7 +318,7 @@ class SMTP
} else {
//Fall back to fsockopen which should work in more places, but is missing some features
$this->edebug(
"Connection: stream_socket_client not available, falling back to fsockopen",
'Connection: stream_socket_client not available, falling back to fsockopen',
self::DEBUG_CONNECTION
);
set_error_handler([$this, 'errorHandler']);
@ -333,14 +336,15 @@ class SMTP
$this->setError(
'Failed to connect to server',
'',
(string)$errno,
(string)$errstr
(string) $errno,
(string) $errstr
);
$this->edebug(
'SMTP ERROR: ' . $this->error['error']
. ": $errstr ($errno)",
self::DEBUG_CLIENT
);
return false;
}
$this->edebug('Connection: opened', self::DEBUG_CONNECTION);
@ -357,6 +361,7 @@ class SMTP
// Get any announcement
$announce = $this->get_lines();
$this->edebug('SERVER -> CLIENT: ' . $announce, self::DEBUG_SERVER);
return true;
}
@ -389,20 +394,22 @@ class SMTP
$crypto_method
);
restore_error_handler();
return (bool)$crypto_ok;
return (bool) $crypto_ok;
}
/**
* Perform SMTP authentication.
* Must be run after hello().
*
* @see hello()
*
* @param string $username The user name
* @param string $password The password
* @param string $authtype The auth type (CRAM-MD5, PLAIN, LOGIN, XOAUTH2)
* @param OAuth $OAuth An optional OAuth instance for XOAUTH2 authentication
* @param OAuth $OAuth An optional OAuth instance for XOAUTH2 authentication
*
* @return bool True if successfully authenticated.
* @see hello()
* @return bool True if successfully authenticated
*/
public function authenticate(
$username,
@ -412,6 +419,7 @@ class SMTP
) {
if (!$this->server_caps) {
$this->setError('Authentication is not allowed before HELO/EHLO');
return false;
}
@ -421,6 +429,7 @@ class SMTP
$this->setError('Authentication is not allowed at this stage');
// 'at this stage' means that auth may be allowed after the stage changes
// e.g. after STARTTLS
return false;
}
@ -447,6 +456,7 @@ class SMTP
}
if (empty($authtype)) {
$this->setError('No supported authentication methods found');
return false;
}
self::edebug('Auth method selected: ' . $authtype, self::DEBUG_LOWLEVEL);
@ -454,6 +464,7 @@ class SMTP
if (!in_array($authtype, $this->server_caps['AUTH'])) {
$this->setError("The requested authentication method \"$authtype\" is not supported by the server");
return false;
}
} elseif (empty($authtype)) {
@ -480,10 +491,10 @@ class SMTP
if (!$this->sendCommand('AUTH', 'AUTH LOGIN', 334)) {
return false;
}
if (!$this->sendCommand("Username", base64_encode($username), 334)) {
if (!$this->sendCommand('Username', base64_encode($username), 334)) {
return false;
}
if (!$this->sendCommand("Password", base64_encode($password), 235)) {
if (!$this->sendCommand('Password', base64_encode($password), 235)) {
return false;
}
break;
@ -514,18 +525,20 @@ class SMTP
break;
default:
$this->setError("Authentication method \"$authtype\" is not supported");
return false;
}
return true;
}
/**
* Calculate an MD5 HMAC hash.
* Works like hash_hmac('md5', $data, $key)
* in case that function is not available
* in case that function is not available.
*
* @param string $data The data to hash
* @param string $key The key to hash with
* @param string $key The key to hash with
*
* @return string
*/
@ -559,7 +572,7 @@ class SMTP
/**
* Check connection state.
*
* @return bool True if connected.
* @return bool True if connected
*/
public function connected()
{
@ -572,10 +585,13 @@ class SMTP
self::DEBUG_CLIENT
);
$this->close();
return false;
}
return true; // everything looks good
}
return false;
}
@ -605,7 +621,7 @@ class SMTP
* that is to be send with the headers. Each header needs to be
* on a single line followed by a <CRLF> with the message headers
* and the message body being separated by an additional <CRLF>.
* Implements RFC 821: DATA <CRLF>
* Implements RFC 821: DATA <CRLF>.
*
* @param string $msg_data Message data to send
*
@ -688,6 +704,7 @@ class SMTP
$this->recordLastTransactionID();
//Restore timelimit
$this->Timelimit = $savetimelimit;
return $result;
}
@ -705,17 +722,18 @@ class SMTP
public function hello($host = '')
{
//Try extended hello first (RFC 2821)
return (bool)($this->sendHello('EHLO', $host) or $this->sendHello('HELO', $host));
return (bool) ($this->sendHello('EHLO', $host) or $this->sendHello('HELO', $host));
}
/**
* Send an SMTP HELO or EHLO command.
* Low-level implementation used by hello()
* Low-level implementation used by hello().
*
* @param string $hello The HELO string
* @param string $host The hostname to say we are
* @param string $host The hostname to say we are
*
* @return bool
*
* @see hello()
*/
protected function sendHello($hello, $host)
@ -727,6 +745,7 @@ class SMTP
} else {
$this->server_caps = null;
}
return $noerror;
}
@ -778,7 +797,7 @@ class SMTP
* $from. Returns true if successful or false otherwise. If True
* the mail transaction is started and then one or more recipient
* commands may be called followed by a data command.
* Implements RFC 821: MAIL <SP> FROM:<reverse-path> <CRLF>
* Implements RFC 821: MAIL <SP> FROM:<reverse-path> <CRLF>.
*
* @param string $from Source address of this message
*
@ -787,6 +806,7 @@ class SMTP
public function mail($from)
{
$useVerp = ($this->do_verp ? ' XVERP' : '');
return $this->sendCommand(
'MAIL FROM',
'MAIL FROM:<' . $from . '>' . $useVerp,
@ -797,7 +817,7 @@ class SMTP
/**
* Send an SMTP QUIT command.
* Closes the socket if there is no error or the $close_on_error argument is true.
* Implements from RFC 821: QUIT <CRLF>
* Implements from RFC 821: QUIT <CRLF>.
*
* @param bool $close_on_error Should the connection close if an error occurs?
*
@ -811,6 +831,7 @@ class SMTP
$this->close();
$this->error = $err; //Restore any error from the quit command
}
return $noerror;
}
@ -818,7 +839,7 @@ class SMTP
* Send an SMTP RCPT command.
* Sets the TO argument to $toaddr.
* Returns true if the recipient was accepted false if it was rejected.
* Implements from RFC 821: RCPT <SP> TO:<forward-path> <CRLF>
* Implements from RFC 821: RCPT <SP> TO:<forward-path> <CRLF>.
*
* @param string $address The address the message is being sent to
*
@ -836,9 +857,9 @@ class SMTP
/**
* Send an SMTP RSET command.
* Abort any transaction that is currently in progress.
* Implements RFC 821: RSET <CRLF>
* Implements RFC 821: RSET <CRLF>.
*
* @return bool True on success.
* @return bool True on success
*/
public function reset()
{
@ -848,21 +869,23 @@ class SMTP
/**
* Send a command to an SMTP server and check its return code.
*
* @param string $command The command name - not sent to the server
* @param string $commandstring The actual command to send
* @param int|array $expect One or more expected integer success codes
* @param string $command The command name - not sent to the server
* @param string $commandstring The actual command to send
* @param int|array $expect One or more expected integer success codes
*
* @return bool True on success.
* @return bool True on success
*/
protected function sendCommand($command, $commandstring, $expect)
{
if (!$this->connected()) {
$this->setError("Called $command without being connected");
return false;
}
//Reject line breaks in all commands
if (strpos($commandstring, "\n") !== false or strpos($commandstring, "\r") !== false) {
$this->setError("Command '$command' contained line breaks");
return false;
}
$this->client_send($commandstring . static::LE);
@ -870,13 +893,13 @@ class SMTP
$this->last_reply = $this->get_lines();
// Fetch SMTP code and possible error code explanation
$matches = [];
if (preg_match("/^([0-9]{3})[ -](?:([0-9]\\.[0-9]\\.[0-9]) )?/", $this->last_reply, $matches)) {
if (preg_match('/^([0-9]{3})[ -](?:([0-9]\\.[0-9]\\.[0-9]) )?/', $this->last_reply, $matches)) {
$code = $matches[1];
$code_ex = (count($matches) > 2 ? $matches[2] : null);
// Cut off error code from each response line
$detail = preg_replace(
"/{$code}[ -]" .
($code_ex ? str_replace('.', '\\.', $code_ex) . ' ' : '') . "/m",
($code_ex ? str_replace('.', '\\.', $code_ex) . ' ' : '') . '/m',
'',
$this->last_reply
);
@ -889,7 +912,7 @@ class SMTP
$this->edebug('SERVER -> CLIENT: ' . $this->last_reply, self::DEBUG_SERVER);
if (!in_array($code, (array)$expect)) {
if (!in_array($code, (array) $expect)) {
$this->setError(
"$command command failed",
$detail,
@ -900,10 +923,12 @@ class SMTP
'SMTP ERROR: ' . $this->error['error'] . ': ' . $this->last_reply,
self::DEBUG_CLIENT
);
return false;
}
$this->setError('');
return true;
}
@ -915,7 +940,7 @@ class SMTP
* commands may be called followed by a data command. This command
* will send the message to the users terminal if they are logged
* in and send them an email.
* Implements RFC 821: SAML <SP> FROM:<reverse-path> <CRLF>
* Implements RFC 821: SAML <SP> FROM:<reverse-path> <CRLF>.
*
* @param string $from The address the message is from
*
@ -940,7 +965,7 @@ class SMTP
/**
* Send an SMTP NOOP command.
* Used to keep keep-alives alive, doesn't actually do anything
* Used to keep keep-alives alive, doesn't actually do anything.
*
* @return bool
*/
@ -953,8 +978,8 @@ class SMTP
* Send an SMTP TURN command.
* This is an optional command for SMTP that this class does not support.
* This method is here to make the RFC821 Definition complete for this class
* and _may_ be implemented in future
* Implements from RFC 821: TURN <CRLF>
* and _may_ be implemented in future.
* Implements from RFC 821: TURN <CRLF>.
*
* @return bool
*/
@ -962,6 +987,7 @@ class SMTP
{
$this->setError('The SMTP TURN command is not implemented');
$this->edebug('SMTP NOTICE: ' . $this->error['error'], self::DEBUG_CLIENT);
return false;
}
@ -978,6 +1004,7 @@ class SMTP
set_error_handler([$this, 'errorHandler']);
$result = fwrite($this->smtp_conn, $data);
restore_error_handler();
return $result;
}
@ -992,7 +1019,7 @@ class SMTP
}
/**
* Get SMTP extensions available on the server
* Get SMTP extensions available on the server.
*
* @return array|null
*/
@ -1002,21 +1029,17 @@ class SMTP
}
/**
* A multipurpose method
* The method works in three ways, dependent on argument value and current state
* 1. HELO/EHLO was not sent - returns null and set up $this->error
* 2. HELO was sent
* $name = 'HELO': returns server name
* $name = 'EHLO': returns boolean false
* $name = any string: returns null and set up $this->error
* 3. EHLO was sent
* $name = 'HELO'|'EHLO': returns server name
* $name = any string: if extension $name exists, returns boolean True
* or its options. Otherwise returns boolean False
* In other words, one can use this method to detect 3 conditions:
* - null returned: handshake was not or we don't know about ext (refer to $this->error)
* - false returned: the requested feature exactly not exists
* - positive value returned: the requested feature exists
* Get metadata about the SMTP server from its HELO/EHLO response.
* The method works in three ways, dependent on argument value and current state:
* 1. HELO/EHLO has not been sent - returns null and populates $this->error.
* 2. HELO has been sent -
* $name == 'HELO': returns server name
* $name == 'EHLO': returns boolean false
* $name == any other string: returns null and populates $this->error
* 3. EHLO has been sent -
* $name == 'HELO'|'EHLO': returns the server name
* $name == any other string: if extension $name exists, returns True
* or its options (e.g. AUTH mechanisms supported). Otherwise returns False.
*
* @param string $name Name of SMTP extension or 'HELO'|'EHLO'
*
@ -1026,10 +1049,10 @@ class SMTP
{
if (!$this->server_caps) {
$this->setError('No HELO/EHLO was sent');
return null;
return;
}
// the tight logic knot ;)
if (!array_key_exists($name, $this->server_caps)) {
if ('HELO' == $name) {
return $this->server_caps['EHLO'];
@ -1037,8 +1060,9 @@ class SMTP
if ('EHLO' == $name || array_key_exists('EHLO', $this->server_caps)) {
return false;
}
$this->setError('HELO handshake was used. Client knows nothing about server extensions');
return null;
$this->setError('HELO handshake was used; No information about server extensions available');
return;
}
return $this->server_caps[$name];
@ -1115,6 +1139,7 @@ class SMTP
break;
}
}
return $data;
}
@ -1141,9 +1166,9 @@ class SMTP
/**
* Set error messages and codes.
*
* @param string $message The error message
* @param string $detail Further detail on the error
* @param string $smtp_code An associated SMTP error code
* @param string $message The error message
* @param string $detail Further detail on the error
* @param string $smtp_code An associated SMTP error code
* @param string $smtp_code_ex Extended SMTP code
*/
protected function setError($message, $detail = '', $smtp_code = '', $smtp_code_ex = '')
@ -1152,7 +1177,7 @@ class SMTP
'error' => $message,
'detail' => $detail,
'smtp_code' => $smtp_code,
'smtp_code_ex' => $smtp_code_ex
'smtp_code_ex' => $smtp_code_ex,
];
}
@ -1199,7 +1224,7 @@ class SMTP
/**
* Set SMTP timeout.
*
* @param int $timeout
* @param int $timeout The timeout duration in seconds
*/
public function setTimeout($timeout = 0)
{
@ -1219,10 +1244,10 @@ class SMTP
/**
* Reports an error number and string.
*
* @param int $errno The error number returned by PHP
* @param string $errmsg The error message returned by PHP
* @param int $errno The error number returned by PHP
* @param string $errmsg The error message returned by PHP
* @param string $errfile The file the error occurred in
* @param int $errline The line number the error occurred on
* @param int $errline The line number the error occurred on
*/
protected function errorHandler($errno, $errmsg, $errfile = '', $errline = 0)
{
@ -1230,7 +1255,7 @@ class SMTP
$this->setError(
$notice,
$errmsg,
(string)$errno
(string) $errno
);
$this->edebug(
"$notice Error #$errno: $errmsg [$errfile line $errline]",
@ -1244,6 +1269,7 @@ class SMTP
* Relies on the host providing the ID in response to a DATA command.
* If no reply has been received yet, it will return null.
* If no pattern was matched, it will return false.
*
* @return bool|null|string
*/
protected function recordLastTransactionID()
@ -1268,7 +1294,9 @@ class SMTP
* Get the queue/transaction ID of the last SMTP transaction
* If no reply has been received yet, it will return null.
* If no pattern was matched, it will return false.
*
* @return bool|null|string
*
* @see recordLastTransactionID()
*/
public function getLastTransactionID()

View File

@ -1,6 +1,6 @@
<?php
/**
* PHPUnit bootstrap file
* PHPUnit bootstrap file.
*/
ini_set('sendmail_path', '/usr/sbin/sendmail -t -i ');
if (file_exists('vendor/autoload.php')) {

View File

@ -1,13 +1,12 @@
<?php
/**
* PHPMailer - language file tests
* PHPMailer - language file tests.
*
* PHP version 5.5
* PHP version 5.5.
*
* @package PHPMailer
* @author Marcus Bointon <phpmailer@synchromedia.co.uk>
* @author Andy Prevost
* @copyright 2010 - 2016 Marcus Bointon
* @copyright 2010 - 2017 Marcus Bointon
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
@ -15,8 +14,7 @@
namespace PHPMailer\PHPMailer;
/**
* PHPMailer - PHP email transport unit test class
* Performs authentication tests
* Check language files for missing or excess translations.
*/
class PHPMailerLangTest extends \PHPUnit_Framework_TestCase
{
@ -28,7 +26,7 @@ class PHPMailerLangTest extends \PHPUnit_Framework_TestCase
public $Mail;
/**
* Default include path
* Default include path.
*
* @var string
*/
@ -39,12 +37,12 @@ class PHPMailerLangTest extends \PHPUnit_Framework_TestCase
*/
public function setUp()
{
$this->Mail = new PHPMailer;
$this->Mail = new PHPMailer();
}
/**
* Test language files for missing and excess translations
* All languages are compared with English
* Test language files for missing and excess translations.
* All languages are compared with English.
*
* @group languages
*/

View File

@ -1,13 +1,11 @@
<?php
/**
* PHPMailer - PHP email transport unit tests.
* PHP version 5.5.
*
* PHP version 5.5
*
* @package PHPMailer
* @author Marcus Bointon <phpmailer@synchromedia.co.uk>
* @author Andy Prevost
* @copyright 2012 - 2016 Marcus Bointon
* @copyright 2012 - 2017 Marcus Bointon
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
@ -20,7 +18,7 @@ namespace PHPMailer\PHPMailer;
class PHPMailerTest extends \PHPUnit_Framework_TestCase
{
/**
* Holds the phpmailer instance.
* Holds the PHPMailer instance.
*
* @var PHPMailer
*/
@ -48,14 +46,14 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
public $NoteLog = [];
/**
* Default include path
* Default include path.
*
* @var string
*/
public $INCLUDE_DIR = '..';
/**
* PIDs of any processes we need to kill
* PIDs of any processes we need to kill.
*
* @var array
*/
@ -70,7 +68,7 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
if (file_exists($this->INCLUDE_DIR . '/test/testbootstrap.php')) {
include $this->INCLUDE_DIR . '/test/testbootstrap.php'; //Overrides go in here
}
$this->Mail = new PHPMailer;
$this->Mail = new PHPMailer();
$this->Mail->SMTPDebug = 3; //Full debug output
$this->Mail->Priority = 3;
$this->Mail->Encoding = '8bit';
@ -186,7 +184,7 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
$ReportBody .= '-------' . $eol;
$ReportBody .= $list_start;
for ($i = 0; $i < count($this->ChangeLog); $i++) {
for ($i = 0; $i < count($this->ChangeLog); ++$i) {
$ReportBody .= $bullet_start . $this->ChangeLog[$i][0] . ' was changed to [' .
$this->ChangeLog[$i][1] . ']' . $bullet_end;
}
@ -199,7 +197,7 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
$ReportBody .= '-----' . $eol;
$ReportBody .= $list_start;
for ($i = 0; $i < count($this->NoteLog); $i++) {
for ($i = 0; $i < count($this->NoteLog); ++$i) {
$ReportBody .= $bullet_start . $this->NoteLog[$i] . $bullet_end;
}
$ReportBody .= $list_end;
@ -265,7 +263,7 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
}
/**
* Adds all of the addresses
* Adds all of the addresses.
*
* @param string $sAddress
* @param string $sName
@ -283,6 +281,7 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
case 'bcc':
return $this->Mail->addBCC($sAddress, $sName);
}
return false;
}
@ -292,15 +291,15 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
*/
public function testBootstrap()
{
$this->assertTrue(
file_exists($this->INCLUDE_DIR . '/test/testbootstrap.php'),
$this->assertFileExists(
$this->INCLUDE_DIR . '/test/testbootstrap.php',
'Test config params missing - copy testbootstrap.php to testbootstrap-dist.php and change as appropriate'
);
}
/**
* Test CRAM-MD5 authentication.
* Needs a connection to a server that supports this auth mechanism, so commented out by default
* Needs a connection to a server that supports this auth mechanism, so commented out by default.
*/
public function testAuthCRAMMD5()
{
@ -399,7 +398,7 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
'cdburgess+!#$%&\'*-/=?+_{}|~test@example.com',
'test@test.com',
'test@xn--example.com',
'test@example.com'
'test@example.com',
];
//These are invalid according to PHP's filter_var
//which doesn't allow dotless domains, numeric TLDs or unbracketed IPv4 literals
@ -474,7 +473,7 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
'first.last@sub.do,com',
'first\@last@iana.org',
'123456789012345678901234567890123456789012345678901234567890' .
'@12345678901234567890123456789012345678901234 [...]',
'@12345678901234567890123456789012345678901234 [...]',
'first.last',
'12345678901234567890123456789012345678901234567890123456789012345@iana.org',
'.first.last@iana.org',
@ -487,7 +486,7 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
'first\@last@iana.org',
'first.last@',
'x@x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.' .
'x23456789.x23456789.x23456789.x23 [...]',
'x23456789.x23456789.x23456789.x23 [...]',
'first.last@[.12.34.56.78]',
'first.last@[12.34.56.789]',
'first.last@[::12.34.56.78]',
@ -534,7 +533,7 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
'test@example.',
'test@.org',
'test@12345678901234567890123456789012345678901234567890123456789012345678901234567890' .
'12345678901234567890 [...]',
'12345678901234567890 [...]',
'test@[123.123.123.123',
'test@123.123.123.123]',
'NotAnEmail',
@ -559,10 +558,10 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
'cal(foo)bar)@iamcal.com',
'cal(foo\)@iamcal.com',
'first(12345678901234567890123456789012345678901234567890)last@(1234567890123456789' .
'01234567890123456789012 [...]',
'01234567890123456789012 [...]',
'first(middle)last@iana.org',
'first(abc("def".ghi).mno)middle(abc("def".ghi).mno).last@(abc("def".ghi).mno)example' .
'(abc("def".ghi).mno). [...]',
'(abc("def".ghi).mno). [...]',
'a(a(b(c)d(e(f))g)(h(i)j)@iana.org',
'.@',
'@bar.com',
@ -609,9 +608,9 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
'first.last@[IPv6:a1:a2:a3:a4:b1:b2:b3:]',
'first.last@[IPv6::a2:a3:a4:b1:b2:b3:b4]',
'first.last@[IPv6:a1:a2:a3:a4::b1:b2:b3:b4]',
//This is a valid RCC5322 address, but we don't want to allow it for obvious reasons!
//This is a valid RFC5322 address, but we don't want to allow it for obvious reasons!
"(\r\n RCPT TO:user@example.com\r\n DATA \\\nSubject: spam10\\\n\r\n Hello," .
"\r\n this is a spam mail.\\\n.\r\n QUIT\r\n ) a@example.net"
"\r\n this is a spam mail.\\\n.\r\n QUIT\r\n ) a@example.net",
];
// IDNs in Unicode and ASCII forms.
$unicodeaddresses = [
@ -672,7 +671,7 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
PHPMailer::validateAddress(
'user@example.com',
function ($address) {
return (strpos($address, '@') !== false);
return strpos($address, '@') !== false;
}
),
'Custom validator false negative'
@ -681,29 +680,29 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
PHPMailer::validateAddress(
'userexample.com',
function ($address) {
return (strpos($address, '@') !== false);
return strpos($address, '@') !== false;
}
),
'Custom validator false positive'
);
//Set the default validator to an injected function
PHPMailer::$validator = function ($address) {
return ('user@example.com' === $address);
return 'user@example.com' === $address;
};
$this->assertTrue(
$this->Mail->addAddress('user@example.com'),
'Custom default validator false negative'
);
$this->assertFalse(
//Need to pick a failing value which would pass all other validators
//to be sure we're using our custom one
//Need to pick a failing value which would pass all other validators
//to be sure we're using our custom one
$this->Mail->addAddress('bananas@example.com'),
'Custom default validator false positive'
);
//Set default validator to PHP built-in
PHPMailer::$validator = 'php';
$this->assertFalse(
//This is a valid address that FILTER_VALIDATE_EMAIL thinks is invalid
//This is a valid address that FILTER_VALIDATE_EMAIL thinks is invalid
$this->Mail->addAddress('first.last@example.123'),
'PHP validator not behaving as expected'
);
@ -778,11 +777,13 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
if (!$this->Mail->addAttachment(realpath($this->INCLUDE_DIR . '/examples/images/phpmailer.png'))) {
$this->assertTrue(false, $this->Mail->ErrorInfo);
return;
}
if (!$this->Mail->addAttachment(__FILE__, 'test.txt')) {
$this->assertTrue(false, $this->Mail->ErrorInfo);
return;
}
@ -858,7 +859,7 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
$noencode = 'eeeeeeeeee';
$this->Mail->isMail();
//Expected results
$bencoderes = '=?UTF-8?B?w6nDqcOpw6nDqcOpw6nDqcOpw6nDqcOpw6nDqcOpw6nDqcOpw6nDqcOpw6k=?='.PHPMailer::getLE().
$bencoderes = '=?UTF-8?B?w6nDqcOpw6nDqcOpw6nDqcOpw6nDqcOpw6nDqcOpw6nDqcOpw6nDqcOpw6k=?=' . PHPMailer::getLE() .
' =?UTF-8?B?w6nDqcOpw6nDqcOpw6nDqcOpw6nDqcOpw6nDqcOpw6nDqcOpw6nDqcOpw6k=?=' . PHPMailer::getLE() .
' =?UTF-8?B?w6nDqcOpw6nDqcOpw6nDqcOpw6nDqcOpw6nDqcOpw6nDqcOpw6nDqcOpw6k=?=' . PHPMailer::getLE() .
' =?UTF-8?B?w6nDqcOpw6nDqcOpw6nDqcOpw6nDqcOpw6k=?=';
@ -866,7 +867,7 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
' =?UTF-8?Q?eeeeeeeeeeeeeeeeeeeeeeeeee=C3=A9?=';
$bencodenofoldres = '=?UTF-8?B?w6nDqcOpw6nDqcOpw6nDqcOpw6k=?=';
$qencodenofoldres = '=?UTF-8?Q?eeeeeeeee=C3=A9?=';
$justfoldres = 'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'.
$justfoldres = 'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' .
'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' . PHPMailer::getLE() . ' eeeeeeeeee';
$noencoderes = 'eeeeeeeeee';
$this->assertEquals(
@ -907,9 +908,9 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
public function testHtml()
{
$this->Mail->isHTML(true);
$this->Mail->Subject .= ": HTML only";
$this->Mail->Subject .= ': HTML only';
$this->Mail->Body = <<<EOT
$this->Mail->Body = <<<'EOT'
<html>
<head>
<title>HTML email test</title>
@ -935,7 +936,7 @@ EOT;
public function testHtmlIso8859()
{
$this->Mail->isHTML(true);
$this->Mail->Subject .= ": ISO-8859-1 HTML";
$this->Mail->Subject .= ': ISO-8859-1 HTML';
$this->Mail->CharSet = 'iso-8859-1';
//This file is in ISO-8859-1 charset
@ -947,8 +948,8 @@ EOT;
$this->Mail->msgHTML(
mb_convert_encoding(
$content,
"ISO-8859-1",
mb_detect_encoding($content, "UTF-8, ISO-8859-1, ISO-8859-15", true)
'ISO-8859-1',
mb_detect_encoding($content, 'UTF-8, ISO-8859-1, ISO-8859-15', true)
),
realpath($this->INCLUDE_DIR . '/examples')
);
@ -966,10 +967,10 @@ EOT;
public function testHtmlUtf8()
{
$this->Mail->isHTML(true);
$this->Mail->Subject .= ": UTF-8 HTML Пустое тело сообщения";
$this->Mail->Subject .= ': UTF-8 HTML Пустое тело сообщения';
$this->Mail->CharSet = 'UTF-8';
$this->Mail->Body = <<<EOT
$this->Mail->Body = <<<'EOT'
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
@ -995,10 +996,10 @@ EOT;
public function testUtf8WithEmbeddedImage()
{
$this->Mail->isHTML(true);
$this->Mail->Subject .= ": UTF-8 with embedded image";
$this->Mail->Subject .= ': UTF-8 with embedded image';
$this->Mail->CharSet = 'UTF-8';
$this->Mail->Body = <<<EOT
$this->Mail->Body = <<<'EOT'
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
@ -1030,10 +1031,10 @@ EOT;
public function testPlainUtf8()
{
$this->Mail->isHTML(false);
$this->Mail->Subject .= ": UTF-8 plain text";
$this->Mail->Subject .= ': UTF-8 plain text';
$this->Mail->CharSet = 'UTF-8';
$this->Mail->Body = <<<EOT
$this->Mail->Body = <<<'EOT'
Chinese text: 郵件內容為空
Russian text: Пустое тело сообщения
Armenian text: Հաղորդագրությունը դատարկ է
@ -1046,7 +1047,7 @@ EOT;
}
/**
* Test simple message builder and html2text converters
* Test simple message builder and html2text converters.
*/
public function testMsgHTML()
{
@ -1067,7 +1068,7 @@ EOT;
$this->Mail->AltBody = '';
$this->Mail->msgHTML(
$message,
realpath($this->INCLUDE_DIR .'/examples'),
realpath($this->INCLUDE_DIR . '/examples'),
function ($html) {
return strtoupper(strip_tags($html));
}
@ -1092,7 +1093,10 @@ EOT;
//Test that absolute URLs are ignored
$this->Mail->msgHTML('<img src="https://github.com/PHPMailer/PHPMailer/blob/master/composer.json">test');
$this->assertTrue(
strpos($this->Mail->Body, 'src="https://github.com/PHPMailer/PHPMailer/blob/master/composer.json"') !== false
strpos(
$this->Mail->Body,
'src="https://github.com/PHPMailer/PHPMailer/blob/master/composer.json"'
) !== false
);
//Test that absolute URLs with anonymous/relative protocol are ignored
//Note that such URLs will not work in email anyway because they have no protocol to be relative to
@ -1106,7 +1110,7 @@ EOT;
}
/**
* Simple HTML and attachment test
* Simple HTML and attachment test.
*/
public function testHTMLAttachment()
{
@ -1121,6 +1125,7 @@ EOT;
)
) {
$this->assertTrue(false, $this->Mail->ErrorInfo);
return;
}
@ -1132,7 +1137,7 @@ EOT;
}
/**
* Test embedded image without a name
* Test embedded image without a name.
*/
public function testHTMLStringEmbedNoName()
{
@ -1142,13 +1147,14 @@ EOT;
if (!$this->Mail->addStringEmbeddedImage(
file_get_contents(realpath($this->INCLUDE_DIR . '/examples/images/phpmailer_mini.png')),
hash('sha256', 'phpmailer_mini.png').'@phpmailer.0',
hash('sha256', 'phpmailer_mini.png') . '@phpmailer.0',
'', //Intentionally empty name
'base64',
'', //Intentionally empty MIME type
'inline'
)) {
$this->assertTrue(false, $this->Mail->ErrorInfo);
return;
}
@ -1157,7 +1163,7 @@ EOT;
}
/**
* Simple HTML and multiple attachment test
* Simple HTML and multiple attachment test.
*/
public function testHTMLMultiAttachment()
{
@ -1171,6 +1177,7 @@ EOT;
)
) {
$this->assertTrue(false, $this->Mail->ErrorInfo);
return;
}
@ -1180,6 +1187,7 @@ EOT;
)
) {
$this->assertTrue(false, $this->Mail->ErrorInfo);
return;
}
@ -1207,6 +1215,7 @@ EOT;
)
) {
$this->assertTrue(false, $this->Mail->ErrorInfo);
return;
}
@ -1237,11 +1246,13 @@ EOT;
)
) {
$this->assertTrue(false, $this->Mail->ErrorInfo);
return;
}
if (!$this->Mail->addAttachment(__FILE__, 'test.txt')) {
$this->assertTrue(false, $this->Mail->ErrorInfo);
return;
}
@ -1255,11 +1266,11 @@ EOT;
public function testAltBody()
{
$this->Mail->Body = 'This is the <strong>HTML</strong> part of the email.';
$this->Mail->AltBody = 'Here is the text body of this message. ' .
'It should be quite a few lines. It should be wrapped at the ' .
$this->Mail->AltBody = 'Here is the plain text body of this message. ' .
'It should be quite a few lines. It should be wrapped at ' .
'40 characters. Make sure that it is.';
$this->Mail->WordWrap = 40;
$this->addNote('This is a mulipart alternative email');
$this->addNote('This is a multipart/alternative email');
$this->Mail->Subject .= ': AltBody + Word Wrap';
$this->buildBody();
@ -1267,7 +1278,7 @@ EOT;
}
/**
* Simple HTML and attachment test
* Simple HTML and attachment test.
*/
public function testAltBodyAttachment()
{
@ -1278,6 +1289,7 @@ EOT;
if (!$this->Mail->addAttachment(__FILE__, 'test_attach.txt')) {
$this->assertTrue(false, $this->Mail->ErrorInfo);
return;
}
@ -1379,7 +1391,7 @@ EOT;
//Use +2 to ensure line length is over limit - LE may only be 1 char
$badlen = str_repeat(str_repeat('1', PHPMailer::MAX_LINE_LENGTH + 2) . PHPMailer::getLE(), 2);
$this->Mail->Body = "This message contains lines that are too long.".
$this->Mail->Body = 'This message contains lines that are too long.' .
PHPMailer::getLE() . $oklen . $badlen . $oklen;
$this->assertTrue(
PHPMailer::hasLineLongerThanMax($this->Mail->Body),
@ -1393,7 +1405,7 @@ EOT;
$message = $this->Mail->getSentMIMEMessage();
$this->assertFalse(
PHPMailer::hasLineLongerThanMax($message),
'Long line not corrected (Max: '.(PHPMailer::MAX_LINE_LENGTH + strlen(PHPMailer::getLE())). ' chars)'
'Long line not corrected (Max: ' . (PHPMailer::MAX_LINE_LENGTH + strlen(PHPMailer::getLE())) . ' chars)'
);
$this->assertContains(
'Content-Transfer-Encoding: quoted-printable',
@ -1409,7 +1421,7 @@ EOT;
{
$oklen = str_repeat(str_repeat('0', PHPMailer::MAX_LINE_LENGTH) . PHPMailer::getLE(), 10);
$this->Mail->Body = "This message does not contain lines that are too long.".
$this->Mail->Body = 'This message does not contain lines that are too long.' .
PHPMailer::getLE() . $oklen;
$this->assertFalse(
PHPMailer::hasLineLongerThanMax($this->Mail->Body),
@ -1446,7 +1458,7 @@ EOT;
}
/**
* Tests this denial of service attack:
* Test this denial of service attack.
*
* @see http://www.cybsec.com/vuln/PHPMailer-DOS.pdf
*/
@ -1460,7 +1472,7 @@ EOT;
}
/**
* Tests this denial of service attack:
* Tests this denial of service attack.
*
* @see https://sourceforge.net/p/phpmailer/bugs/383/
* According to the ticket, this should get stuck in a loop, though I can't make it happen.
@ -1534,15 +1546,15 @@ EOT;
'Failed to recognise address list (IMAP parser)'
);
$this->assertEquals(
array(
array("name" => 'Joe User', 'address' => 'joe@example.com'),
array("name" => 'Jill User', 'address' => 'jill@example.net'),
array("name" => '', 'address' => 'frank@example.com'),
),
[
['name' => 'Joe User', 'address' => 'joe@example.com'],
['name' => 'Jill User', 'address' => 'jill@example.net'],
['name' => '', 'address' => 'frank@example.com'],
],
$this->Mail->parseAddresses(
'Joe User <joe@example.com>,'
. 'Jill User <jill@example.net>,'
. 'frank@example.com,'
. 'Jill User <jill@example.net>,'
. 'frank@example.com,'
),
'Parsed addresses'
);
@ -1643,8 +1655,8 @@ EOT;
$this->buildBody();
$this->Mail->preSend();
$this->assertRegExp(
"/Content-Transfer-Encoding: 8bit\r\n\r\n".
"This is a multi-part message in MIME format./",
"/Content-Transfer-Encoding: 8bit\r\n\r\n" .
'This is a multi-part message in MIME format./',
$this->Mail->getSentMIMEMessage(),
'MIME structure broken'
);
@ -1712,6 +1724,7 @@ EOT;
$this->buildBody();
$this->assertTrue($this->Mail->send(), 'Base64 encoding failed');
}
/**
* S/MIME Signing tests (self-signed).
*
@ -1730,12 +1743,12 @@ EOT;
'organizationName' => 'PHP',
'organizationalUnitName' => 'PHPMailer',
'commonName' => 'PHPMailer Test',
'emailAddress' => 'phpmailer@example.com'
'emailAddress' => 'phpmailer@example.com',
];
$keyconfig = [
"digest_alg" => "sha256",
"private_key_bits" => 2048,
"private_key_type" => OPENSSL_KEYTYPE_RSA,
'digest_alg' => 'sha256',
'private_key_bits' => 2048,
'private_key_type' => OPENSSL_KEYTYPE_RSA,
];
$password = 'password';
$certfile = 'certfile.pem';
@ -1771,7 +1784,7 @@ EOT;
* S/MIME Signing tests using a CA chain cert.
* To test that a generated message is signed correctly, save the message in a file called `signed.eml`
* and use openssl along with the certs generated by this script:
* `openssl smime -verify -in signed.eml -signer certfile.pem -CAfile cacertfile.pem`
* `openssl smime -verify -in signed.eml -signer certfile.pem -CAfile cacertfile.pem`.
*
* @requires extension openssl
*/
@ -1788,7 +1801,7 @@ EOT;
'organizationName' => 'PHP',
'organizationalUnitName' => 'PHPMailer',
'commonName' => 'PHPMailer Test',
'emailAddress' => 'phpmailer@example.com'
'emailAddress' => 'phpmailer@example.com',
];
$cacertprops = [
'countryName' => 'UK',
@ -1797,7 +1810,7 @@ EOT;
'organizationName' => 'PHP',
'organizationalUnitName' => 'PHPMailer CA',
'commonName' => 'PHPMailer Test CA',
'emailAddress' => 'phpmailer@example.com'
'emailAddress' => 'phpmailer@example.com',
];
$keyconfig = [
'digest_alg' => 'sha256',
@ -1905,7 +1918,7 @@ EOT;
$pk = openssl_pkey_new(
[
'private_key_bits' => 2048,
'private_key_type' => OPENSSL_KEYTYPE_RSA
'private_key_type' => OPENSSL_KEYTYPE_RSA,
]
);
openssl_pkey_export_to_file($pk, $privatekeyfile);
@ -1952,11 +1965,11 @@ EOT;
}
/**
* Test line length detection
* Test line length detection.
*/
public function testLineLength()
{
$oklen = str_repeat(str_repeat('0', PHPMailer::MAX_LINE_LENGTH)."\r\n", 2);
$oklen = str_repeat(str_repeat('0', PHPMailer::MAX_LINE_LENGTH) . "\r\n", 2);
$badlen = str_repeat(str_repeat('1', PHPMailer::MAX_LINE_LENGTH + 1) . "\r\n", 2);
$this->assertTrue(PHPMailer::hasLineLongerThanMax($badlen), 'Long line not detected (only)');
$this->assertTrue(PHPMailer::hasLineLongerThanMax($oklen . $badlen), 'Long line not detected (first)');
@ -1967,7 +1980,7 @@ EOT;
);
$this->assertFalse(PHPMailer::hasLineLongerThanMax($oklen), 'Long line false positive');
$this->Mail->isHTML(false);
$this->Mail->Subject .= ": Line length test";
$this->Mail->Subject .= ': Line length test';
$this->Mail->CharSet = 'UTF-8';
$this->Mail->Encoding = '8bit';
$this->Mail->Body = $oklen . $badlen . $oklen . $badlen;
@ -1988,7 +2001,7 @@ EOT;
$this->Mail->preSend();
$lastid = $this->Mail->getLastMessageID();
$this->assertNotEquals($lastid, $id, 'Invalid Message ID allowed');
$id = '<'. hash('sha256', 12345).'@example.com>';
$id = '<' . hash('sha256', 12345) . '@example.com>';
$this->Mail->MessageID = $id;
$this->buildBody();
$this->Mail->preSend();
@ -2086,13 +2099,13 @@ EOT;
'127.0.0.1',
trim(str_repeat('a0123456789.', 21), '.'),
'[::1]',
'[0:1234:dc0:41:216:3eff:fe67:3e01]'
'[0:1234:dc0:41:216:3eff:fe67:3e01]',
];
$bad = [
null,
123,
1.5,
new \stdClass,
new \stdClass(),
[],
'',
'999.0.0.0',
@ -2100,17 +2113,18 @@ EOT;
'[1234:::1]',
trim(str_repeat('a0123456789.', 22), '.'),
'0:1234:dc0:41:216:3eff:fe67:3e01',
'[012q:1234:dc0:41:216:3eff:fe67:3e01]'
'[012q:1234:dc0:41:216:3eff:fe67:3e01]',
];
foreach ($good as $h) {
$this->assertTrue(PHPMailer::isValidHost($h), 'Good hostname denied: '.$h);
$this->assertTrue(PHPMailer::isValidHost($h), 'Good hostname denied: ' . $h);
}
foreach ($bad as $h) {
$this->assertFalse(PHPMailer::isValidHost($h), 'Bad hostname accepted: ' . var_export($h, true));
}
}
/**
* Tests the Custom header getter
* Tests the Custom header getter.
*/
public function testCustomHeaderGetter()
{
@ -2121,7 +2135,7 @@ EOT;
$this->assertEquals(
[
['foo', 'bar'],
['foo', 'baz']
['foo', 'baz'],
],
$this->Mail->getCustomHeaders()
);
@ -2136,7 +2150,7 @@ EOT;
$this->assertEquals(
[
['yux'],
['Content-Type', ' application/json']
['Content-Type', ' application/json'],
],
$this->Mail->getCustomHeaders()
);
@ -2272,8 +2286,7 @@ EOT;
}
/**
* Use a fake POP3 server to test POP-before-SMTP auth.
* With a known-good login
* Use a fake POP3 server to test POP-before-SMTP auth with a known-good login.
*
* @group pop3
*/
@ -2328,7 +2341,7 @@ EOT;
/**
* Test SMTP host connections.
* This test can take a long time, so run it last
* This test can take a long time, so run it last.
*
* @group slow
*/
@ -2337,14 +2350,14 @@ EOT;
$this->Mail->SMTPDebug = 4; //Show connection-level errors
$this->assertTrue($this->Mail->smtpConnect(), 'SMTP single connect failed');
$this->Mail->smtpClose();
$this->Mail->Host = "localhost:12345;10.10.10.10:54321;" . $_REQUEST['mail_host'];
$this->Mail->Host = 'localhost:12345;10.10.10.10:54321;' . $_REQUEST['mail_host'];
$this->assertTrue($this->Mail->smtpConnect(), 'SMTP multi-connect failed');
$this->Mail->smtpClose();
$this->Mail->Host = "[::1]:" . $this->Mail->Port . ';' . $_REQUEST['mail_host'];
$this->Mail->Host = '[::1]:' . $this->Mail->Port . ';' . $_REQUEST['mail_host'];
$this->assertTrue($this->Mail->smtpConnect(), 'SMTP IPv6 literal multi-connect failed');
$this->Mail->smtpClose();
//All these hosts are expected to fail
$this->Mail->Host = "xyz://bogus:25;tls://[bogus]:25;ssl://localhost:12345;tls://localhost:587;10.10.10.10:54321;localhost:12345;10.10.10.10";
$this->Mail->Host = 'xyz://bogus:25;tls://[bogus]:25;ssl://localhost:12345;tls://localhost:587;10.10.10.10:54321;localhost:12345;10.10.10.10';
$this->assertFalse($this->Mail->smtpConnect(), 'SMTP bad multi-connect succeeded');
$this->Mail->smtpClose();
$this->Mail->Host = ' localhost:12345 ; ' . $_REQUEST['mail_host'] . ' ';
@ -2359,7 +2372,7 @@ EOT;
}
}
/**
/*
* This is a sample form for setting appropriate test values through a browser
* These values can also be set using a file called testbootstrap.php (not in repo) in the same folder as this script
* which is probably more useful if you run these tests a lot

View File

@ -1,4 +1,5 @@
<?php
$_REQUEST['submitted'] = 1;
$_REQUEST['mail_to'] = 'somebody@example.com';
$_REQUEST['mail_from'] = 'phpunit@example.com';