From 1bd3d887057ce807944188f8f18142c14418b2ea Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 22 Dec 2011 15:38:20 +0200 Subject: Improve the Email library --- system/libraries/Email.php | 480 ++++++++++++++++----------------------------- 1 file changed, 172 insertions(+), 308 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 631b62e86..5158e859c 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1,13 +1,13 @@ -_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; - $this->_safe_mode = ((boolean)@ini_get("safe_mode") === FALSE) ? FALSE : TRUE; + $this->_safe_mode = (bool) @ini_get("safe_mode"); } log_message('debug', "Email Class Initialized"); @@ -140,7 +140,7 @@ class CI_Email { $this->clear(); $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; - $this->_safe_mode = ((boolean)@ini_get("safe_mode") === FALSE) ? FALSE : TRUE; + $this->_safe_mode = (bool) @ini_get("safe_mode"); return $this; } @@ -194,7 +194,7 @@ class CI_Email { { if (preg_match( '/\<(.*)\>/', $from, $match)) { - $from = $match['1']; + $from = $match[1]; } if ($this->validate) @@ -237,7 +237,7 @@ class CI_Email { { if (preg_match( '/\<(.*)\>/', $replyto, $match)) { - $replyto = $match['1']; + $replyto = $match[1]; } if ($this->validate) @@ -250,7 +250,7 @@ class CI_Email { $name = $replyto; } - if (strncmp($name, '"', 1) != 0) + if (strncmp($name, '"', 1) !== 0) { $name = '"'.$name.'"'; } @@ -280,7 +280,7 @@ class CI_Email { $this->validate_email($to); } - if ($this->_get_protocol() != 'mail') + if ($this->_get_protocol() !== 'mail') { $this->_set_header('To', implode(", ", $to)); } @@ -320,7 +320,7 @@ class CI_Email { $this->_set_header('Cc', implode(", ", $cc)); - if ($this->_get_protocol() == "smtp") + if ($this->_get_protocol() === 'smtp') { $this->_cc_array = $cc; } @@ -354,7 +354,7 @@ class CI_Email { $this->validate_email($bcc); } - if (($this->_get_protocol() == "smtp") OR ($this->bcc_batch_mode && count($bcc) > $this->bcc_batch_size)) + if ($this->_get_protocol() === 'smtp' OR ($this->bcc_batch_mode && count($bcc) > $this->bcc_batch_size)) { $this->_bcc_array = $bcc; } @@ -538,19 +538,13 @@ class CI_Email { */ public function set_priority($n = 3) { - if ( ! is_numeric($n)) - { - $this->priority = 3; - return; - } - - if ($n < 1 OR $n > 5) + if ( ! is_numeric($n) OR $n < 1 OR $n > 5) { $this->priority = 3; return; } - $this->priority = $n; + $this->priority = (int) $n; return $this; } @@ -565,14 +559,7 @@ class CI_Email { */ public function set_newline($newline = "\n") { - if ($newline != "\n" AND $newline != "\r\n" AND $newline != "\r") - { - $this->newline = "\n"; - return; - } - - $this->newline = $newline; - + $this->newline = ($newline !== "\n" AND $newline !== "\r\n" AND $newline !== "\r") ? "\n" : $newline; return $this; } @@ -587,14 +574,7 @@ class CI_Email { */ public function set_crlf($crlf = "\n") { - if ($crlf != "\n" AND $crlf != "\r\n" AND $crlf != "\r") - { - $this->crlf = "\n"; - return; - } - - $this->crlf = $crlf; - + $this->crlf = ($crlf !== "\n" AND $crlf !== "\r\n" AND $crlf !== "\r") ? "\n" : $crlf; return $this; } @@ -622,9 +602,7 @@ class CI_Email { */ protected function _get_message_id() { - $from = $this->_headers['Return-Path']; - $from = str_replace(">", "", $from); - $from = str_replace("<", "", $from); + $from = str_replace(array('>', '<'), array('', ''), $this->_headers['Return-Path']); return "<".uniqid('').strstr($from, '@').">"; } @@ -664,7 +642,7 @@ class CI_Email { foreach ($this->_base_charsets as $charset) { - if (strncmp($charset, $this->charset, strlen($charset)) == 0) + if (strncmp($charset, $this->charset, strlen($charset)) === 0) { $this->_encoding = '7bit'; } @@ -686,15 +664,15 @@ class CI_Email { */ protected function _get_content_type() { - if ($this->mailtype == 'html' && count($this->_attach_name) == 0) + if ($this->mailtype === 'html' && count($this->_attach_name) === 0) { return 'html'; } - elseif ($this->mailtype == 'html' && count($this->_attach_name) > 0) + elseif ($this->mailtype === 'html' && count($this->_attach_name) > 0) { return 'html-attach'; } - elseif ($this->mailtype == 'text' && count($this->_attach_name) > 0) + elseif ($this->mailtype === 'text' && count($this->_attach_name) > 0) { return 'plain-attach'; } @@ -715,9 +693,9 @@ class CI_Email { protected function _set_date() { $timezone = date("Z"); - $operator = (strncmp($timezone, '-', 1) == 0) ? '-' : '+'; + $operator = (strncmp($timezone, '-', 1) === 0) ? '-' : '+'; $timezone = abs($timezone); - $timezone = floor($timezone/3600) * 100 + ($timezone % 3600 ) / 60; + $timezone = floor($timezone/3600) * 100 + ($timezone % 3600) / 60; return sprintf("%s %s%04d", date("D, j M Y H:i:s"), $operator, $timezone); } @@ -775,7 +753,7 @@ class CI_Email { */ public function valid_email($address) { - return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) ? FALSE : TRUE; + return (bool) preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address); } // -------------------------------------------------------------------- @@ -791,28 +769,14 @@ class CI_Email { { if ( ! is_array($email)) { - if (preg_match('/\<(.*)\>/', $email, $match)) - { - return $match['1']; - } - else - { - return $email; - } + return (preg_match('/\<(.*)\>/', $email, $match)) ? $match[1] : $email; } $clean_email = array(); foreach ($email as $addy) { - if (preg_match( '/\<(.*)\>/', $addy, $match)) - { - $clean_email[] = $match['1']; - } - else - { - $clean_email[] = $addy; - } + $clean_email[] = (preg_match( '/\<(.*)\>/', $addy, $match)) ? $match[1] : $addy; } return $clean_email; @@ -838,32 +802,15 @@ class CI_Email { return $this->word_wrap($this->alt_message, '76'); } - if (preg_match('/\(.*)\<\/body\>/si', $this->_body, $match)) - { - $body = $match['1']; - } - else - { - $body = $this->_body; - } - - $body = trim(strip_tags($body)); - $body = preg_replace( '#