Skip to content

Commit

Permalink
Avoid convoluted syntax
Browse files Browse the repository at this point in the history
Use more robust comparisons, be more forgiving where it's not important
Don't assume temp file writing worked
  • Loading branch information
Synchro committed Nov 3, 2014
1 parent 92b445d commit 5afb552
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
24 changes: 13 additions & 11 deletions class.phpmailer.php
Expand Up @@ -576,7 +576,7 @@ class PHPMailer
*/
public function __construct($exceptions = false)
{
$this->exceptions = ($exceptions == true);
$this->exceptions = (boolean)$exceptions;
}

/**
Expand Down Expand Up @@ -1102,7 +1102,7 @@ protected function sendmailSend($header, $body)
$sendmail = sprintf('%s -oi -t', escapeshellcmd($this->Sendmail));
}
}
if ($this->SingleTo === true) {
if ($this->SingleTo) {
foreach ($this->SingleToArray as $toAddr) {
if (!@$mail = popen($sendmail, 'w')) {
throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
Expand Down Expand Up @@ -1166,7 +1166,7 @@ protected function mailSend($header, $body)
ini_set('sendmail_from', $this->Sender);
}
$result = false;
if ($this->SingleTo === true && count($toArr) > 1) {
if ($this->SingleTo && count($toArr) > 1) {
foreach ($toArr as $toAddr) {
$result = $this->mailPassthru($toAddr, $this->Subject, $body, $header, $params);
$this->doCallback($result, array($toAddr), $this->cc, $this->bcc, $this->Subject, $body, $this->From);
Expand Down Expand Up @@ -1255,7 +1255,7 @@ protected function smtpSend($header, $body)
if ((count($this->all_recipients) > count($bad_rcpt)) and !$this->smtp->data($header . $body)) {
throw new phpmailerException($this->lang('data_not_accepted'), self::STOP_CRITICAL);
}
if ($this->SMTPKeepAlive == true) {
if ($this->SMTPKeepAlive) {
$this->smtp->reset();
} else {
$this->smtp->quit();
Expand Down Expand Up @@ -1431,7 +1431,7 @@ public function setLanguage($langcode = 'en', $lang_path = '')
}
}
$this->language = $PHPMAILER_LANG;
return ($foundlang == true); // Returns false if language not found
return (boolean)$foundlang; // Returns false if language not found
}

/**
Expand Down Expand Up @@ -1586,7 +1586,7 @@ public function utf8CharBoundary($encodedText, $maxLength)
while (!$foundSplitPos) {
$lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
$encodedCharPos = strpos($lastChunk, '=');
if ($encodedCharPos !== false) {
if (false !== $encodedCharPos) {
// Found start of encoded character byte within $lookBack block.
// Check the encoded byte value (the 2 chars after the '=')
$hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
Expand Down Expand Up @@ -1658,7 +1658,7 @@ public function createHeader()


// To be created automatically by mail()
if ($this->SingleTo === true) {
if ($this->SingleTo) {
if ($this->Mailer != 'mail') {
foreach ($this->to as $toaddr) {
$this->SingleToArray[] = $this->addrFormat($toaddr);
Expand Down Expand Up @@ -1937,7 +1937,9 @@ public function createBody()
}
// @TODO would be nice to use php://temp streams here, but need to wrap for PHP < 5.1
$file = tempnam(sys_get_temp_dir(), 'mail');
file_put_contents($file, $body); // @TODO check this worked
if (false === file_put_contents($file, $body)) {
throw new phpmailerException($this->lang('signing') . ' Could not write temp file');
}
$signed = tempnam(sys_get_temp_dir(), 'signed');
if (@openssl_pkcs7_sign(
$file,
Expand Down Expand Up @@ -2513,7 +2515,7 @@ public function encodeQ($str, $position = 'text')
// If the string contains an '=', make sure it's the first thing we replace
// so as to avoid double-encoding
$eqkey = array_search('=', $matches[0]);
if ($eqkey !== false) {
if (false !== $eqkey) {
unset($matches[0][$eqkey]);
array_unshift($matches[0], '=');
}
Expand Down Expand Up @@ -2564,7 +2566,7 @@ public function addStringAttachment(
/**
* Add an embedded (inline) attachment from a file.
* This can include images, sounds, and just about any other document type.
* These differ from 'regular' attachmants in that they are intended to be
* These differ from 'regular' attachments in that they are intended to be
* displayed inline with the message, not just attached for download.
* This is used in HTML messages that embed the images
* the HTML refers to using the $cid value.
Expand Down Expand Up @@ -3088,7 +3090,7 @@ public static function filenameToType($filename)
{
// In case the path is a URL, strip any query string before getting extension
$qpos = strpos($filename, '?');
if ($qpos !== false) {
if (false !== $qpos) {
$filename = substr($filename, 0, $qpos);
}
$pathinfo = self::mb_pathinfo($filename);
Expand Down
8 changes: 4 additions & 4 deletions class.pop3.php
Expand Up @@ -166,13 +166,13 @@ public function authorise($host, $port = false, $timeout = false, $username = ''
{
$this->host = $host;
// If no port value provided, use default
if ($port === false) {
if (false === $port) {
$this->port = $this->POP3_PORT;
} else {
$this->port = (integer)$port;
}
// If no timeout value provided, use default
if ($timeout === false) {
if (false === $timeout) {
$this->tval = $this->POP3_TIMEOUT;
} else {
$this->tval = (integer)$timeout;
Expand Down Expand Up @@ -215,7 +215,7 @@ public function connect($host, $port = false, $tval = 30)
//Rather than suppress it with @fsockopen, capture it cleanly instead
set_error_handler(array($this, 'catchWarning'));

if ($port === false) {
if (false === $port) {
$port = $this->POP3_PORT;
}

Expand All @@ -231,7 +231,7 @@ public function connect($host, $port = false, $tval = 30)
restore_error_handler();

// Did we connect?
if ($this->pop_conn === false) {
if (false === $this->pop_conn) {
// It would appear not...
$this->setError(array(
'error' => "Failed to connect to server $host on port $port",
Expand Down

0 comments on commit 5afb552

Please sign in to comment.