diff options
Diffstat (limited to 'system/libraries/Email.php')
-rw-r--r-- | system/libraries/Email.php | 242 |
1 files changed, 81 insertions, 161 deletions
diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 6a8bda70e..f9a4ae733 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -147,7 +147,7 @@ class CI_Email { * * @var string */ - public $charset = 'UTF-8'; + public $charset = 'utf-8'; /** * Alternative message (for HTML messages only) @@ -161,7 +161,7 @@ class CI_Email { * * @var bool */ - public $validate = FALSE; + public $validate = TRUE; /** * X-Priority header value. @@ -226,13 +226,6 @@ class CI_Email { // -------------------------------------------------------------------- /** - * Whether PHP is running in safe mode. Initialized by the class constructor. - * - * @var bool - */ - protected $_safe_mode = FALSE; - - /** * Subject header * * @var string @@ -395,7 +388,6 @@ class CI_Email { { $this->charset = config_item('charset'); $this->initialize($config); - $this->_safe_mode = ( ! is_php('5.4') && ini_get('safe_mode')); isset(self::$func_overload) OR self::$func_overload = (extension_loaded('mbstring') && ini_get('mbstring.func_overload')); @@ -675,18 +667,6 @@ class CI_Email { public function message($body) { $this->_body = rtrim(str_replace("\r", '', $body)); - - /* strip slashes only if magic quotes is ON - if we do it with magic quotes OFF, it strips real, user-inputted chars. - - NOTE: In PHP 5.4 get_magic_quotes_gpc() will always return 0 and - it will probably not exist in future versions at all. - */ - if ( ! is_php('5.4') && get_magic_quotes_gpc()) - { - $this->_body = stripslashes($this->_body); - } - return $this; } @@ -1032,13 +1012,9 @@ class CI_Email { */ public function valid_email($email) { - if (function_exists('idn_to_ascii') && strpos($email, '@')) + if (function_exists('idn_to_ascii') && $atpos = strpos($email, '@')) { - list($account, $domain) = explode('@', $email, 2); - $domain = is_php('5.4') - ? idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46) - : idn_to_ascii($domain); - $email = $account.'@'.$domain; + $email = self::substr($email, 0, ++$atpos).idn_to_ascii(self::substr($email, $atpos), 0, INTL_IDNA_VARIANT_UTS46); } return (bool) filter_var($email, FILTER_VALIDATE_EMAIL); @@ -1257,7 +1233,7 @@ class CI_Email { /** * Build Final Body and attachments * - * @return bool + * @return void */ protected function _build_message() { @@ -1424,8 +1400,6 @@ class CI_Email { $this->_finalbody = ($this->_get_protocol() === 'mail') ? $body : $hdr.$this->newline.$this->newline.$body; - - return TRUE; } // -------------------------------------------------------------------- @@ -1687,8 +1661,8 @@ class CI_Email { $this->reply_to($this->_headers['From']); } - if ( ! isset($this->_recipients) && ! isset($this->_headers['To']) - && ! isset($this->_bcc_array) && ! isset($this->_headers['Bcc']) + if (empty($this->_recipients) && ! isset($this->_headers['To']) + && empty($this->_bcc_array) && ! isset($this->_headers['Bcc']) && ! isset($this->_headers['Cc'])) { $this->_set_error_message('lang:email_no_recipients'); @@ -1699,21 +1673,17 @@ class CI_Email { if ($this->bcc_batch_mode && count($this->_bcc_array) > $this->bcc_batch_size) { - $result = $this->batch_bcc_send(); + $this->batch_bcc_send(); - if ($result && $auto_clear) + if ($auto_clear) { $this->clear(); } - return $result; - } - - if ($this->_build_message() === FALSE) - { - return FALSE; + return TRUE; } + $this->_build_message(); $result = $this->_spool_email(); if ($result && $auto_clear) @@ -1772,11 +1742,7 @@ class CI_Email { $this->_bcc_array = $bcc; } - if ($this->_build_message() === FALSE) - { - return FALSE; - } - + $this->_build_message(); $this->_spool_email(); } } @@ -1853,13 +1819,9 @@ class CI_Email { */ protected function _validate_email_for_shell(&$email) { - if (function_exists('idn_to_ascii') && strpos($email, '@')) + if (function_exists('idn_to_ascii') && $atpos = strpos($email, '@')) { - list($account, $domain) = explode('@', $email, 2); - $domain = is_php('5.4') - ? idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46) - : idn_to_ascii($domain); - $email = $account.'@'.$domain; + $email = self::substr($email, 0, ++$atpos).idn_to_ascii(self::substr($email, $atpos), 0, INTL_IDNA_VARIANT_UTS46); } return (filter_var($email, FILTER_VALIDATE_EMAIL) === $email && preg_match('#\A[a-z0-9._+-]+@[a-z0-9.-]{1,253}\z#i', $email)); @@ -1883,16 +1845,14 @@ class CI_Email { // so this needs to be assigned to a variable $from = $this->clean_email($this->_headers['Return-Path']); - if ($this->_safe_mode === TRUE || ! $this->_validate_email_for_shell($from)) + if ( ! $this->_validate_email_for_shell($from)) { return mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str); } - else - { - // most documentation of sendmail using the "-f" flag lacks a space after it, however - // we've encountered servers that seem to require it to be in place. - return mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, '-f '.$from); - } + + // most documentation of sendmail using the "-f" flag lacks a space after it, however + // we've encountered servers that seem to require it to be in place. + return mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, '-f '.$from); } // -------------------------------------------------------------------- @@ -1973,27 +1933,21 @@ class CI_Email { } } - if (count($this->_cc_array) > 0) + foreach ($this->_cc_array as $val) { - foreach ($this->_cc_array as $val) + if ($val !== '' && ! $this->_send_command('to', $val)) { - if ($val !== '' && ! $this->_send_command('to', $val)) - { - $this->_smtp_end(); - return FALSE; - } + $this->_smtp_end(); + return FALSE; } } - if (count($this->_bcc_array) > 0) + foreach ($this->_bcc_array as $val) { - foreach ($this->_bcc_array as $val) + if ($val !== '' && ! $this->_send_command('to', $val)) { - if ($val !== '' && ! $this->_send_command('to', $val)) - { - $this->_smtp_end(); - return FALSE; - } + $this->_smtp_end(); + return FALSE; } } @@ -2007,7 +1961,6 @@ class CI_Email { $this->_send_data($this->_header_str.preg_replace('/^\./m', '..$1', $this->_finalbody)); $this->_send_data('.'); - $reply = $this->_get_smtp_data(); $this->_set_error_message($reply); @@ -2033,9 +1986,7 @@ class CI_Email { */ protected function _smtp_end() { - ($this->smtp_keepalive) - ? $this->_send_command('reset') - : $this->_send_command('quit'); + $this->_send_command($this->smtp_keepalive ? 'reset' : 'quit'); } // -------------------------------------------------------------------- @@ -2054,11 +2005,13 @@ class CI_Email { $ssl = ($this->smtp_crypto === 'ssl') ? 'ssl://' : ''; - $this->_smtp_connect = fsockopen($ssl.$this->smtp_host, - $this->smtp_port, - $errno, - $errstr, - $this->smtp_timeout); + $this->_smtp_connect = fsockopen( + $ssl.$this->smtp_host, + $this->smtp_port, + $errno, + $errstr, + $this->smtp_timeout + ); if ( ! is_resource($this->_smtp_connect)) { @@ -2099,57 +2052,49 @@ class CI_Email { { switch ($cmd) { - case 'hello' : - - if ($this->_smtp_auth OR $this->_get_encoding() === '8bit') - { - $this->_send_data('EHLO '.$this->_get_hostname()); - } - else - { - $this->_send_data('HELO '.$this->_get_hostname()); - } - - $resp = 250; - break; - case 'starttls' : - - $this->_send_data('STARTTLS'); - $resp = 220; - break; - case 'from' : - - $this->_send_data('MAIL FROM:<'.$data.'>'); - $resp = 250; - break; - case 'to' : - - if ($this->dsn) - { - $this->_send_data('RCPT TO:<'.$data.'> NOTIFY=SUCCESS,DELAY,FAILURE ORCPT=rfc822;'.$data); - } - else - { - $this->_send_data('RCPT TO:<'.$data.'>'); - } - - $resp = 250; - break; - case 'data' : - - $this->_send_data('DATA'); - $resp = 354; - break; - case 'reset': - - $this->_send_data('RSET'); - $resp = 250; - break; - case 'quit' : + case 'hello': + if ($this->_smtp_auth OR $this->_get_encoding() === '8bit') + { + $this->_send_data('EHLO '.$this->_get_hostname()); + } + else + { + $this->_send_data('HELO '.$this->_get_hostname()); + } - $this->_send_data('QUIT'); - $resp = 221; - break; + $resp = 250; + break; + case 'starttls': + $this->_send_data('STARTTLS'); + $resp = 220; + break; + case 'from': + $this->_send_data('MAIL FROM:<'.$data.'>'); + $resp = 250; + break; + case 'to': + if ($this->dsn) + { + $this->_send_data('RCPT TO:<'.$data.'> NOTIFY=SUCCESS,DELAY,FAILURE ORCPT=rfc822;'.$data); + } + else + { + $this->_send_data('RCPT TO:<'.$data.'>'); + } + $resp = 250; + break; + case 'data': + $this->_send_data('DATA'); + $resp = 354; + break; + case 'reset': + $this->_send_data('RSET'); + $resp = 250; + break; + case 'quit': + $this->_send_data('QUIT'); + $resp = 221; + break; } $reply = $this->_get_smtp_data(); @@ -2191,7 +2136,6 @@ class CI_Email { } $this->_send_data('AUTH LOGIN'); - $reply = $this->_get_smtp_data(); if (strpos($reply, '503') === 0) // Already authenticated @@ -2205,7 +2149,6 @@ class CI_Email { } $this->_send_data(base64_encode($this->smtp_user)); - $reply = $this->_get_smtp_data(); if (strpos($reply, '334') !== 0) @@ -2215,7 +2158,6 @@ class CI_Email { } $this->_send_data(base64_encode($this->smtp_pass)); - $reply = $this->_get_smtp_data(); if (strpos($reply, '235') !== 0) @@ -2336,34 +2278,15 @@ class CI_Email { */ public function print_debugger($include = array('headers', 'subject', 'body')) { - $msg = ''; - - if (count($this->_debug_msg) > 0) - { - foreach ($this->_debug_msg as $val) - { - $msg .= $val; - } - } + $msg = implode('', $this->_debug_msg); // Determine which parts of our raw data needs to be printed $raw_data = ''; is_array($include) OR $include = array($include); - if (in_array('headers', $include, TRUE)) - { - $raw_data = htmlspecialchars($this->_header_str)."\n"; - } - - if (in_array('subject', $include, TRUE)) - { - $raw_data .= htmlspecialchars($this->_subject)."\n"; - } - - if (in_array('body', $include, TRUE)) - { - $raw_data .= htmlspecialchars($this->_finalbody); - } + in_array('headers', $include, TRUE) && $raw_data = htmlspecialchars($this->_header_str)."\n"; + in_array('subject', $include, TRUE) && $raw_data .= htmlspecialchars($this->_subject)."\n"; + in_array('body', $include, TRUE) && $raw_data .= htmlspecialchars($this->_finalbody); return $msg.($raw_data === '' ? '' : '<pre>'.$raw_data.'</pre>'); } @@ -2457,9 +2380,6 @@ class CI_Email { { if (self::$func_overload) { - // mb_substr($str, $start, null, '8bit') returns an empty - // string on PHP 5.3 - isset($length) OR $length = ($start >= 0 ? self::strlen($str) - $start : -$start); return mb_substr($str, $start, $length, '8bit'); } |