Some sweeping syntax changes for consistency:

(! foo) changed to ( ! foo)
|| changed to OR
changed newline standardization code in various places from preg_replace to str_replace
diff --git a/system/libraries/Email.php b/system/libraries/Email.php
index ebb9692..ab3a248 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 @@
 	 */	

 	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 @@
 	 */	

 	function _str_to_array($email)

 	{

-		if (! is_array($email))

+		if ( ! is_array($email))

 		{

 			if (strpos($email, ',') !== FALSE)

 			{

@@ -459,7 +466,7 @@
 	 */	

 	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 @@
 	 */	

 	function set_priority($n = 3)

 	{

-		if (! is_numeric($n))

+		if ( ! is_numeric($n))

 		{

 			$this->priority = 3;

 			return;

@@ -571,7 +578,7 @@
 	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 @@
 	 */	

 	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 @@
 	 */	

 	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 @@
 

 		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 @@
 	 */	

 	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 @@
 	 */	

 	function clean_email($email)

 	{

-		if (! is_array($email))

+		if ( ! is_array($email))

 		{

 			if (preg_match('/\<(.*)\>/', $email, $match))

 			{

@@ -816,7 +823,10 @@
 		$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 @@
 				}

 

 				// Trim the word down

-				$temp .= ($line, 0, $charlim-1);

+				$temp .= substr($line, 0, $charlim-1);

 				$line = substr($line, $charlim-1);

 			}

 	

@@ -1089,7 +1099,7 @@
 			$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 @@
 			$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 @@
 		$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 @@
 			$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 @@
 

 		$this->_build_message();

 

-		if (! $this->_spool_email())

+		if ( ! $this->_spool_email())

 		{

 			return FALSE;

 		}

@@ -1338,7 +1351,12 @@
 	 */	

 	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 @@
 		{

 			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 @@
 			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 @@
 			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 @@
 	{	

 		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 @@
 		{

 			// 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 @@
 	{

 		$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 @@
 										$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 @@
 	 */	

 	function _smtp_authenticate()

 	{	

-		if (! $this->_smtp_auth)

+		if ( ! $this->_smtp_auth)

 		{

 			return TRUE;

 		}

@@ -1660,7 +1678,7 @@
 	 */	

 	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 @@
 			$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 @@
 						'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)];

 	}

 

 }