From 83320ebb3b607f21410fcacbfb32c360ec55197d Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Thu, 15 Sep 2011 13:28:02 +0800 Subject: Update: Incorrect comments for clean method in CI_Email class --- system/libraries/Email.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 28a3d17b4..c8cb8549e 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -138,6 +138,7 @@ class CI_Email { * Initialize the Email Data * * @access public + * @param bool * @return void */ public function clear($clear_attachments = FALSE) -- cgit v1.2.3-24-g4f1b From bbf04b011bd30c9c67970aa5a5049a32a01474b4 Mon Sep 17 00:00:00 2001 From: Radu Potop Date: Wed, 28 Sep 2011 13:57:51 +0300 Subject: Added TLS and SSL support to Email library. Fixes issue #171 --- system/libraries/Email.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index c8cb8549e..648bb6b4d 100644 --- 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 @@ -1667,7 +1668,10 @@ class CI_Email { */ 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, @@ -1680,6 +1684,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'); } @@ -1706,6 +1718,12 @@ class CI_Email { $resp = 250; break; + case 'starttls' : + + $this->_send_data('STARTTLS'); + + $resp = 220; + break; case 'from' : $this->_send_data('MAIL FROM:<'.$data.'>'); -- cgit v1.2.3-24-g4f1b From 4c589aed7b0215e3d4105b11776bc45f299d291d Mon Sep 17 00:00:00 2001 From: Radu Potop Date: Thu, 29 Sep 2011 10:19:55 +0300 Subject: style edit, print error if crypto fails --- system/libraries/Email.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 648bb6b4d..ef20e1978 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1669,8 +1669,12 @@ class CI_Email { protected function _smtp_connect() { $ssl = NULL; + if ($this->smtp_crypto == 'ssl') + { $ssl = 'ssl://'; + } + $this->_smtp_connect = fsockopen($ssl.$this->smtp_host, $this->smtp_port, $errno, @@ -1689,7 +1693,13 @@ class CI_Email { { $this->_send_command('hello'); $this->_send_command('starttls'); - stream_socket_enable_crypto($this->_smtp_connect, TRUE, STREAM_CRYPTO_METHOD_TLS_CLIENT); + $crypto = stream_socket_enable_crypto($this->_smtp_connect, TRUE, STREAM_CRYPTO_METHOD_TLS_CLIENT); + } + + if ($crypto !== TRUE) + { + $this->_set_error_message('lang:email_smtp_error', $this->_get_smtp_data()); + return FALSE; } return $this->_send_command('hello'); -- cgit v1.2.3-24-g4f1b From 33c3280d902bbe46096c3e2036ebbcce877219ae Mon Sep 17 00:00:00 2001 From: diegorivera Date: Wed, 19 Oct 2011 02:56:15 -0200 Subject: Update system/libraries/Email.php --- system/libraries/Email.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index ef20e1978..73ff2e7d1 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -381,7 +381,15 @@ 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. + if (get_magic_quotes_gpc()) + { + $this->_body = stripslashes($this->_body); + } + return $this; } -- cgit v1.2.3-24-g4f1b From 9fca615492ba481f5c27890b3b61f0603f45c55b Mon Sep 17 00:00:00 2001 From: diegorivera Date: Wed, 19 Oct 2011 11:18:45 -0200 Subject: I wasn't following the CI code style guide. --- system/libraries/Email.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 73ff2e7d1..c7d0bc52b 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -385,10 +385,10 @@ class CI_Email { //strip slashes only if magic quotes is ON //if we do it with magic quotes OFF, it strips real, user-inputted chars. - if (get_magic_quotes_gpc()) - { + if (get_magic_quotes_gpc()) + { $this->_body = stripslashes($this->_body); - } + } return $this; } -- cgit v1.2.3-24-g4f1b From af7286251ec2c0dfd69ae764dbc0e3e8d0b736bf Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 20 Oct 2011 10:11:59 +0300 Subject: get_magic_quotes_gpc() to be executed only if PHP version is 5.3 or lower --- system/libraries/Email.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index c7d0bc52b..83a4eefb1 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -383,9 +383,13 @@ class CI_Email { { $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. - if (get_magic_quotes_gpc()) + /* 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); } -- cgit v1.2.3-24-g4f1b From f4a4bd8fac188ebc9cda822ffc811c218fd92b45 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 20 Oct 2011 12:18:42 -0500 Subject: adding new license file (OSL 3.0) and updating readme to ReST added notice of license to all source files. OSL to all except the few files we ship inside of the application folder, those are AFL. Updated license in user guide. incrementing next dev version to 3.0 due to licensing change --- system/libraries/Email.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 83a4eefb1..db6ea8f90 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -4,10 +4,22 @@ * * An open source application development framework for PHP 5.1.6 or newer * + * NOTICE OF LICENSE + * + * Licensed under the Open Software License version 3.0 + * + * This source file is subject to the Open Software License (OSL 3.0) that is + * bundled with this package in the files license.txt / license.rst. It is + * also available through the world wide web at this URL: + * http://opensource.org/licenses/OSL-3.0 + * If you did not receive a copy of the license and are unable to obtain it + * through the world wide web, please send an email to + * licensing@ellislab.com so we can send you a copy immediately. + * * @package CodeIgniter - * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. - * @license http://codeigniter.com/user_guide/license.html + * @author EllisLab Dev Team + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 * @filesource @@ -23,7 +35,7 @@ * @package CodeIgniter * @subpackage Libraries * @category Libraries - * @author ExpressionEngine Dev Team + * @author EllisLab Dev Team * @link http://codeigniter.com/user_guide/libraries/email.html */ class CI_Email { -- cgit v1.2.3-24-g4f1b From 13095cbc1b1b0509ac8c984e7a5fd704d9826569 Mon Sep 17 00:00:00 2001 From: diegorivera Date: Wed, 19 Oct 2011 02:56:15 -0200 Subject: Update system/libraries/Email.php --- system/libraries/Email.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index e28c23a04..2916b9a13 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -379,7 +379,15 @@ 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. + if (get_magic_quotes_gpc()) + { + $this->_body = stripslashes($this->_body); + } + return $this; } -- cgit v1.2.3-24-g4f1b From 6eab49a844b3542a5efee6620233a86f645a30f5 Mon Sep 17 00:00:00 2001 From: diegorivera Date: Wed, 19 Oct 2011 11:18:45 -0200 Subject: I wasn't following the CI code style guide. --- system/libraries/Email.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 2916b9a13..5f8d48682 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -383,10 +383,10 @@ class CI_Email { //strip slashes only if magic quotes is ON //if we do it with magic quotes OFF, it strips real, user-inputted chars. - if (get_magic_quotes_gpc()) - { + if (get_magic_quotes_gpc()) + { $this->_body = stripslashes($this->_body); - } + } return $this; } -- cgit v1.2.3-24-g4f1b From 75b1f3991013c17cacac18e47879c483fe1cf542 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 20 Oct 2011 10:11:59 +0300 Subject: get_magic_quotes_gpc() to be executed only if PHP version is 5.3 or lower --- system/libraries/Email.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 5f8d48682..c8b727c34 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -381,9 +381,13 @@ class CI_Email { { $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. - if (get_magic_quotes_gpc()) + /* 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); } -- cgit v1.2.3-24-g4f1b From e862ddd7c33cc41f306d21725c93170daf864c52 Mon Sep 17 00:00:00 2001 From: Sean Fisher Date: Wed, 26 Oct 2011 22:45:00 -0300 Subject: Crypt isn't set and it causes extensive script time when specifying a custom SMTP server --- system/libraries/Email.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index db6ea8f90..6739db33b 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1718,12 +1718,12 @@ class CI_Email { $this->_send_command('hello'); $this->_send_command('starttls'); $crypto = stream_socket_enable_crypto($this->_smtp_connect, TRUE, STREAM_CRYPTO_METHOD_TLS_CLIENT); - } - if ($crypto !== TRUE) - { - $this->_set_error_message('lang:email_smtp_error', $this->_get_smtp_data()); - return FALSE; + if ($crypto !== TRUE) + { + $this->_set_error_message('lang:email_smtp_error', $this->_get_smtp_data()); + return FALSE; + } } return $this->_send_command('hello'); -- cgit v1.2.3-24-g4f1b From c78301cee7b648911601f663731ddb4871d1bba4 Mon Sep 17 00:00:00 2001 From: Radu Potop Date: Wed, 28 Sep 2011 13:57:51 +0300 Subject: Added TLS and SSL support to Email library. Fixes issue #171 --- system/libraries/Email.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index c8b727c34..9ec40af9d 100644 --- 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 @@ -1678,7 +1679,10 @@ class CI_Email { */ 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, @@ -1691,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'); } @@ -1717,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.'>'); -- cgit v1.2.3-24-g4f1b From 0aae75388cef0a41931c491dfef7deb0a18fa101 Mon Sep 17 00:00:00 2001 From: trit Date: Wed, 23 Nov 2011 06:54:25 -0500 Subject: Added custom file name to attach(), updated _build_message to handle it --- system/libraries/Email.php | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 7bde4c4fd..b898bae2a 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -38,7 +38,7 @@ * @author EllisLab Dev Team * @link http://codeigniter.com/user_guide/libraries/email.html */ -class CI_Email { +class CI_Email{ var $useragent = "CodeIgniter"; var $mailpath = "/usr/sbin/sendmail"; // Sendmail path @@ -418,9 +418,9 @@ class CI_Email { * @param string * @return void */ - public function attach($filename, $disposition = 'attachment') + public function attach($filepath, $filename=NULL, $disposition = 'attachment') { - $this->_attach_name[] = $filename; + $this->_attach_name[] = array($filepath, $filename); $this->_attach_type[] = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION)); $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters return $this; @@ -1151,13 +1151,19 @@ class CI_Email { for ($i=0; $i < count($this->_attach_name); $i++) { - $filename = $this->_attach_name[$i]; - $basename = basename($filename); + $filepath = $this->_attach_name[$i][0]; + $basename = $this->_attach_name[$i][1]; + + if( ! $basename) + { + $basename = basename($filename); + } + $ctype = $this->_attach_type[$i]; - if ( ! file_exists($filename)) + if ( ! file_exists($filepath)) { - $this->_set_error_message('lang:email_attachment_missing', $filename); + $this->_set_error_message('lang:email_attachment_missing', $filepath); return FALSE; } @@ -1168,11 +1174,11 @@ class CI_Email { $h .= "Content-Transfer-Encoding: base64".$this->newline; $attachment[$z++] = $h; - $file = filesize($filename) +1; + $file = filesize($filepath) +1; - if ( ! $fp = fopen($filename, FOPEN_READ)) + if ( ! $fp = fopen($filepath, FOPEN_READ)) { - $this->_set_error_message('lang:email_attachment_unreadable', $filename); + $this->_set_error_message('lang:email_attachment_unreadable', $filepath); return FALSE; } -- cgit v1.2.3-24-g4f1b From a1dc1f94e1186f60211fca07addd829ef2ebd19c Mon Sep 17 00:00:00 2001 From: trit Date: Wed, 23 Nov 2011 07:00:09 -0500 Subject: Fixed variable name causing problem --- system/libraries/Email.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index b898bae2a..6be294377 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1156,7 +1156,7 @@ class CI_Email{ if( ! $basename) { - $basename = basename($filename); + $basename = basename($filepath); } $ctype = $this->_attach_type[$i]; -- cgit v1.2.3-24-g4f1b From bc4ac992d1d609c559884e5164b2c51fb0c1fc89 Mon Sep 17 00:00:00 2001 From: trit Date: Wed, 23 Nov 2011 07:19:41 -0500 Subject: Changed filepath back to filename --- system/libraries/Email.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 6be294377..f2670f961 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1151,19 +1151,19 @@ class CI_Email{ for ($i=0; $i < count($this->_attach_name); $i++) { - $filepath = $this->_attach_name[$i][0]; + $filename = $this->_attach_name[$i][0]; $basename = $this->_attach_name[$i][1]; if( ! $basename) { - $basename = basename($filepath); + $basename = basename($filename); } $ctype = $this->_attach_type[$i]; - if ( ! file_exists($filepath)) + if ( ! file_exists($filename)) { - $this->_set_error_message('lang:email_attachment_missing', $filepath); + $this->_set_error_message('lang:email_attachment_missing', $filename); return FALSE; } @@ -1174,11 +1174,11 @@ class CI_Email{ $h .= "Content-Transfer-Encoding: base64".$this->newline; $attachment[$z++] = $h; - $file = filesize($filepath) +1; + $file = filesize($filename) +1; - if ( ! $fp = fopen($filepath, FOPEN_READ)) + if ( ! $fp = fopen($filename, FOPEN_READ)) { - $this->_set_error_message('lang:email_attachment_unreadable', $filepath); + $this->_set_error_message('lang:email_attachment_unreadable', $filename); return FALSE; } -- cgit v1.2.3-24-g4f1b From 151fc68508658ef342f7ad53187ca28d9ec15c97 Mon Sep 17 00:00:00 2001 From: trit Date: Wed, 23 Nov 2011 07:30:06 -0500 Subject: Changed the names around again --- system/libraries/Email.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index f2670f961..8f2ca62ea 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -418,9 +418,9 @@ class CI_Email{ * @param string * @return void */ - public function attach($filepath, $filename=NULL, $disposition = 'attachment') + public function attach($filename, $newname=NULL, $disposition = 'attachment') { - $this->_attach_name[] = array($filepath, $filename); + $this->_attach_name[] = array($filename, $newname); $this->_attach_type[] = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION)); $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters return $this; -- cgit v1.2.3-24-g4f1b From 2ca47a99bd7ec44c0b4c9df6aa7364e11492e081 Mon Sep 17 00:00:00 2001 From: trit Date: Wed, 23 Nov 2011 07:32:34 -0500 Subject: Switched order of arguments to maintain compatibility --- system/libraries/Email.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 8f2ca62ea..d81fd44dc 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -418,7 +418,7 @@ class CI_Email{ * @param string * @return void */ - public function attach($filename, $newname=NULL, $disposition = 'attachment') + public function attach($filename, $disposition = 'attachment', $newname=NULL) { $this->_attach_name[] = array($filename, $newname); $this->_attach_type[] = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION)); -- cgit v1.2.3-24-g4f1b From a15dd4f52933dff11b5b542d16d8e49a973a0e89 Mon Sep 17 00:00:00 2001 From: trit Date: Wed, 23 Nov 2011 07:40:05 -0500 Subject: Added space after CI_Email for coding standard --- system/libraries/Email.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index d81fd44dc..d24a30493 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -38,7 +38,7 @@ * @author EllisLab Dev Team * @link http://codeigniter.com/user_guide/libraries/email.html */ -class CI_Email{ +class CI_Email { var $useragent = "CodeIgniter"; var $mailpath = "/usr/sbin/sendmail"; // Sendmail path -- cgit v1.2.3-24-g4f1b From 7f42519fd156a541bdb3517b517287f3352b5e49 Mon Sep 17 00:00:00 2001 From: trit Date: Wed, 23 Nov 2011 15:19:49 -0500 Subject: Added a couple of style tweaks and a note about function change in changelog --- system/libraries/Email.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index d24a30493..e012545d9 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -418,7 +418,7 @@ class CI_Email { * @param string * @return void */ - public function attach($filename, $disposition = 'attachment', $newname=NULL) + public function attach($filename, $disposition = 'attachment', $newname = NULL) { $this->_attach_name[] = array($filename, $newname); $this->_attach_type[] = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION)); @@ -1152,12 +1152,7 @@ class CI_Email { for ($i=0; $i < count($this->_attach_name); $i++) { $filename = $this->_attach_name[$i][0]; - $basename = $this->_attach_name[$i][1]; - - if( ! $basename) - { - $basename = basename($filename); - } + $basename = is_null($this->_attach_name[$i][1]) ? basename($filename) : $this->_attach_name[$i][1]; $ctype = $this->_attach_type[$i]; -- cgit v1.2.3-24-g4f1b From 10eb14d37a4399f7ed4dfa212feef07e2041f889 Mon Sep 17 00:00:00 2001 From: trit Date: Wed, 23 Nov 2011 15:48:21 -0500 Subject: Changed attachment definition to allow for blank disposition defaulting to attachment - should make things easier for the user who uses a custom name --- system/libraries/Email.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index e012545d9..a24ce7440 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -418,8 +418,10 @@ class CI_Email { * @param string * @return void */ - public function attach($filename, $disposition = 'attachment', $newname = NULL) + public function attach($filename, $disposition = '', $newname = NULL) { + if(empty($disposition)) + $disposition = 'attachment'; $this->_attach_name[] = array($filename, $newname); $this->_attach_type[] = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION)); $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters @@ -1152,7 +1154,7 @@ class CI_Email { for ($i=0; $i < count($this->_attach_name); $i++) { $filename = $this->_attach_name[$i][0]; - $basename = is_null($this->_attach_name[$i][1]) ? basename($filename) : $this->_attach_name[$i][1]; + $basename = ( is_null($this->_attach_name[$i][1]) ? basename($filename) : $this->_attach_name[$i][1] ); $ctype = $this->_attach_type[$i]; -- cgit v1.2.3-24-g4f1b From b2b510dd441d6fc450c046a2fcb0b3742d6a7e04 Mon Sep 17 00:00:00 2001 From: trit Date: Wed, 23 Nov 2011 15:51:08 -0500 Subject: More style tweaks --- system/libraries/Email.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index a24ce7440..3c679ce48 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -421,7 +421,10 @@ class CI_Email { public function attach($filename, $disposition = '', $newname = NULL) { if(empty($disposition)) + { $disposition = 'attachment'; + } + $this->_attach_name[] = array($filename, $newname); $this->_attach_type[] = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION)); $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters -- cgit v1.2.3-24-g4f1b From d52699842f598d185b1388f4c6b72d2d63e21e64 Mon Sep 17 00:00:00 2001 From: trit Date: Wed, 23 Nov 2011 17:22:44 -0500 Subject: Switch disposition set to ternary operation --- system/libraries/Email.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 3c679ce48..631b62e86 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -420,14 +420,9 @@ class CI_Email { */ public function attach($filename, $disposition = '', $newname = NULL) { - if(empty($disposition)) - { - $disposition = 'attachment'; - } - $this->_attach_name[] = array($filename, $newname); $this->_attach_type[] = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION)); - $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters + $this->_attach_disp[] = empty($disposition) ? 'attachment' : $disposition; // Can also be 'inline' Not sure if it matters return $this; } -- cgit v1.2.3-24-g4f1b From 1bd3d887057ce807944188f8f18142c14418b2ea Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 22 Dec 2011 15:38:20 +0200 Subject: Improve the Email library --- system/libraries/Email.php | 480 ++++++++++++++++----------------------------- 1 file changed, 172 insertions(+), 308 deletions(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 631b62e86..5158e859c 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1,13 +1,13 @@ -_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; - $this->_safe_mode = ((boolean)@ini_get("safe_mode") === FALSE) ? FALSE : TRUE; + $this->_safe_mode = (bool) @ini_get("safe_mode"); } log_message('debug', "Email Class Initialized"); @@ -140,7 +140,7 @@ class CI_Email { $this->clear(); $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; - $this->_safe_mode = ((boolean)@ini_get("safe_mode") === FALSE) ? FALSE : TRUE; + $this->_safe_mode = (bool) @ini_get("safe_mode"); return $this; } @@ -194,7 +194,7 @@ class CI_Email { { if (preg_match( '/\<(.*)\>/', $from, $match)) { - $from = $match['1']; + $from = $match[1]; } if ($this->validate) @@ -237,7 +237,7 @@ class CI_Email { { if (preg_match( '/\<(.*)\>/', $replyto, $match)) { - $replyto = $match['1']; + $replyto = $match[1]; } if ($this->validate) @@ -250,7 +250,7 @@ class CI_Email { $name = $replyto; } - if (strncmp($name, '"', 1) != 0) + if (strncmp($name, '"', 1) !== 0) { $name = '"'.$name.'"'; } @@ -280,7 +280,7 @@ class CI_Email { $this->validate_email($to); } - if ($this->_get_protocol() != 'mail') + if ($this->_get_protocol() !== 'mail') { $this->_set_header('To', implode(", ", $to)); } @@ -320,7 +320,7 @@ class CI_Email { $this->_set_header('Cc', implode(", ", $cc)); - if ($this->_get_protocol() == "smtp") + if ($this->_get_protocol() === 'smtp') { $this->_cc_array = $cc; } @@ -354,7 +354,7 @@ class CI_Email { $this->validate_email($bcc); } - if (($this->_get_protocol() == "smtp") OR ($this->bcc_batch_mode && count($bcc) > $this->bcc_batch_size)) + if ($this->_get_protocol() === 'smtp' OR ($this->bcc_batch_mode && count($bcc) > $this->bcc_batch_size)) { $this->_bcc_array = $bcc; } @@ -538,19 +538,13 @@ class CI_Email { */ public function set_priority($n = 3) { - if ( ! is_numeric($n)) - { - $this->priority = 3; - return; - } - - if ($n < 1 OR $n > 5) + if ( ! is_numeric($n) OR $n < 1 OR $n > 5) { $this->priority = 3; return; } - $this->priority = $n; + $this->priority = (int) $n; return $this; } @@ -565,14 +559,7 @@ class CI_Email { */ public function set_newline($newline = "\n") { - if ($newline != "\n" AND $newline != "\r\n" AND $newline != "\r") - { - $this->newline = "\n"; - return; - } - - $this->newline = $newline; - + $this->newline = ($newline !== "\n" AND $newline !== "\r\n" AND $newline !== "\r") ? "\n" : $newline; return $this; } @@ -587,14 +574,7 @@ class CI_Email { */ public function set_crlf($crlf = "\n") { - if ($crlf != "\n" AND $crlf != "\r\n" AND $crlf != "\r") - { - $this->crlf = "\n"; - return; - } - - $this->crlf = $crlf; - + $this->crlf = ($crlf !== "\n" AND $crlf !== "\r\n" AND $crlf !== "\r") ? "\n" : $crlf; return $this; } @@ -622,9 +602,7 @@ class CI_Email { */ protected function _get_message_id() { - $from = $this->_headers['Return-Path']; - $from = str_replace(">", "", $from); - $from = str_replace("<", "", $from); + $from = str_replace(array('>', '<'), array('', ''), $this->_headers['Return-Path']); return "<".uniqid('').strstr($from, '@').">"; } @@ -664,7 +642,7 @@ class CI_Email { foreach ($this->_base_charsets as $charset) { - if (strncmp($charset, $this->charset, strlen($charset)) == 0) + if (strncmp($charset, $this->charset, strlen($charset)) === 0) { $this->_encoding = '7bit'; } @@ -686,15 +664,15 @@ class CI_Email { */ protected function _get_content_type() { - if ($this->mailtype == 'html' && count($this->_attach_name) == 0) + if ($this->mailtype === 'html' && count($this->_attach_name) === 0) { return 'html'; } - elseif ($this->mailtype == 'html' && count($this->_attach_name) > 0) + elseif ($this->mailtype === 'html' && count($this->_attach_name) > 0) { return 'html-attach'; } - elseif ($this->mailtype == 'text' && count($this->_attach_name) > 0) + elseif ($this->mailtype === 'text' && count($this->_attach_name) > 0) { return 'plain-attach'; } @@ -715,9 +693,9 @@ class CI_Email { protected function _set_date() { $timezone = date("Z"); - $operator = (strncmp($timezone, '-', 1) == 0) ? '-' : '+'; + $operator = (strncmp($timezone, '-', 1) === 0) ? '-' : '+'; $timezone = abs($timezone); - $timezone = floor($timezone/3600) * 100 + ($timezone % 3600 ) / 60; + $timezone = floor($timezone/3600) * 100 + ($timezone % 3600) / 60; return sprintf("%s %s%04d", date("D, j M Y H:i:s"), $operator, $timezone); } @@ -775,7 +753,7 @@ class CI_Email { */ public 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 (bool) preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address); } // -------------------------------------------------------------------- @@ -791,28 +769,14 @@ class CI_Email { { if ( ! is_array($email)) { - if (preg_match('/\<(.*)\>/', $email, $match)) - { - return $match['1']; - } - else - { - return $email; - } + return (preg_match('/\<(.*)\>/', $email, $match)) ? $match[1] : $email; } $clean_email = array(); foreach ($email as $addy) { - if (preg_match( '/\<(.*)\>/', $addy, $match)) - { - $clean_email[] = $match['1']; - } - else - { - $clean_email[] = $addy; - } + $clean_email[] = (preg_match( '/\<(.*)\>/', $addy, $match)) ? $match[1] : $addy; } return $clean_email; @@ -838,32 +802,15 @@ class CI_Email { return $this->word_wrap($this->alt_message, '76'); } - if (preg_match('/\(.*)\<\/body\>/si', $this->_body, $match)) - { - $body = $match['1']; - } - else - { - $body = $this->_body; - } - - $body = trim(strip_tags($body)); - $body = preg_replace( '#