Skip to content

Commit

Permalink
Avoid ternary statements
Browse files Browse the repository at this point in the history
Use boolean values consistently for magic_quotes settings
  • Loading branch information
Synchro committed Mar 5, 2015
1 parent ec9148b commit ec94520
Showing 1 changed file with 36 additions and 14 deletions.
50 changes: 36 additions & 14 deletions class.phpmailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,11 @@ protected function smtpSend($header, $body)
if (!$this->smtpConnect()) {
throw new phpmailerException($this->lang('smtp_connect_failed'), self::STOP_CRITICAL);
}
$smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
if ('' == $this->Sender) {
$smtp_from = $this->From;
} else {
$smtp_from = $this->Sender;
}
if (!$this->smtp->mail($smtp_from)) {
$this->setError($this->lang('from_failed') . $smtp_from . ' : ' . implode(',', $this->smtp->getError()));
throw new phpmailerException($this->ErrorInfo, self::STOP_CRITICAL);
Expand Down Expand Up @@ -1496,7 +1500,11 @@ public function addrFormat($addr)
*/
public function wrapText($message, $length, $qp_mode = false)
{
$soft_break = ($qp_mode) ? sprintf(' =%s', $this->LE) : $this->LE;
if ($qp_mode) {
$soft_break = sprintf(' =%s', $this->LE);
} else {
$soft_break = $this->LE;
}
// If utf-8 encoding is used, we will need to make sure we don't
// split multibyte characters when we wrap
$is_utf8 = (strtolower($this->CharSet) == 'utf-8');
Expand Down Expand Up @@ -1582,11 +1590,11 @@ public function wrapText($message, $length, $qp_mode = false)

/**
* Find the last character boundary prior to $maxLength in a utf-8
* quoted (printable) encoded string.
* quoted-printable encoded string.
* Original written by Colin Brown.
* @access public
* @param string $encodedText utf-8 QP text
* @param integer $maxLength find last character boundary prior to this length
* @param integer $maxLength Find the last character boundary prior to this length
* @return integer
*/
public function utf8CharBoundary($encodedText, $maxLength)
Expand All @@ -1601,17 +1609,21 @@ public function utf8CharBoundary($encodedText, $maxLength)
// Check the encoded byte value (the 2 chars after the '=')
$hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
$dec = hexdec($hex);
if ($dec < 128) { // Single byte character.
if ($dec < 128) {
// Single byte character.
// If the encoded char was found at pos 0, it will fit
// otherwise reduce maxLength to start of the encoded char
$maxLength = ($encodedCharPos == 0) ? $maxLength :
$maxLength - ($lookBack - $encodedCharPos);
if ($encodedCharPos > 0) {
$maxLength = $maxLength - ($lookBack - $encodedCharPos);
}
$foundSplitPos = true;
} elseif ($dec >= 192) { // First byte of a multi byte character
} elseif ($dec >= 192) {
// First byte of a multi byte character
// Reduce maxLength to split at start of character
$maxLength = $maxLength - ($lookBack - $encodedCharPos);
$foundSplitPos = true;
} elseif ($dec < 192) { // Middle byte of a multi byte character, look further back
} elseif ($dec < 192) {
// Middle byte of a multi byte character, look further back
$lookBack += 3;
}
} else {
Expand All @@ -1623,7 +1635,10 @@ public function utf8CharBoundary($encodedText, $maxLength)
}

/**
* Set the body wrapping.
* Apply word wrapping to the message body.
* Wraps the message body to the number of chars set in the WordWrap property.
* You should only do this to plain-text bodies as wrapping HTML tags may break them.
* This is called automatically by createBody(), so you don't need to call it yourself.
* @access public
* @return void
*/
Expand Down Expand Up @@ -2259,7 +2274,7 @@ protected function encodeFile($path, $encoding = 'base64')
//Doesn't exist in PHP 5.4, but we don't need to check because
//get_magic_quotes_runtime always returns false in 5.4+
//so it will never get here
ini_set('magic_quotes_runtime', 0);
ini_set('magic_quotes_runtime', false);
}
}
$file_buffer = file_get_contents($path);
Expand All @@ -2268,7 +2283,7 @@ protected function encodeFile($path, $encoding = 'base64')
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
set_magic_quotes_runtime($magic_quotes);
} else {
ini_set('magic_quotes_runtime', ($magic_quotes?'1':'0'));
ini_set('magic_quotes_runtime', $magic_quotes);
}
}
return $file_buffer;
Expand Down Expand Up @@ -3100,7 +3115,10 @@ public static function _mime_types($ext = '')
'avi' => 'video/x-msvideo',
'movie' => 'video/x-sgi-movie'
);
return (array_key_exists(strtolower($ext), $mimes) ? $mimes[strtolower($ext)]: 'application/octet-stream');
if (array_key_exists(strtolower($ext), $mimes)) {
return $mimes[strtolower($ext)];
}
return 'application/octet-stream';
}

/**
Expand Down Expand Up @@ -3366,7 +3384,11 @@ public function DKIM_Add($headers_line, $subject, $body)
$body = $this->DKIM_BodyC($body);
$DKIMlen = strlen($body); // Length of body
$DKIMb64 = base64_encode(pack('H*', sha1($body))); // Base64 of packed binary SHA-1 hash of body
$ident = ($this->DKIM_identity == '') ? '' : ' i=' . $this->DKIM_identity . ';';
if ('' == $this->DKIM_identity) {
$ident = '';
} else {
$ident = ' i=' . $this->DKIM_identity . ';';
}
$dkimhdrs = 'DKIM-Signature: v=1; a=' .
$DKIMsignatureType . '; q=' .
$DKIMquery . '; l=' .
Expand Down

0 comments on commit ec94520

Please sign in to comment.