diff options
Diffstat (limited to 'system/libraries/Email.php')
-rw-r--r-- | system/libraries/Email.php | 84 |
1 files changed, 51 insertions, 33 deletions
diff --git a/system/libraries/Email.php b/system/libraries/Email.php index ebb969288..ab3a24893 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1,4 +1,4 @@ -<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
@@ -329,8 +329,15 @@ class CI_Email { */
function subject($subject)
{
- $subject = preg_replace("/(\r\n)|(\r)|(\n)/", "", $subject);
- $subject = preg_replace("/(\t)/", " ", $subject);
+ if (strpos($subject, "\r") !== FALSE OR strpos($subject, "\n") !== FALSE)
+ {
+ $subject = str_replace(array("\r\n", "\r", "\n"), '', $subject);
+ }
+
+ if (strpos($subject, "\t"))
+ {
+ $subject = str_replace("\t", ' ', $subject);
+ }
$this->_set_header('Subject', trim($subject));
}
@@ -391,7 +398,7 @@ class CI_Email { */
function _str_to_array($email)
{
- if (! is_array($email))
+ if ( ! is_array($email))
{
if (strpos($email, ',') !== FALSE)
{
@@ -459,7 +466,7 @@ class CI_Email { */
function set_protocol($protocol = 'mail')
{
- $this->protocol = (! in_array($protocol, $this->_protocols, TRUE)) ? 'mail' : strtolower($protocol);
+ $this->protocol = ( ! in_array($protocol, $this->_protocols, TRUE)) ? 'mail' : strtolower($protocol);
}
// --------------------------------------------------------------------
@@ -473,7 +480,7 @@ class CI_Email { */
function set_priority($n = 3)
{
- if (! is_numeric($n))
+ if ( ! is_numeric($n))
{
$this->priority = 3;
return;
@@ -571,7 +578,7 @@ class CI_Email { function _get_protocol($return = TRUE)
{
$this->protocol = strtolower($this->protocol);
- $this->protocol = (! in_array($this->protocol, $this->_protocols, TRUE)) ? 'mail' : $this->protocol;
+ $this->protocol = ( ! in_array($this->protocol, $this->_protocols, TRUE)) ? 'mail' : $this->protocol;
if ($return == TRUE)
{
@@ -590,7 +597,7 @@ class CI_Email { */
function _get_encoding($return = TRUE)
{
- $this->_encoding = (! in_array($this->_encoding, $this->_bit_depths)) ? '8bit' : $this->_encoding;
+ $this->_encoding = ( ! in_array($this->_encoding, $this->_bit_depths)) ? '8bit' : $this->_encoding;
foreach ($this->_base_charsets as $charset)
{
@@ -676,7 +683,7 @@ class CI_Email { */
function validate_email($email)
{
- if (! is_array($email))
+ if ( ! is_array($email))
{
$this->_set_error_message('email_must_be_array');
return FALSE;
@@ -684,7 +691,7 @@ class CI_Email { foreach ($email as $val)
{
- if (! $this->valid_email($val))
+ if ( ! $this->valid_email($val))
{
$this->_set_error_message('email_invalid_address', $val);
return FALSE;
@@ -703,7 +710,7 @@ class CI_Email { */
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 ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) ? FALSE : TRUE;
}
// --------------------------------------------------------------------
@@ -717,7 +724,7 @@ class CI_Email { */
function clean_email($email)
{
- if (! is_array($email))
+ if ( ! is_array($email))
{
if (preg_match('/\<(.*)\>/', $email, $match))
{
@@ -816,7 +823,10 @@ class CI_Email { $str = preg_replace("| +|", " ", $str);
// Standardize newlines
- $str = preg_replace("/\r\n|\r/", "\n", $str);
+ if (strpos($str, "\r") !== FALSE)
+ {
+ $str = str_replace(array("\r\n", "\r"), "\n", $str);
+ }
// If the current word is surrounded by {unwrap} tags we'll
// strip the entire chunk and replace it with a marker.
@@ -857,7 +867,7 @@ class CI_Email { }
// Trim the word down
- $temp .= ($line, 0, $charlim-1);
+ $temp .= substr($line, 0, $charlim-1);
$line = substr($line, $charlim-1);
}
@@ -1089,7 +1099,7 @@ class CI_Email { $basename = basename($filename);
$ctype = $this->_attach_type[$i];
- if (! file_exists($filename))
+ if ( ! file_exists($filename))
{
$this->_set_error_message('email_attachment_missing', $filename);
return FALSE;
@@ -1104,7 +1114,7 @@ class CI_Email { $attachment[$z++] = $h;
$file = filesize($filename) +1;
- if (! $fp = fopen($filename, FOPEN_READ))
+ if ( ! $fp = fopen($filename, FOPEN_READ))
{
$this->_set_error_message('email_attachment_unreadable', $filename);
return FALSE;
@@ -1153,7 +1163,10 @@ class CI_Email { $str = preg_replace("| +|", " ", $str);
// Standardize newlines
- $str = preg_replace("/\r\n|\r/", "\n", $str);
+ if (strpos($str, "\r") !== FALSE)
+ {
+ $str = str_replace(array("\r\n", "\r"), "\n", $str);
+ }
// We are intentionally wrapping so mail servers will encode characters
// properly and MUAs will behave, so {unwrap} must go!
@@ -1228,9 +1241,9 @@ class CI_Email { $this->reply_to($this->_headers['From']);
}
- if ((! isset($this->_recipients) AND ! isset($this->_headers['To'])) AND
- (! isset($this->_bcc_array) AND ! isset($this->_headers['Bcc'])) AND
- (! isset($this->_headers['Cc'])))
+ if (( ! isset($this->_recipients) AND ! isset($this->_headers['To'])) AND
+ ( ! isset($this->_bcc_array) AND ! isset($this->_headers['Bcc'])) AND
+ ( ! isset($this->_headers['Cc'])))
{
$this->_set_error_message('email_no_recipients');
return FALSE;
@@ -1246,7 +1259,7 @@ class CI_Email { $this->_build_message();
- if (! $this->_spool_email())
+ if ( ! $this->_spool_email())
{
return FALSE;
}
@@ -1338,7 +1351,12 @@ class CI_Email { */
function _remove_nl_callback($matches)
{
- return preg_replace("/(\r\n)|(\r)|(\n)/", "", $matches['1']);
+ if (strpos($matches[1], "\r") !== FALSE OR strpos($matches[1], "\n") !== FALSE)
+ {
+ $matches[1] = str_replace(array("\r\n", "\r", "\n"), '', $matches[1]);
+ }
+
+ return $matches[1];
}
// --------------------------------------------------------------------
@@ -1357,7 +1375,7 @@ class CI_Email { {
case 'mail' :
- if (! $this->_send_with_mail())
+ if ( ! $this->_send_with_mail())
{
$this->_set_error_message('email_send_failure_phpmail');
return FALSE;
@@ -1365,7 +1383,7 @@ class CI_Email { break;
case 'sendmail' :
- if (! $this->_send_with_sendmail())
+ if ( ! $this->_send_with_sendmail())
{
$this->_set_error_message('email_send_failure_sendmail');
return FALSE;
@@ -1373,7 +1391,7 @@ class CI_Email { break;
case 'smtp' :
- if (! $this->_send_with_smtp())
+ if ( ! $this->_send_with_smtp())
{
$this->_set_error_message('email_send_failure_smtp');
return FALSE;
@@ -1398,7 +1416,7 @@ class CI_Email { {
if ($this->_safe_mode == TRUE)
{
- if (! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str))
+ if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str))
return FALSE;
else
return TRUE;
@@ -1407,7 +1425,7 @@ class CI_Email { {
// 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.
- if (! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, "-f ".$this->clean_email($this->_headers['From'])))
+ if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, "-f ".$this->clean_email($this->_headers['From'])))
return FALSE;
else
return TRUE;
@@ -1426,7 +1444,7 @@ class CI_Email { {
$fp = @popen($this->mailpath . " -oi -f ".$this->clean_email($this->_headers['From'])." -t", 'w');
- if (! is_resource($fp))
+ if ( ! is_resource($fp))
{
$this->_set_error_message('email_no_socket');
return FALSE;
@@ -1519,7 +1537,7 @@ class CI_Email { $errstr,
$this->smtp_timeout);
- if(! is_resource($this->_smtp_connect))
+ if( ! is_resource($this->_smtp_connect))
{
$this->_set_error_message('email_smtp_error', $errno." ".$errstr);
return FALSE;
@@ -1606,7 +1624,7 @@ class CI_Email { */
function _smtp_authenticate()
{
- if (! $this->_smtp_auth)
+ if ( ! $this->_smtp_auth)
{
return TRUE;
}
@@ -1660,7 +1678,7 @@ class CI_Email { */
function _send_data($data)
{
- if (! fwrite($this->_smtp_connect, $data . $this->newline))
+ if ( ! fwrite($this->_smtp_connect, $data . $this->newline))
{
$this->_set_error_message('email_smtp_data_failure', $data);
return FALSE;
@@ -1739,7 +1757,7 @@ class CI_Email { $this->_IP = end($x);
}
- if (! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $this->_IP))
+ if ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $this->_IP))
{
$this->_IP = '0.0.0.0';
}
@@ -1899,7 +1917,7 @@ class CI_Email { 'eml' => 'message/rfc822'
);
- return (! isset($mimes[strtolower($ext)])) ? "application/x-unknown-content-type" : $mimes[strtolower($ext)];
+ return ( ! isset($mimes[strtolower($ext)])) ? "application/x-unknown-content-type" : $mimes[strtolower($ext)];
}
}
|