Short array syntax

This commit is contained in:
Synchro 2015-11-10 13:45:13 +01:00
parent 9b3e13dc14
commit 14e8ef03eb
9 changed files with 188 additions and 172 deletions

View File

@ -36,12 +36,12 @@ $authenticate_username = (isset($_POST['authenticate_username'])) ?
$_POST['authenticate_username'] : $CFG['smtp_username']; $_POST['authenticate_username'] : $CFG['smtp_username'];
// storing all status output from the script to be shown to the user later // storing all status output from the script to be shown to the user later
$results_messages = array(); $results_messages = [];
// $example_code represents the "final code" that we're using, and will // $example_code represents the "final code" that we're using, and will
// be shown to the user at the end. // be shown to the user at the end.
$example_code = "\nrequire_once '../PHPMailerAutoload.php';"; $example_code = "\nrequire_once '../PHPMailerAutoload.php';";
$example_code .= "\n\n\$results_messages = array();"; $example_code .= "\n\n\$results_messages = [];";
$mail = new PHPMailer(true); //PHPMailer instance with exceptions enabled $mail = new PHPMailer(true); //PHPMailer instance with exceptions enabled
$mail->CharSet = 'utf-8'; $mail->CharSet = 'utf-8';

View File

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

View File

@ -27,13 +27,13 @@ $clientSecret = 'RANDOMCHARS-----lGyjPcRtvP';
//Set Redirect URI in Developer Console as [https/http]://<yourdomain>/<folder>/get_oauth_token.php //Set Redirect URI in Developer Console as [https/http]://<yourdomain>/<folder>/get_oauth_token.php
$provider = new League\OAuth2\Client\Provider\Google( $provider = new League\OAuth2\Client\Provider\Google(
array( [
'clientId' => $clientId, 'clientId' => $clientId,
'clientSecret' => $clientSecret, 'clientSecret' => $clientSecret,
'redirectUri' => $redirectUri, 'redirectUri' => $redirectUri,
'scopes' => array('https://mail.google.com/'), 'scopes' => ['https://mail.google.com/'],
'accessType' => 'offline' 'accessType' => 'offline'
) ]
); );
if (!isset($_GET['code'])) { if (!isset($_GET['code'])) {
@ -50,9 +50,9 @@ if (!isset($_GET['code'])) {
// Try to get an access token (using the authorization code grant) // Try to get an access token (using the authorization code grant)
$token = $provider->getAccessToken( $token = $provider->getAccessToken(
'authorization_code', 'authorization_code',
array( [
'code' => $_GET['code'] 'code' => $_GET['code']
) ]
); );
// Use this to get a new access token if the old one expires // Use this to get a new access token if the old one expires

View File

@ -254,7 +254,7 @@ class PHPMailer
* Options array passed to stream_context_create when connecting via SMTP. * Options array passed to stream_context_create when connecting via SMTP.
* @var array * @var array
*/ */
public $SMTPOptions = array(); public $SMTPOptions = [];
/** /**
* SMTP username. * SMTP username.
@ -346,7 +346,7 @@ class PHPMailer
* @var array * @var array
* @TODO This should really not be public * @TODO This should really not be public
*/ */
public $SingleToArray = array(); public $SingleToArray = [];
/** /**
* Whether to generate VERP addresses on send. * Whether to generate VERP addresses on send.
@ -443,28 +443,28 @@ class PHPMailer
* @var array * @var array
* @access protected * @access protected
*/ */
protected $to = array(); protected $to = [];
/** /**
* The array of 'cc' names and addresses. * The array of 'cc' names and addresses.
* @var array * @var array
* @access protected * @access protected
*/ */
protected $cc = array(); protected $cc = [];
/** /**
* The array of 'bcc' names and addresses. * The array of 'bcc' names and addresses.
* @var array * @var array
* @access protected * @access protected
*/ */
protected $bcc = array(); protected $bcc = [];
/** /**
* The array of reply-to names and addresses. * The array of reply-to names and addresses.
* @var array * @var array
* @access protected * @access protected
*/ */
protected $ReplyTo = array(); protected $ReplyTo = [];
/** /**
* An array of all kinds of addresses. * An array of all kinds of addresses.
@ -473,7 +473,7 @@ class PHPMailer
* @access protected * @access protected
* @see PHPMailer::$to @see PHPMailer::$cc @see PHPMailer::$bcc * @see PHPMailer::$to @see PHPMailer::$cc @see PHPMailer::$bcc
*/ */
protected $all_recipients = array(); protected $all_recipients = [];
/** /**
* An array of names and addresses queued for validation. * An array of names and addresses queued for validation.
@ -485,7 +485,7 @@ class PHPMailer
* @see PHPMailer::$to @see PHPMailer::$cc @see PHPMailer::$bcc * @see PHPMailer::$to @see PHPMailer::$cc @see PHPMailer::$bcc
* @see PHPMailer::$all_recipients * @see PHPMailer::$all_recipients
*/ */
protected $RecipientsQueue = array(); protected $RecipientsQueue = [];
/** /**
* An array of reply-to names and addresses queued for validation. * An array of reply-to names and addresses queued for validation.
@ -495,21 +495,21 @@ class PHPMailer
* @access protected * @access protected
* @see PHPMailer::$ReplyTo * @see PHPMailer::$ReplyTo
*/ */
protected $ReplyToQueue = array(); protected $ReplyToQueue = [];
/** /**
* The array of attachments. * The array of attachments.
* @var array * @var array
* @access protected * @access protected
*/ */
protected $attachment = array(); protected $attachment = [];
/** /**
* The array of custom headers. * The array of custom headers.
* @var array * @var array
* @access protected * @access protected
*/ */
protected $CustomHeader = array(); protected $CustomHeader = [];
/** /**
* The most recent Message-ID (including angular brackets). * The most recent Message-ID (including angular brackets).
@ -530,14 +530,14 @@ class PHPMailer
* @var array * @var array
* @access protected * @access protected
*/ */
protected $boundary = array(); protected $boundary = [];
/** /**
* The array of available languages. * The array of available languages.
* @var array * @var array
* @access protected * @access protected
*/ */
protected $language = array(); protected $language = [];
/** /**
* The number of errors encountered. * The number of errors encountered.
@ -682,7 +682,7 @@ class PHPMailer
return; return;
} }
//Avoid clash with built-in function names //Avoid clash with built-in function names
if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) { if (!in_array($this->Debugoutput, ['error_log', 'html', 'echo']) and is_callable($this->Debugoutput)) {
call_user_func($this->Debugoutput, $str, $this->SMTPDebug); call_user_func($this->Debugoutput, $str, $this->SMTPDebug);
return; return;
} }
@ -848,7 +848,7 @@ class PHPMailer
} }
return false; return false;
} }
$params = array($kind, $address, $name); $params = [$kind, $address, $name];
// Enqueue addresses with IDN until we know the PHPMailer::$CharSet. // Enqueue addresses with IDN until we know the PHPMailer::$CharSet.
if ($this->has8bitChars(substr($address, ++$pos)) and $this->idnSupported()) { if ($this->has8bitChars(substr($address, ++$pos)) and $this->idnSupported()) {
if ($kind != 'Reply-To') { if ($kind != 'Reply-To') {
@ -865,7 +865,7 @@ class PHPMailer
return false; return false;
} }
// Immediately add standard addresses without IDN. // Immediately add standard addresses without IDN.
return call_user_func_array(array($this, 'addAnAddress'), $params); return call_user_func_array([$this, 'addAnAddress'], $params);
} }
/** /**
@ -880,7 +880,7 @@ class PHPMailer
*/ */
protected function addAnAddress($kind, $address, $name = '') protected function addAnAddress($kind, $address, $name = '')
{ {
if (!in_array($kind, array('to', 'cc', 'bcc', 'Reply-To'))) { if (!in_array($kind, ['to', 'cc', 'bcc', 'Reply-To'])) {
$error_message = $this->lang('Invalid recipient kind: ') . $kind; $error_message = $this->lang('Invalid recipient kind: ') . $kind;
$this->setError($error_message); $this->setError($error_message);
$this->edebug($error_message); $this->edebug($error_message);
@ -900,13 +900,13 @@ class PHPMailer
} }
if ($kind != 'Reply-To') { if ($kind != 'Reply-To') {
if (!array_key_exists(strtolower($address), $this->all_recipients)) { if (!array_key_exists(strtolower($address), $this->all_recipients)) {
array_push($this->$kind, array($address, $name)); array_push($this->$kind, [$address, $name]);
$this->all_recipients[strtolower($address)] = true; $this->all_recipients[strtolower($address)] = true;
return true; return true;
} }
} else { } else {
if (!array_key_exists(strtolower($address), $this->ReplyTo)) { if (!array_key_exists(strtolower($address), $this->ReplyTo)) {
$this->ReplyTo[strtolower($address)] = array($address, $name); $this->ReplyTo[strtolower($address)] = [$address, $name];
return true; return true;
} }
} }
@ -925,17 +925,17 @@ class PHPMailer
*/ */
public function parseAddresses($addrstr, $useimap = true) public function parseAddresses($addrstr, $useimap = true)
{ {
$addresses = array(); $addresses = [];
if ($useimap and function_exists('imap_rfc822_parse_adrlist')) { if ($useimap and function_exists('imap_rfc822_parse_adrlist')) {
//Use this built-in parser if it's available //Use this built-in parser if it's available
$list = imap_rfc822_parse_adrlist($addrstr, ''); $list = imap_rfc822_parse_adrlist($addrstr, '');
foreach ($list as $address) { foreach ($list as $address) {
if ($address->host != '.SYNTAX-ERROR.') { if ($address->host != '.SYNTAX-ERROR.') {
if ($this->validateAddress($address->mailbox . '@' . $address->host)) { if ($this->validateAddress($address->mailbox . '@' . $address->host)) {
$addresses[] = array( $addresses[] = [
'name' => (property_exists($address, 'personal') ? $address->personal : ''), 'name' => (property_exists($address, 'personal') ? $address->personal : ''),
'address' => $address->mailbox . '@' . $address->host 'address' => $address->mailbox . '@' . $address->host
); ];
} }
} }
} }
@ -948,19 +948,19 @@ class PHPMailer
if (strpos($address, '<') === false) { if (strpos($address, '<') === false) {
//No separate name, just use the whole thing //No separate name, just use the whole thing
if ($this->validateAddress($address)) { if ($this->validateAddress($address)) {
$addresses[] = array( $addresses[] = [
'name' => '', 'name' => '',
'address' => $address 'address' => $address
); ];
} }
} else { } else {
list($name, $email) = explode('<', $address); list($name, $email) = explode('<', $address);
$email = trim(str_replace('>', '', $email)); $email = trim(str_replace('>', '', $email));
if ($this->validateAddress($email)) { if ($this->validateAddress($email)) {
$addresses[] = array( $addresses[] = [
'name' => trim(str_replace(array('"', "'"), '', $name)), 'name' => trim(str_replace(['"', "'"], '', $name)),
'address' => $email 'address' => $email
); ];
} }
} }
} }
@ -1185,14 +1185,14 @@ class PHPMailer
// Dequeue recipient and Reply-To addresses with IDN // Dequeue recipient and Reply-To addresses with IDN
foreach (array_merge($this->RecipientsQueue, $this->ReplyToQueue) as $params) { foreach (array_merge($this->RecipientsQueue, $this->ReplyToQueue) as $params) {
$params[1] = $this->punyencodeAddress($params[1]); $params[1] = $this->punyencodeAddress($params[1]);
call_user_func_array(array($this, 'addAnAddress'), $params); call_user_func_array([$this, 'addAnAddress'], $params);
} }
if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) { if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
throw new Exception($this->lang('provide_address'), self::STOP_CRITICAL); throw new Exception($this->lang('provide_address'), self::STOP_CRITICAL);
} }
// Validate From, Sender, and ConfirmReadingTo addresses // Validate From, Sender, and ConfirmReadingTo addresses
foreach (array('From', 'Sender', 'ConfirmReadingTo') as $address_kind) { foreach (['From', 'Sender', 'ConfirmReadingTo'] as $address_kind) {
$this->$address_kind = trim($this->$address_kind); $this->$address_kind = trim($this->$address_kind);
if (empty($this->$address_kind)) { if (empty($this->$address_kind)) {
continue; continue;
@ -1336,7 +1336,7 @@ class PHPMailer
$result = pclose($mail); $result = pclose($mail);
$this->doCallback( $this->doCallback(
($result == 0), ($result == 0),
array($toAddr), [$toAddr],
$this->cc, $this->cc,
$this->bcc, $this->bcc,
$this->Subject, $this->Subject,
@ -1381,7 +1381,7 @@ class PHPMailer
*/ */
protected function mailSend($header, $body) protected function mailSend($header, $body)
{ {
$toArr = array(); $toArr = [];
foreach ($this->to as $toaddr) { foreach ($this->to as $toaddr) {
$toArr[] = $this->addrFormat($toaddr); $toArr[] = $this->addrFormat($toaddr);
} }
@ -1400,7 +1400,7 @@ class PHPMailer
if ($this->SingleTo && count($toArr) > 1) { if ($this->SingleTo && count($toArr) > 1) {
foreach ($toArr as $toAddr) { foreach ($toArr as $toAddr) {
$result = $this->mailPassthru($toAddr, $this->Subject, $body, $header, $params); $result = $this->mailPassthru($toAddr, $this->Subject, $body, $header, $params);
$this->doCallback($result, array($toAddr), $this->cc, $this->bcc, $this->Subject, $body, $this->From); $this->doCallback($result, [$toAddr], $this->cc, $this->bcc, $this->Subject, $body, $this->From);
} }
} else { } else {
$result = $this->mailPassthru($to, $this->Subject, $body, $header, $params); $result = $this->mailPassthru($to, $this->Subject, $body, $header, $params);
@ -1442,7 +1442,7 @@ class PHPMailer
*/ */
protected function smtpSend($header, $body) protected function smtpSend($header, $body)
{ {
$bad_rcpt = array(); $bad_rcpt = [];
if (!$this->smtpConnect($this->SMTPOptions)) { if (!$this->smtpConnect($this->SMTPOptions)) {
throw new Exception($this->lang('smtp_connect_failed'), self::STOP_CRITICAL); throw new Exception($this->lang('smtp_connect_failed'), self::STOP_CRITICAL);
} }
@ -1457,16 +1457,16 @@ class PHPMailer
} }
// Attempt to send to all recipients // Attempt to send to all recipients
foreach (array($this->to, $this->cc, $this->bcc) as $togroup) { foreach ([$this->to, $this->cc, $this->bcc] as $togroup) {
foreach ($togroup as $to) { foreach ($togroup as $to) {
if (!$this->smtp->recipient($to[0])) { if (!$this->smtp->recipient($to[0])) {
$error = $this->smtp->getError(); $error = $this->smtp->getError();
$bad_rcpt[] = array('to' => $to[0], 'error' => $error['detail']); $bad_rcpt[] = ['to' => $to[0], 'error' => $error['detail']];
$isSent = false; $isSent = false;
} else { } else {
$isSent = true; $isSent = true;
} }
$this->doCallback($isSent, array($to[0]), array(), array(), $this->Subject, $body, $this->From); $this->doCallback($isSent, [$to[0]], [], [], $this->Subject, $body, $this->From);
} }
} }
@ -1504,7 +1504,7 @@ class PHPMailer
* @uses SMTP * @uses SMTP
* @access public * @access public
*/ */
public function smtpConnect($options = array()) public function smtpConnect($options = [])
{ {
if (is_null($this->smtp)) { if (is_null($this->smtp)) {
$this->smtp = $this->getSMTPInstance(); $this->smtp = $this->getSMTPInstance();
@ -1523,7 +1523,7 @@ class PHPMailer
$lastexception = null; $lastexception = null;
foreach ($hosts as $hostentry) { foreach ($hosts as $hostentry) {
$hostinfo = array(); $hostinfo = [];
if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) { if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) {
// Not a valid host entry // Not a valid host entry
continue; continue;
@ -1638,7 +1638,7 @@ class PHPMailer
public function setLanguage($langcode = 'en', $lang_path = '') public function setLanguage($langcode = 'en', $lang_path = '')
{ {
// Define full set of translatable strings in English // Define full set of translatable strings in English
$PHPMAILER_LANG = array( $PHPMAILER_LANG = [
'authenticate' => 'SMTP Error: Could not authenticate.', 'authenticate' => 'SMTP Error: Could not authenticate.',
'connect_host' => 'SMTP Error: Could not connect to SMTP host.', 'connect_host' => 'SMTP Error: Could not connect to SMTP host.',
'data_not_accepted' => 'SMTP Error: data not accepted.', 'data_not_accepted' => 'SMTP Error: data not accepted.',
@ -1658,7 +1658,7 @@ class PHPMailer
'smtp_error' => 'SMTP server error: ', 'smtp_error' => 'SMTP server error: ',
'variable_set' => 'Cannot set or reset variable: ', 'variable_set' => 'Cannot set or reset variable: ',
'extension_missing' => 'Extension missing: ' 'extension_missing' => 'Extension missing: '
); ];
if (empty($lang_path)) { if (empty($lang_path)) {
// Calculate an absolute path so it can work if CWD is not here // Calculate an absolute path so it can work if CWD is not here
$lang_path = dirname(__FILE__). DIRECTORY_SEPARATOR . 'language'. DIRECTORY_SEPARATOR; $lang_path = dirname(__FILE__). DIRECTORY_SEPARATOR . 'language'. DIRECTORY_SEPARATOR;
@ -1696,12 +1696,12 @@ class PHPMailer
* @param array $addr An array of recipient, * @param array $addr An array of recipient,
* where each recipient is a 2-element indexed array with element 0 containing an address * where each recipient is a 2-element indexed array with element 0 containing an address
* and element 1 containing a name, like: * and element 1 containing a name, like:
* array(array('joe@example.com', 'Joe User'), array('zoe@example.com', 'Zoe User')) * [['joe@example.com', 'Joe User'], ['zoe@example.com', 'Zoe User']]
* @return string * @return string
*/ */
public function addrAppend($type, $addr) public function addrAppend($type, $addr)
{ {
$addresses = array(); $addresses = [];
foreach ($addr as $address) { foreach ($addr as $address) {
$addresses[] = $this->addrFormat($address); $addresses[] = $this->addrFormat($address);
} }
@ -1712,7 +1712,7 @@ class PHPMailer
* Format an address for use in a message header. * Format an address for use in a message header.
* @access public * @access public
* @param array $addr A 2-element indexed array, element 0 containing an address, element 1 containing a name * @param array $addr A 2-element indexed array, element 0 containing an address, element 1 containing a name
* like array('joe@example.com', 'Joe User') * like ['joe@example.com', 'Joe User']
* @return string * @return string
*/ */
public function addrFormat($addr) public function addrFormat($addr)
@ -1931,7 +1931,7 @@ class PHPMailer
} }
} }
$result .= $this->addrAppend('From', array(array(trim($this->From), $this->FromName))); $result .= $this->addrAppend('From', [[trim($this->From), $this->FromName]]);
// sendmail and mail() extract Cc from the header before sending // sendmail and mail() extract Cc from the header before sending
if (count($this->cc) > 0) { if (count($this->cc) > 0) {
@ -2232,7 +2232,7 @@ class PHPMailer
$file, $file,
$signed, $signed,
'file://' . realpath($this->sign_cert_file), 'file://' . realpath($this->sign_cert_file),
array('file://' . realpath($this->sign_key_file), $this->sign_key_pass), ['file://' . realpath($this->sign_key_file), $this->sign_key_pass],
null null
); );
} else { } else {
@ -2240,7 +2240,7 @@ class PHPMailer
$file, $file,
$signed, $signed,
'file://' . realpath($this->sign_cert_file), 'file://' . realpath($this->sign_cert_file),
array('file://' . realpath($this->sign_key_file), $this->sign_key_pass), ['file://' . realpath($this->sign_key_file), $this->sign_key_pass],
null, null,
PKCS7_DETACHED, PKCS7_DETACHED,
$this->sign_extracerts_file $this->sign_extracerts_file
@ -2322,7 +2322,7 @@ class PHPMailer
*/ */
protected function setMessageType() protected function setMessageType()
{ {
$type = array(); $type = [];
if ($this->alternativeExists()) { if ($this->alternativeExists()) {
$type[] = 'alt'; $type[] = 'alt';
} }
@ -2389,7 +2389,7 @@ class PHPMailer
$name = $filename; $name = $filename;
} }
$this->attachment[] = array( $this->attachment[] = [
0 => $path, 0 => $path,
1 => $filename, 1 => $filename,
2 => $name, 2 => $name,
@ -2398,7 +2398,7 @@ class PHPMailer
5 => false, // isStringAttachment 5 => false, // isStringAttachment
6 => $disposition, 6 => $disposition,
7 => 0 7 => 0
); ];
} catch (Exception $exc) { } catch (Exception $exc) {
$this->setError($exc->getMessage()); $this->setError($exc->getMessage());
@ -2431,9 +2431,9 @@ class PHPMailer
protected function attachAll($disposition_type, $boundary) protected function attachAll($disposition_type, $boundary)
{ {
// Return text of body // Return text of body
$mime = array(); $mime = [];
$cidUniq = array(); $cidUniq = [];
$incl = array(); $incl = [];
// Add all attachments // Add all attachments
foreach ($this->attachment as $attachment) { foreach ($this->attachment as $attachment) {
@ -2755,8 +2755,8 @@ class PHPMailer
} }
// Fall back to a pure PHP implementation // Fall back to a pure PHP implementation
$string = str_replace( $string = str_replace(
array('%20', '%0D%0A.', '%0D%0A', '%'), ['%20', '%0D%0A.', '%0D%0A', '%'],
array(' ', "\r\n=2E", "\r\n", '='), [' ', "\r\n=2E", "\r\n", '='],
rawurlencode($string) rawurlencode($string)
); );
return preg_replace('/[^\r\n]{' . ($line_max - 3) . '}[^=\r\n]{2}/', "$0=\r\n", $string); return preg_replace('/[^\r\n]{' . ($line_max - 3) . '}[^=\r\n]{2}/', "$0=\r\n", $string);
@ -2774,7 +2774,7 @@ class PHPMailer
{ {
// There should not be any EOL in the string // There should not be any EOL in the string
$pattern = ''; $pattern = '';
$encoded = str_replace(array("\r", "\n"), '', $str); $encoded = str_replace(["\r", "\n"], '', $str);
switch (strtolower($position)) { switch (strtolower($position)) {
case 'phrase': case 'phrase':
// RFC 2047 section 5.3 // RFC 2047 section 5.3
@ -2793,7 +2793,7 @@ class PHPMailer
$pattern = '\000-\011\013\014\016-\037\075\077\137\177-\377' . $pattern; $pattern = '\000-\011\013\014\016-\037\075\077\137\177-\377' . $pattern;
break; break;
} }
$matches = array(); $matches = [];
if (preg_match_all("/[{$pattern}]/", $encoded, $matches)) { if (preg_match_all("/[{$pattern}]/", $encoded, $matches)) {
// If the string contains an '=', make sure it's the first thing we replace // If the string contains an '=', make sure it's the first thing we replace
// so as to avoid double-encoding // so as to avoid double-encoding
@ -2833,7 +2833,7 @@ class PHPMailer
$type = self::filenameToType($filename); $type = self::filenameToType($filename);
} }
// Append to $attachment array // Append to $attachment array
$this->attachment[] = array( $this->attachment[] = [
0 => $string, 0 => $string,
1 => $filename, 1 => $filename,
2 => basename($filename), 2 => basename($filename),
@ -2842,7 +2842,7 @@ class PHPMailer
5 => true, // isStringAttachment 5 => true, // isStringAttachment
6 => $disposition, 6 => $disposition,
7 => 0 7 => 0
); ];
} }
/** /**
@ -2879,7 +2879,7 @@ class PHPMailer
} }
// Append to $attachment array // Append to $attachment array
$this->attachment[] = array( $this->attachment[] = [
0 => $path, 0 => $path,
1 => $filename, 1 => $filename,
2 => $name, 2 => $name,
@ -2888,7 +2888,7 @@ class PHPMailer
5 => false, // isStringAttachment 5 => false, // isStringAttachment
6 => $disposition, 6 => $disposition,
7 => $cid 7 => $cid
); ];
return true; return true;
} }
@ -2920,7 +2920,7 @@ class PHPMailer
} }
// Append to $attachment array // Append to $attachment array
$this->attachment[] = array( $this->attachment[] = [
0 => $string, 0 => $string,
1 => $name, 1 => $name,
2 => $name, 2 => $name,
@ -2929,7 +2929,7 @@ class PHPMailer
5 => true, // isStringAttachment 5 => true, // isStringAttachment
6 => $disposition, 6 => $disposition,
7 => $cid 7 => $cid
); ];
return true; return true;
} }
@ -2996,7 +2996,7 @@ class PHPMailer
foreach ($this->to as $to) { foreach ($this->to as $to) {
unset($this->all_recipients[strtolower($to[0])]); unset($this->all_recipients[strtolower($to[0])]);
} }
$this->to = array(); $this->to = [];
$this->clearQueuedAddresses('to'); $this->clearQueuedAddresses('to');
} }
@ -3009,7 +3009,7 @@ class PHPMailer
foreach ($this->cc as $cc) { foreach ($this->cc as $cc) {
unset($this->all_recipients[strtolower($cc[0])]); unset($this->all_recipients[strtolower($cc[0])]);
} }
$this->cc = array(); $this->cc = [];
$this->clearQueuedAddresses('cc'); $this->clearQueuedAddresses('cc');
} }
@ -3022,7 +3022,7 @@ class PHPMailer
foreach ($this->bcc as $bcc) { foreach ($this->bcc as $bcc) {
unset($this->all_recipients[strtolower($bcc[0])]); unset($this->all_recipients[strtolower($bcc[0])]);
} }
$this->bcc = array(); $this->bcc = [];
$this->clearQueuedAddresses('bcc'); $this->clearQueuedAddresses('bcc');
} }
@ -3032,8 +3032,8 @@ class PHPMailer
*/ */
public function clearReplyTos() public function clearReplyTos()
{ {
$this->ReplyTo = array(); $this->ReplyTo = [];
$this->ReplyToQueue = array(); $this->ReplyToQueue = [];
} }
/** /**
@ -3042,11 +3042,11 @@ class PHPMailer
*/ */
public function clearAllRecipients() public function clearAllRecipients()
{ {
$this->to = array(); $this->to = [];
$this->cc = array(); $this->cc = [];
$this->bcc = array(); $this->bcc = [];
$this->all_recipients = array(); $this->all_recipients = [];
$this->RecipientsQueue = array(); $this->RecipientsQueue = [];
} }
/** /**
@ -3055,7 +3055,7 @@ class PHPMailer
*/ */
public function clearAttachments() public function clearAttachments()
{ {
$this->attachment = array(); $this->attachment = [];
} }
/** /**
@ -3064,7 +3064,7 @@ class PHPMailer
*/ */
public function clearCustomHeaders() public function clearCustomHeaders()
{ {
$this->CustomHeader = array(); $this->CustomHeader = [];
} }
/** /**
@ -3175,7 +3175,7 @@ class PHPMailer
public function fixEOL($str) public function fixEOL($str)
{ {
// Normalise to \n // Normalise to \n
$nstr = str_replace(array("\r\n", "\r"), "\n", $str); $nstr = str_replace(["\r\n", "\r"], "\n", $str);
// Now convert LE as needed // Now convert LE as needed
if ($this->LE !== "\n") { if ($this->LE !== "\n") {
$nstr = str_replace("\n", $this->LE, $nstr); $nstr = str_replace("\n", $this->LE, $nstr);
@ -3198,7 +3198,7 @@ class PHPMailer
// Value passed in as name:value // Value passed in as name:value
$this->CustomHeader[] = explode(':', $name, 2); $this->CustomHeader[] = explode(':', $name, 2);
} else { } else {
$this->CustomHeader[] = array($name, $value); $this->CustomHeader[] = [$name, $value];
} }
} }
@ -3328,7 +3328,7 @@ class PHPMailer
*/ */
public static function _mime_types($ext = '') public static function _mime_types($ext = '')
{ {
$mimes = array( $mimes = [
'xl' => 'application/excel', 'xl' => 'application/excel',
'js' => 'application/javascript', 'js' => 'application/javascript',
'hqx' => 'application/mac-binhex40', 'hqx' => 'application/mac-binhex40',
@ -3427,7 +3427,7 @@ class PHPMailer
'rv' => 'video/vnd.rn-realvideo', 'rv' => 'video/vnd.rn-realvideo',
'avi' => 'video/x-msvideo', 'avi' => 'video/x-msvideo',
'movie' => 'video/x-sgi-movie' 'movie' => 'video/x-sgi-movie'
); ];
if (array_key_exists(strtolower($ext), $mimes)) { if (array_key_exists(strtolower($ext), $mimes)) {
return $mimes[strtolower($ext)]; return $mimes[strtolower($ext)];
} }
@ -3465,8 +3465,8 @@ class PHPMailer
*/ */
public static function mb_pathinfo($path, $options = null) public static function mb_pathinfo($path, $options = null)
{ {
$ret = array('dirname' => '', 'basename' => '', 'extension' => '', 'filename' => ''); $ret = ['dirname' => '', 'basename' => '', 'extension' => '', 'filename' => ''];
$pathinfo = array(); $pathinfo = [];
if (preg_match('%^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^\.\\\\/]+?)|))[\\\\/\.]*$%im', $path, $pathinfo)) { if (preg_match('%^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^\.\\\\/]+?)|))[\\\\/\.]*$%im', $path, $pathinfo)) {
if (array_key_exists(1, $pathinfo)) { if (array_key_exists(1, $pathinfo)) {
$ret['dirname'] = $pathinfo[1]; $ret['dirname'] = $pathinfo[1];
@ -3532,7 +3532,7 @@ class PHPMailer
*/ */
public function secureHeader($str) public function secureHeader($str)
{ {
return trim(str_replace(array("\r", "\n"), '', $str)); return trim(str_replace(["\r", "\n"], '', $str));
} }
/** /**
@ -3807,7 +3807,7 @@ class PHPMailer
protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from) protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from)
{ {
if (!empty($this->action_function) && is_callable($this->action_function)) { if (!empty($this->action_function) && is_callable($this->action_function)) {
$params = array($isSent, $to, $cc, $bcc, $subject, $body, $from); $params = [$isSent, $to, $cc, $bcc, $subject, $body, $from];
call_user_func_array($this->action_function, $params); call_user_func_array($this->action_function, $params);
} }
} }

View File

@ -85,7 +85,7 @@ class PHPMailerOAuth extends PHPMailer
* @uses SMTP * @uses SMTP
* @access public * @access public
*/ */
public function smtpConnect($options = array()) public function smtpConnect($options = [])
{ {
if (is_null($this->smtp)) { if (is_null($this->smtp)) {
$this->smtp = $this->getSMTPInstance(); $this->smtp = $this->getSMTPInstance();
@ -108,7 +108,7 @@ class PHPMailerOAuth extends PHPMailer
$lastexception = null; $lastexception = null;
foreach ($hosts as $hostentry) { foreach ($hosts as $hostentry) {
$hostinfo = array(); $hostinfo = [];
if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) { if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) {
// Not a valid host entry // Not a valid host entry
continue; continue;

View File

@ -122,7 +122,7 @@ class POP3
* @var array * @var array
* @access protected * @access protected
*/ */
protected $errors = array(); protected $errors = [];
/** /**
* Line break constant * Line break constant
@ -183,7 +183,7 @@ class POP3
$this->username = $username; $this->username = $username;
$this->password = $password; $this->password = $password;
// Reset the error log // Reset the error log
$this->errors = array(); $this->errors = [];
// connect // connect
$result = $this->connect($this->host, $this->port, $this->tval); $result = $this->connect($this->host, $this->port, $this->tval);
if ($result) { if ($result) {
@ -215,7 +215,7 @@ class POP3
//On Windows this will raise a PHP Warning error if the hostname doesn't exist. //On Windows this will raise a PHP Warning error if the hostname doesn't exist.
//Rather than suppress it with @fsockopen, capture it cleanly instead //Rather than suppress it with @fsockopen, capture it cleanly instead
set_error_handler(array($this, 'catchWarning')); set_error_handler([$this, 'catchWarning']);
if (false === $port) { if (false === $port) {
$port = $this->POP3_PORT; $port = $this->POP3_PORT;
@ -235,11 +235,13 @@ class POP3
// Did we connect? // Did we connect?
if (false === $this->pop_conn) { if (false === $this->pop_conn) {
// It would appear not... // It would appear not...
$this->setError(array( $this->setError(
[
'error' => "Failed to connect to server $host on port $port", 'error' => "Failed to connect to server $host on port $port",
'errno' => $errno, 'errno' => $errno,
'errstr' => $errstr 'errstr' => $errstr
)); ]
);
return false; return false;
} }
@ -350,11 +352,13 @@ class POP3
protected function checkResponse($string) protected function checkResponse($string)
{ {
if (substr($string, 0, 3) !== '+OK') { if (substr($string, 0, 3) !== '+OK') {
$this->setError(array( $this->setError(
[
'error' => "Server reported an error: $string", 'error' => "Server reported an error: $string",
'errno' => 0, 'errno' => 0,
'errstr' => '' 'errstr' => ''
)); ]
);
return false; return false;
} else { } else {
return true; return true;
@ -398,12 +402,14 @@ class POP3
*/ */
protected function catchWarning($errno, $errstr, $errfile, $errline) protected function catchWarning($errno, $errstr, $errfile, $errline)
{ {
$this->setError(array( $this->setError(
'error' => "Connecting to the POP3 server raised a PHP warning: ", [
'error' => 'Connecting to the POP3 server raised a PHP warning: ',
'errno' => $errno, 'errno' => $errno,
'errstr' => $errstr, 'errstr' => $errstr,
'errfile' => $errfile, 'errfile' => $errfile,
'errline' => $errline 'errline' => $errline
)); ]
);
} }
} }

View File

@ -154,12 +154,12 @@ class SMTP
* Error information, if any, for the last SMTP command. * Error information, if any, for the last SMTP command.
* @var array * @var array
*/ */
protected $error = array( protected $error = [
'error' => '', 'error' => '',
'detail' => '', 'detail' => '',
'smtp_code' => '', 'smtp_code' => '',
'smtp_code_ex' => '' 'smtp_code_ex' => ''
); ];
/** /**
* The reply the server sent to us for HELO. * The reply the server sent to us for HELO.
@ -199,7 +199,7 @@ class SMTP
return; return;
} }
//Avoid clash with built-in function names //Avoid clash with built-in function names
if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) { if (!in_array($this->Debugoutput, ['error_log', 'html', 'echo']) and is_callable($this->Debugoutput)) {
call_user_func($this->Debugoutput, $str, $this->do_debug); call_user_func($this->Debugoutput, $str, $this->do_debug);
return; return;
} }
@ -238,7 +238,7 @@ class SMTP
* @access public * @access public
* @return boolean * @return boolean
*/ */
public function connect($host, $port = null, $timeout = 30, $options = array()) public function connect($host, $port = null, $timeout = 30, $options = [])
{ {
static $streamok; static $streamok;
//This is enabled by default since 5.0.0 but some providers disable it //This is enabled by default since 5.0.0 but some providers disable it
@ -383,7 +383,7 @@ class SMTP
); );
if (empty($authtype)) { if (empty($authtype)) {
foreach (array('LOGIN', 'CRAM-MD5', 'NTLM', 'PLAIN', 'XOAUTH2') as $method) { foreach (['LOGIN', 'CRAM-MD5', 'NTLM', 'PLAIN', 'XOAUTH2'] as $method) {
if (in_array($method, $this->server_caps['AUTH'])) { if (in_array($method, $this->server_caps['AUTH'])) {
$authtype = $method; $authtype = $method;
break; break;
@ -621,7 +621,7 @@ class SMTP
*/ */
// Normalize line breaks before exploding // Normalize line breaks before exploding
$lines = explode("\n", str_replace(array("\r\n", "\r"), "\n", $msg_data)); $lines = explode("\n", str_replace(["\r\n", "\r"], "\n", $msg_data));
/* To distinguish between a complete RFC822 message and a plain message body, we check if the first field /* To distinguish between a complete RFC822 message and a plain message body, we check if the first field
* of the first line (':' separated) does not contain a space then it _should_ be a header and we will * of the first line (':' separated) does not contain a space then it _should_ be a header and we will
@ -635,7 +635,7 @@ class SMTP
} }
foreach ($lines as $line) { foreach ($lines as $line) {
$lines_out = array(); $lines_out = [];
if ($in_headers and $line == '') { if ($in_headers and $line == '') {
$in_headers = false; $in_headers = false;
} }
@ -729,7 +729,7 @@ class SMTP
*/ */
protected function parseHelloFields($type) protected function parseHelloFields($type)
{ {
$this->server_caps = array(); $this->server_caps = [];
$lines = explode("\n", $this->last_reply); $lines = explode("\n", $this->last_reply);
foreach ($lines as $n => $s) { foreach ($lines as $n => $s) {
@ -751,7 +751,7 @@ class SMTP
break; break;
case 'AUTH': case 'AUTH':
if (!is_array($fields)) { if (!is_array($fields)) {
$fields = array(); $fields = [];
} }
break; break;
default: default:
@ -817,7 +817,7 @@ class SMTP
return $this->sendCommand( return $this->sendCommand(
'RCPT TO', 'RCPT TO',
'RCPT TO:<' . $address . '>', 'RCPT TO:<' . $address . '>',
array(250, 251) [250, 251]
); );
} }
@ -856,7 +856,7 @@ class SMTP
$this->last_reply = $this->get_lines(); $this->last_reply = $this->get_lines();
// Fetch SMTP code and possible error code explanation // Fetch SMTP code and possible error code explanation
$matches = array(); $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 = $matches[1];
$code_ex = (count($matches) > 2 ? $matches[2] : null); $code_ex = (count($matches) > 2 ? $matches[2] : null);
@ -919,7 +919,7 @@ class SMTP
*/ */
public function verify($name) public function verify($name)
{ {
return $this->sendCommand('VRFY', "VRFY $name", array(250, 251)); return $this->sendCommand('VRFY', "VRFY $name", [250, 251]);
} }
/** /**
@ -1111,12 +1111,12 @@ class SMTP
*/ */
protected function setError($message, $detail = '', $smtp_code = '', $smtp_code_ex = '') protected function setError($message, $detail = '', $smtp_code = '', $smtp_code_ex = '')
{ {
$this->error = array( $this->error = [
'error' => $message, 'error' => $message,
'detail' => $detail, 'detail' => $detail,
'smtp_code' => $smtp_code, 'smtp_code' => $smtp_code,
'smtp_code_ex' => $smtp_code_ex 'smtp_code_ex' => $smtp_code_ex
); ];
} }
/** /**

View File

@ -56,11 +56,11 @@ class PHPMailerLangTest extends \PHPUnit_Framework_TestCase
if ($fileInfo->isDot()) { if ($fileInfo->isDot()) {
continue; continue;
} }
$matches = array(); $matches = [];
//Only look at language files, ignore anything else in there //Only look at language files, ignore anything else in there
if (preg_match('/^phpmailer\.lang-([a-z_]{2,})\.php$/', $fileInfo->getFilename(), $matches)) { if (preg_match('/^phpmailer\.lang-([a-z_]{2,})\.php$/', $fileInfo->getFilename(), $matches)) {
$lang = $matches[1]; //Extract language code $lang = $matches[1]; //Extract language code
$PHPMAILER_LANG = array(); //Language strings get put in here $PHPMAILER_LANG = []; //Language strings get put in here
include $fileInfo->getPathname(); //Get language strings include $fileInfo->getPathname(); //Get language strings
$missing = array_diff(array_keys($definedStrings), array_keys($PHPMAILER_LANG)); $missing = array_diff(array_keys($definedStrings), array_keys($PHPMAILER_LANG));
$extra = array_diff(array_keys($PHPMAILER_LANG), array_keys($definedStrings)); $extra = array_diff(array_keys($PHPMAILER_LANG), array_keys($definedStrings));

View File

@ -12,6 +12,7 @@
*/ */
namespace PHPMailer\PHPMailer; namespace PHPMailer\PHPMailer;
require '../vendor/autoload.php'; require '../vendor/autoload.php';
/** /**
@ -39,14 +40,14 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
* @private * @private
* @var string[] * @var string[]
*/ */
public $ChangeLog = array(); public $ChangeLog = [];
/** /**
* Holds the note log. * Holds the note log.
* @private * @private
* @var string[] * @var string[]
*/ */
public $NoteLog = array(); public $NoteLog = [];
/** /**
* Default include path * Default include path
@ -59,7 +60,7 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
* @var array * @var array
* @access private * @access private
*/ */
private $pids = array(); private $pids = [];
/** /**
* Run before each test is started. * Run before each test is started.
@ -121,8 +122,8 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
{ {
// Clean global variables // Clean global variables
$this->Mail = null; $this->Mail = null;
$this->ChangeLog = array(); $this->ChangeLog = [];
$this->NoteLog = array(); $this->NoteLog = [];
foreach ($this->pids as $pid) { foreach ($this->pids as $pid) {
$p = escapeshellarg($pid); $p = escapeshellarg($pid);
@ -161,7 +162,7 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
$ReportBody .= '---------------------' . $eol; $ReportBody .= '---------------------' . $eol;
$ReportBody .= 'Unit Test Information' . $eol; $ReportBody .= 'Unit Test Information' . $eol;
$ReportBody .= '---------------------' . $eol; $ReportBody .= '---------------------' . $eol;
$ReportBody .= 'phpmailer version: ' . $this->Mail->Version . $eol; $ReportBody .= 'phpmailer version: ' . PHPMailer::VERSION . $eol;
$ReportBody .= 'Content Type: ' . $this->Mail->ContentType . $eol; $ReportBody .= 'Content Type: ' . $this->Mail->ContentType . $eol;
$ReportBody .= 'CharSet: ' . $this->Mail->CharSet . $eol; $ReportBody .= 'CharSet: ' . $this->Mail->CharSet . $eol;
@ -256,7 +257,7 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
*/ */
public function addChange($sName, $sNewValue) public function addChange($sName, $sNewValue)
{ {
$this->ChangeLog[] = array($sName, $sNewValue); $this->ChangeLog[] = [$sName, $sNewValue];
} }
/** /**
@ -332,7 +333,7 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
*/ */
public function testValidate() public function testValidate()
{ {
$validaddresses = array( $validaddresses = [
'first@iana.org', 'first@iana.org',
'first.last@iana.org', 'first.last@iana.org',
'1234567890123456789012345678901234567890123456789012345678901234@iana.org', '1234567890123456789012345678901234567890123456789012345678901234@iana.org',
@ -465,8 +466,8 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
'test@test.com', 'test@test.com',
'test@xn--example.com', 'test@xn--example.com',
'test@example.com' 'test@example.com'
); ];
$invalidaddresses = array( $invalidaddresses = [
'first.last@sub.do,com', 'first.last@sub.do,com',
'first\@last@iana.org', 'first\@last@iana.org',
'123456789012345678901234567890123456789012345678901234567890' . '123456789012345678901234567890123456789012345678901234567890' .
@ -608,25 +609,25 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
//This is valid RCC5322, but we don't want to allow it //This is valid RCC5322, but we don't want to allow it
"(\r\n RCPT TO:websec02@d.mbsd.jp\r\n DATA \\\nSubject: spam10\\\n\r\n". "(\r\n RCPT TO:websec02@d.mbsd.jp\r\n DATA \\\nSubject: spam10\\\n\r\n".
" Hello,\r\n this is a spam mail.\\\n.\r\n QUIT\r\n ) a@gmail.com" " Hello,\r\n this is a spam mail.\\\n.\r\n QUIT\r\n ) a@gmail.com"
); ];
// IDNs in Unicode and ASCII forms. // IDNs in Unicode and ASCII forms.
$unicodeaddresses = array( $unicodeaddresses = [
'first.last@bücher.ch', 'first.last@bücher.ch',
'first.last@кто.рф', 'first.last@кто.рф',
'first.last@phplíst.com', 'first.last@phplíst.com',
); ];
$asciiaddresses = array( $asciiaddresses = [
'first.last@xn--bcher-kva.ch', 'first.last@xn--bcher-kva.ch',
'first.last@xn--j1ail.xn--p1ai', 'first.last@xn--j1ail.xn--p1ai',
'first.last@xn--phplst-6va.com', 'first.last@xn--phplst-6va.com',
); ];
$goodfails = array(); $goodfails = [];
foreach (array_merge($validaddresses, $asciiaddresses) as $address) { foreach (array_merge($validaddresses, $asciiaddresses) as $address) {
if (!PHPMailer::validateAddress($address)) { if (!PHPMailer::validateAddress($address)) {
$goodfails[] = $address; $goodfails[] = $address;
} }
} }
$badpasses = array(); $badpasses = [];
foreach (array_merge($invalidaddresses, $unicodeaddresses) as $address) { foreach (array_merge($invalidaddresses, $unicodeaddresses) as $address) {
if (PHPMailer::validateAddress($address)) { if (PHPMailer::validateAddress($address)) {
$badpasses[] = $address; $badpasses[] = $address;
@ -772,7 +773,7 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
//Check that a quoted printable encode and decode results in the same as went in //Check that a quoted printable encode and decode results in the same as went in
$t = file_get_contents(__FILE__); //Use this file as test content $t = file_get_contents(__FILE__); //Use this file as test content
//Force line breaks to UNIX-style //Force line breaks to UNIX-style
$t = str_replace(array("\r\n", "\r"), "\n", $t); $t = str_replace(["\r\n", "\r"], "\n", $t);
$this->assertEquals( $this->assertEquals(
$t, $t,
quoted_printable_decode($this->Mail->encodeQP($t)), quoted_printable_decode($this->Mail->encodeQP($t)),
@ -1523,7 +1524,7 @@ EOT;
$this->Mail->Body = 'This message is S/MIME signed.'; $this->Mail->Body = 'This message is S/MIME signed.';
$this->buildBody(); $this->buildBody();
$dn = array( $dn = [
'countryName' => 'UK', 'countryName' => 'UK',
'stateOrProvinceName' => 'Here', 'stateOrProvinceName' => 'Here',
'localityName' => 'There', 'localityName' => 'There',
@ -1531,12 +1532,12 @@ EOT;
'organizationalUnitName' => 'PHPMailer', 'organizationalUnitName' => 'PHPMailer',
'commonName' => 'PHPMailer Test', 'commonName' => 'PHPMailer Test',
'emailAddress' => 'phpmailer@example.com' 'emailAddress' => 'phpmailer@example.com'
); ];
$keyconfig = array( $keyconfig = [
"digest_alg" => "sha256", "digest_alg" => "sha256",
"private_key_bits" => 2048, "private_key_bits" => 2048,
"private_key_type" => OPENSSL_KEYTYPE_RSA, "private_key_type" => OPENSSL_KEYTYPE_RSA,
); ];
$password = 'password'; $password = 'password';
$certfile = 'certfile.txt'; $certfile = 'certfile.txt';
$keyfile = 'keyfile.txt'; $keyfile = 'keyfile.txt';
@ -1580,7 +1581,7 @@ EOT;
$this->Mail->Body = 'This message is S/MIME signed with an extra CA cert.'; $this->Mail->Body = 'This message is S/MIME signed with an extra CA cert.';
$this->buildBody(); $this->buildBody();
$certprops = array( $certprops = [
'countryName' => 'UK', 'countryName' => 'UK',
'stateOrProvinceName' => 'Here', 'stateOrProvinceName' => 'Here',
'localityName' => 'There', 'localityName' => 'There',
@ -1588,8 +1589,8 @@ EOT;
'organizationalUnitName' => 'PHPMailer', 'organizationalUnitName' => 'PHPMailer',
'commonName' => 'PHPMailer Test', 'commonName' => 'PHPMailer Test',
'emailAddress' => 'phpmailer@example.com' 'emailAddress' => 'phpmailer@example.com'
); ];
$cacertprops = array( $cacertprops = [
'countryName' => 'UK', 'countryName' => 'UK',
'stateOrProvinceName' => 'Here', 'stateOrProvinceName' => 'Here',
'localityName' => 'There', 'localityName' => 'There',
@ -1597,12 +1598,12 @@ EOT;
'organizationalUnitName' => 'PHPMailer CA', 'organizationalUnitName' => 'PHPMailer CA',
'commonName' => 'PHPMailer Test CA', 'commonName' => 'PHPMailer Test CA',
'emailAddress' => 'phpmailer@example.com' 'emailAddress' => 'phpmailer@example.com'
); ];
$keyconfig = array( $keyconfig = [
"digest_alg" => "sha256", 'digest_alg' => 'sha256',
"private_key_bits" => 2048, 'private_key_bits' => 2048,
"private_key_type" => OPENSSL_KEYTYPE_RSA, 'private_key_type' => OPENSSL_KEYTYPE_RSA,
); ];
$password = 'password'; $password = 'password';
$cacertfile = 'cacertfile.pem'; $cacertfile = 'cacertfile.pem';
$cakeyfile = 'cakeyfile.pem'; $cakeyfile = 'cakeyfile.pem';
@ -1664,10 +1665,10 @@ EOT;
//(2048 bits is the recommended minimum key length - //(2048 bits is the recommended minimum key length -
//gmail won't accept less than 1024 bits) //gmail won't accept less than 1024 bits)
$pk = openssl_pkey_new( $pk = openssl_pkey_new(
array( [
'private_key_bits' => 2048, 'private_key_bits' => 2048,
'private_key_type' => OPENSSL_KEYTYPE_RSA 'private_key_type' => OPENSSL_KEYTYPE_RSA
) ]
); );
openssl_pkey_export_to_file($pk, $privatekeyfile); openssl_pkey_export_to_file($pk, $privatekeyfile);
$this->Mail->DKIM_domain = 'example.com'; $this->Mail->DKIM_domain = 'example.com';
@ -1787,25 +1788,31 @@ EOT;
public function testCustomHeaderGetter() public function testCustomHeaderGetter()
{ {
$this->Mail->addCustomHeader('foo', 'bar'); $this->Mail->addCustomHeader('foo', 'bar');
$this->assertEquals(array(array('foo', 'bar')), $this->Mail->getCustomHeaders()); $this->assertEquals([['foo', 'bar']], $this->Mail->getCustomHeaders());
$this->Mail->addCustomHeader('foo', 'baz'); $this->Mail->addCustomHeader('foo', 'baz');
$this->assertEquals(array( $this->assertEquals(
array('foo', 'bar'), [
array('foo', 'baz') ['foo', 'bar'],
), $this->Mail->getCustomHeaders()); ['foo', 'baz']
],
$this->Mail->getCustomHeaders()
);
$this->Mail->clearCustomHeaders(); $this->Mail->clearCustomHeaders();
$this->assertEmpty($this->Mail->getCustomHeaders()); $this->assertEmpty($this->Mail->getCustomHeaders());
$this->Mail->addCustomHeader('yux'); $this->Mail->addCustomHeader('yux');
$this->assertEquals(array(array('yux')), $this->Mail->getCustomHeaders()); $this->assertEquals([['yux']], $this->Mail->getCustomHeaders());
$this->Mail->addCustomHeader('Content-Type: application/json'); $this->Mail->addCustomHeader('Content-Type: application/json');
$this->assertEquals(array( $this->assertEquals(
array('yux'), [
array('Content-Type', ' application/json') ['yux'],
), $this->Mail->getCustomHeaders()); ['Content-Type', ' application/json']
],
$this->Mail->getCustomHeaders()
);
} }
/** /**
@ -1872,18 +1879,21 @@ EOT;
// Addresses with IDN are returned by get*Addresses() after send() call. // Addresses with IDN are returned by get*Addresses() after send() call.
$domain = $this->Mail->punyencodeAddress($domain); $domain = $this->Mail->punyencodeAddress($domain);
$this->assertEquals( $this->assertEquals(
array(array('test' . $domain, '')), [['test' . $domain, '']],
$this->Mail->getToAddresses(), $this->Mail->getToAddresses(),
'Bad "to" recipients'); 'Bad "to" recipients'
);
$this->assertEquals( $this->assertEquals(
array(array('test+cc' . $domain, '')), [['test+cc' . $domain, '']],
$this->Mail->getCcAddresses(), $this->Mail->getCcAddresses(),
'Bad "cc" recipients'); 'Bad "cc" recipients'
);
$this->assertEmpty($this->Mail->getBccAddresses(), 'Bad "bcc" recipients'); $this->assertEmpty($this->Mail->getBccAddresses(), 'Bad "bcc" recipients');
$this->assertEquals( $this->assertEquals(
array('test+replyto' . $domain => array('test+replyto' . $domain, '')), ['test+replyto' . $domain => ['test+replyto' . $domain, '']],
$this->Mail->getReplyToAddresses(), $this->Mail->getReplyToAddresses(),
'Bad "reply-to" addresses'); 'Bad "reply-to" addresses'
);
} }
/** /**
@ -1981,19 +1991,19 @@ EOT;
$this->Mail->SMTPDebug = 4; //Show connection-level errors $this->Mail->SMTPDebug = 4; //Show connection-level errors
$this->assertTrue($this->Mail->smtpConnect(), 'SMTP single connect failed'); $this->assertTrue($this->Mail->smtpConnect(), 'SMTP single connect failed');
$this->Mail->smtpClose(); $this->Mail->smtpClose();
$this->Mail->Host = "ssl://localhost:12345;tls://localhost:587;10.10.10.10:54321;localhost:12345;10.10.10.10"; $this->Mail->Host = '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->assertFalse($this->Mail->smtpConnect(), 'SMTP bad multi-connect succeeded');
$this->Mail->smtpClose(); $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->assertTrue($this->Mail->smtpConnect(), 'SMTP multi-connect failed');
$this->Mail->smtpClose(); $this->Mail->smtpClose();
$this->Mail->Host = " localhost:12345 ; " . $_REQUEST['mail_host'] . ' '; $this->Mail->Host = ' localhost:12345 ; ' . $_REQUEST['mail_host'] . ' ';
$this->assertTrue($this->Mail->smtpConnect(), 'SMTP hosts with stray spaces failed'); $this->assertTrue($this->Mail->smtpConnect(), 'SMTP hosts with stray spaces failed');
$this->Mail->smtpClose(); $this->Mail->smtpClose();
$this->Mail->Host = $_REQUEST['mail_host']; $this->Mail->Host = $_REQUEST['mail_host'];
//Need to pick a harmless option so as not cause problems of its own! socket:bind doesn't work with Travis-CI //Need to pick a harmless option so as not cause problems of its own! socket:bind doesn't work with Travis-CI
$this->assertTrue( $this->assertTrue(
$this->Mail->smtpConnect(array('ssl' => array('verify_depth' => 10))), $this->Mail->smtpConnect(['ssl' => ['verify_depth' => 10]]),
'SMTP connect with options failed' 'SMTP connect with options failed'
); );
} }