summaryrefslogtreecommitdiffstats
path: root/system/libraries/Email.php
diff options
context:
space:
mode:
Diffstat (limited to 'system/libraries/Email.php')
-rw-r--r--system/libraries/Email.php232
1 files changed, 79 insertions, 153 deletions
diff --git a/system/libraries/Email.php b/system/libraries/Email.php
index 3b1da8de0..f115d9f40 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;
}
@@ -1036,8 +1016,7 @@ class CI_Email {
{
if (function_exists('idn_to_ascii') && $atpos = strpos($email, '@'))
{
- $variant = defined('INTL_IDNA_VARIANT_UTS46') ? INTL_IDNA_VARIANT_UTS46 : INTL_IDNA_VARIANT_2003;
- $email = self::substr($email, 0, ++$atpos).idn_to_ascii(self::substr($email, $atpos), 0, $variant);
+ $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);
@@ -1256,7 +1235,7 @@ class CI_Email {
/**
* Build Final Body and attachments
*
- * @return bool
+ * @return void
*/
protected function _build_message()
{
@@ -1423,8 +1402,6 @@ class CI_Email {
$this->_finalbody = ($this->_get_protocol() === 'mail')
? $body
: $hdr.$this->newline.$this->newline.$body;
-
- return TRUE;
}
// --------------------------------------------------------------------
@@ -1686,8 +1663,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');
@@ -1698,21 +1675,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)
@@ -1771,11 +1744,7 @@ class CI_Email {
$this->_bcc_array = $bcc;
}
- if ($this->_build_message() === FALSE)
- {
- return FALSE;
- }
-
+ $this->_build_message();
$this->_spool_email();
}
}
@@ -1854,8 +1823,7 @@ class CI_Email {
{
if (function_exists('idn_to_ascii') && $atpos = strpos($email, '@'))
{
- $variant = defined('INTL_IDNA_VARIANT_UTS46') ? INTL_IDNA_VARIANT_UTS46 : INTL_IDNA_VARIANT_2003;
- $email = self::substr($email, 0, ++$atpos).idn_to_ascii(self::substr($email, $atpos), 0, $variant);
+ $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));
@@ -1879,16 +1847,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);
}
// --------------------------------------------------------------------
@@ -1969,27 +1935,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;
}
}
@@ -2003,7 +1963,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);
@@ -2029,9 +1988,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');
}
// --------------------------------------------------------------------
@@ -2050,11 +2007,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))
{
@@ -2095,57 +2054,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();
@@ -2187,7 +2138,6 @@ class CI_Email {
}
$this->_send_data('AUTH LOGIN');
-
$reply = $this->_get_smtp_data();
if (strpos($reply, '503') === 0) // Already authenticated
@@ -2201,7 +2151,6 @@ class CI_Email {
}
$this->_send_data(base64_encode($this->smtp_user));
-
$reply = $this->_get_smtp_data();
if (strpos($reply, '334') !== 0)
@@ -2211,7 +2160,6 @@ class CI_Email {
}
$this->_send_data(base64_encode($this->smtp_pass));
-
$reply = $this->_get_smtp_data();
if (strpos($reply, '235') !== 0)
@@ -2334,34 +2282,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>');
}
@@ -2455,9 +2384,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');
}