diff options
Diffstat (limited to 'system/libraries/Email.php')
-rwxr-xr-x | system/libraries/Email.php | 154 |
1 files changed, 92 insertions, 62 deletions
diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 03eccea09..9ec40af9d 100755 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -36,6 +36,7 @@ class CI_Email { var $smtp_pass = ""; // SMTP Password var $smtp_port = "25"; // SMTP Port var $smtp_timeout = 5; // SMTP Timeout in seconds + var $smtp_crypto = ""; // SMTP Encryption. Can be null, tls or ssl. var $wordwrap = TRUE; // TRUE/FALSE Turns word-wrap on/off var $wrapchars = "76"; // Number of characters to wrap at. var $mailtype = "text"; // text/html Defines email formatting @@ -379,7 +380,19 @@ class CI_Email { */ public function message($body) { - $this->_body = stripslashes(rtrim(str_replace("\r", "", $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; } @@ -405,12 +418,12 @@ class CI_Email { /** * Add a Header Item * - * @access private + * @access protected * @param string * @param string * @return void */ - private function _set_header($header, $value) + protected function _set_header($header, $value) { $this->_headers[$header] = $value; } @@ -420,11 +433,11 @@ class CI_Email { /** * Convert a String to an Array * - * @access private + * @access protected * @param string * @return array */ - private function _str_to_array($email) + protected function _str_to_array($email) { if ( ! is_array($email)) { @@ -452,7 +465,7 @@ class CI_Email { */ public function set_alt_message($str = '') { - $this->alt_message = ($str == '') ? '' : $str; + $this->alt_message = $str; return $this; } @@ -577,10 +590,10 @@ class CI_Email { /** * Set Message Boundary * - * @access private + * @access protected * @return void */ - private function _set_boundaries() + protected function _set_boundaries() { $this->_alt_boundary = "B_ALT_".uniqid(''); // multipart/alternative $this->_atc_boundary = "B_ATC_".uniqid(''); // attachment boundary @@ -591,10 +604,10 @@ class CI_Email { /** * Get the Message ID * - * @access private + * @access protected * @return string */ - private function _get_message_id() + protected function _get_message_id() { $from = $this->_headers['Return-Path']; $from = str_replace(">", "", $from); @@ -608,11 +621,11 @@ class CI_Email { /** * Get Mail Protocol * - * @access private + * @access protected * @param bool * @return string */ - private function _get_protocol($return = TRUE) + protected function _get_protocol($return = TRUE) { $this->protocol = strtolower($this->protocol); $this->protocol = ( ! in_array($this->protocol, $this->_protocols, TRUE)) ? 'mail' : $this->protocol; @@ -628,11 +641,11 @@ class CI_Email { /** * Get Mail Encoding * - * @access private + * @access protected * @param bool * @return string */ - private function _get_encoding($return = TRUE) + protected function _get_encoding($return = TRUE) { $this->_encoding = ( ! in_array($this->_encoding, $this->_bit_depths)) ? '8bit' : $this->_encoding; @@ -655,10 +668,10 @@ class CI_Email { /** * Get content type (text/html/attachment) * - * @access private + * @access protected * @return string */ - private function _get_content_type() + protected function _get_content_type() { if ($this->mailtype == 'html' && count($this->_attach_name) == 0) { @@ -683,10 +696,10 @@ class CI_Email { /** * Set RFC 822 Date * - * @access private + * @access protected * @return string */ - private function _set_date() + protected function _set_date() { $timezone = date("Z"); $operator = (strncmp($timezone, '-', 1) == 0) ? '-' : '+'; @@ -701,10 +714,10 @@ class CI_Email { /** * Mime message * - * @access private + * @access protected * @return string */ - private function _get_mime_message() + protected function _get_mime_message() { return "This is a multi-part message in MIME format.".$this->newline."Your email application may not support this format."; } @@ -802,10 +815,10 @@ class CI_Email { * If the user hasn't specified his own alternative message * it creates one by stripping the HTML * - * @access private + * @access protected * @return string */ - private function _get_alt_message() + protected function _get_alt_message() { if ($this->alt_message != "") { @@ -941,11 +954,11 @@ class CI_Email { /** * Build final headers * - * @access private + * @access protected * @param string * @return string */ - private function _build_headers() + protected function _build_headers() { $this->_set_header('X-Sender', $this->clean_email($this->_headers['From'])); $this->_set_header('X-Mailer', $this->useragent); @@ -959,10 +972,10 @@ class CI_Email { /** * Write Headers as a string * - * @access private + * @access protected * @return void */ - private function _write_headers() + protected function _write_headers() { if ($this->protocol == 'mail') { @@ -994,10 +1007,10 @@ class CI_Email { /** * Build Final Body and attachments * - * @access private + * @access protected * @return void */ - private function _build_message() + protected function _build_message() { if ($this->wordwrap === TRUE AND $this->mailtype != 'html') { @@ -1177,12 +1190,12 @@ class CI_Email { * Prepares string for Quoted-Printable Content-Transfer-Encoding * Refer to RFC 2045 http://www.ietf.org/rfc/rfc2045.txt * - * @access private + * @access protected * @param string * @param integer * @return string */ - private function _prep_quoted_printable($str, $charlim = '') + protected function _prep_quoted_printable($str, $charlim = '') { // Set the character limit // Don't allow over 76, as that will make servers and MUAs barf @@ -1275,7 +1288,7 @@ class CI_Email { * @param bool // set to TRUE for processing From: headers * @return str */ - private function _prep_q_encoding($str, $from = FALSE) + protected function _prep_q_encoding($str, $from = FALSE) { $str = str_replace(array("\r", "\n"), array('', ''), $str); @@ -1440,10 +1453,10 @@ class CI_Email { /** * Unwrap special elements * - * @access private + * @access protected * @return void */ - private function _unwrap_specials() + protected function _unwrap_specials() { $this->_finalbody = preg_replace_callback("/\{unwrap\}(.*?)\{\/unwrap\}/si", array($this, '_remove_nl_callback'), $this->_finalbody); } @@ -1453,10 +1466,10 @@ class CI_Email { /** * Strip line-breaks via callback * - * @access private + * @access protected * @return string */ - private function _remove_nl_callback($matches) + protected function _remove_nl_callback($matches) { if (strpos($matches[1], "\r") !== FALSE OR strpos($matches[1], "\n") !== FALSE) { @@ -1471,10 +1484,10 @@ class CI_Email { /** * Spool mail to the mail server * - * @access private + * @access protected * @return bool */ - private function _spool_email() + protected function _spool_email() { $this->_unwrap_specials(); @@ -1516,10 +1529,10 @@ class CI_Email { /** * Send using mail() * - * @access private + * @access protected * @return bool */ - private function _send_with_mail() + protected function _send_with_mail() { if ($this->_safe_mode == TRUE) { @@ -1553,10 +1566,10 @@ class CI_Email { /** * Send using Sendmail * - * @access private + * @access protected * @return bool */ - private function _send_with_sendmail() + protected function _send_with_sendmail() { $fp = @popen($this->mailpath . " -oi -f ".$this->clean_email($this->_headers['From'])." -t", 'w'); @@ -1591,10 +1604,10 @@ class CI_Email { /** * Send using SMTP * - * @access private + * @access protected * @return bool */ - private function _send_with_smtp() + protected function _send_with_smtp() { if ($this->smtp_host == '') { @@ -1660,13 +1673,16 @@ class CI_Email { /** * SMTP Connect * - * @access private + * @access protected * @param string * @return string */ - private function _smtp_connect() + protected function _smtp_connect() { - $this->_smtp_connect = fsockopen($this->smtp_host, + $ssl = NULL; + if ($this->smtp_crypto == 'ssl') + $ssl = 'ssl://'; + $this->_smtp_connect = fsockopen($ssl.$this->smtp_host, $this->smtp_port, $errno, $errstr, @@ -1679,6 +1695,14 @@ class CI_Email { } $this->_set_error_message($this->_get_smtp_data()); + + if ($this->smtp_crypto == 'tls') + { + $this->_send_command('hello'); + $this->_send_command('starttls'); + stream_socket_enable_crypto($this->_smtp_connect, TRUE, STREAM_CRYPTO_METHOD_TLS_CLIENT); + } + return $this->_send_command('hello'); } @@ -1687,12 +1711,12 @@ class CI_Email { /** * Send SMTP command * - * @access private + * @access protected * @param string * @param string * @return string */ - private function _send_command($cmd, $data = '') + protected function _send_command($cmd, $data = '') { switch ($cmd) { @@ -1705,6 +1729,12 @@ class CI_Email { $resp = 250; break; + case 'starttls' : + + $this->_send_data('STARTTLS'); + + $resp = 220; + break; case 'from' : $this->_send_data('MAIL FROM:<'.$data.'>'); @@ -1754,10 +1784,10 @@ class CI_Email { /** * SMTP Authenticate * - * @access private + * @access protected * @return bool */ - private function _smtp_authenticate() + protected function _smtp_authenticate() { if ( ! $this->_smtp_auth) { @@ -1808,10 +1838,10 @@ class CI_Email { /** * Send SMTP data * - * @access private + * @access protected * @return bool */ - private function _send_data($data) + protected function _send_data($data) { if ( ! fwrite($this->_smtp_connect, $data . $this->newline)) { @@ -1829,10 +1859,10 @@ class CI_Email { /** * Get SMTP data * - * @access private + * @access protected * @return string */ - private function _get_smtp_data() + protected function _get_smtp_data() { $data = ""; @@ -1854,10 +1884,10 @@ class CI_Email { /** * Get Hostname * - * @access private + * @access protected * @return string */ - private function _get_hostname() + protected function _get_hostname() { return (isset($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : 'localhost.localdomain'; } @@ -1867,10 +1897,10 @@ class CI_Email { /** * Get IP * - * @access private + * @access protected * @return string */ - private function _get_ip() + protected function _get_ip() { if ($this->_IP !== FALSE) { @@ -1933,11 +1963,11 @@ class CI_Email { /** * Set Message * - * @access private + * @access protected * @param string * @return string */ - private function _set_error_message($msg, $val = '') + protected function _set_error_message($msg, $val = '') { $CI =& get_instance(); $CI->lang->load('email'); @@ -1957,11 +1987,11 @@ class CI_Email { /** * Mime Types * - * @access private + * @access protected * @param string * @return string */ - private function _mime_types($ext = "") + protected function _mime_types($ext = "") { $mimes = array( 'hqx' => 'application/mac-binhex40', 'cpt' => 'application/mac-compactpro', |