summaryrefslogtreecommitdiffstats
path: root/system/libraries/Email.php
diff options
context:
space:
mode:
authorDaniel Hunsaker <danhunsaker@gmail.com>2013-02-22 21:49:33 +0100
committerDaniel Hunsaker <danhunsaker@gmail.com>2013-02-22 21:49:33 +0100
commit44a6d1da2be916fe0f23a3ea4d5fcb391d7f65dd (patch)
tree31549ebf6ea5ea98e4347eb640d1caa685316f3e /system/libraries/Email.php
parent353f9834adf3f44c6c7a0f924089bb2b43360404 (diff)
parenteb291c1d1e1116a4420fa30e587adeea0451eeb7 (diff)
Merge branch 'develop' of github.com:EllisLab/CodeIgniter into feature/exit-status
Diffstat (limited to 'system/libraries/Email.php')
-rw-r--r--system/libraries/Email.php55
1 files changed, 52 insertions, 3 deletions
diff --git a/system/libraries/Email.php b/system/libraries/Email.php
index 997757b0a..daa38484b 100644
--- a/system/libraries/Email.php
+++ b/system/libraries/Email.php
@@ -96,6 +96,13 @@ class CI_Email {
public $smtp_timeout = 5;
/**
+ * SMTP persistent connection
+ *
+ * @var bool
+ */
+ public $smtp_keepalive = FALSE;
+
+ /**
* SMTP Encryption
*
* @var string NULL, 'tls' or 'ssl'
@@ -403,6 +410,21 @@ class CI_Email {
// --------------------------------------------------------------------
/**
+ * Destructor - Releases Resources
+ *
+ * @return void
+ */
+ public function __destruct()
+ {
+ if (is_resource($this->_smtp_connect))
+ {
+ $this->_send_command('quit');
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Initialize preferences
*
* @param array
@@ -1183,8 +1205,11 @@ class CI_Email {
{
if ($this->protocol === 'mail')
{
- $this->_subject = $this->_headers['Subject'];
- unset($this->_headers['Subject']);
+ if (isset($this->_headers['Subject']))
+ {
+ $this->_subject = $this->_headers['Subject'];
+ unset($this->_headers['Subject']);
+ }
}
reset($this->_headers);
@@ -1824,7 +1849,15 @@ class CI_Email {
return FALSE;
}
- $this->_send_command('quit');
+ if ($this->smtp_keepalive)
+ {
+ $this->_send_command('reset');
+ }
+ else
+ {
+ $this->_send_command('quit');
+ }
+
return TRUE;
}
@@ -1837,6 +1870,11 @@ class CI_Email {
*/
protected function _smtp_connect()
{
+ if (is_resource($this->_smtp_connect))
+ {
+ return TRUE;
+ }
+
$ssl = ($this->smtp_crypto === 'ssl') ? 'ssl://' : NULL;
$this->_smtp_connect = fsockopen($ssl.$this->smtp_host,
@@ -1851,6 +1889,7 @@ class CI_Email {
return FALSE;
}
+ stream_set_timeout($this->_smtp_connect, $this->smtp_timeout);
$this->_set_error_message($this->_get_smtp_data());
if ($this->smtp_crypto === 'tls')
@@ -1924,6 +1963,11 @@ class CI_Email {
$this->_send_data('DATA');
$resp = 354;
break;
+ case 'reset':
+
+ $this->_send_data('RSET');
+ $resp = 250;
+ break;
case 'quit' :
$this->_send_data('QUIT');
@@ -1973,6 +2017,11 @@ class CI_Email {
$reply = $this->_get_smtp_data();
+ if (strpos($reply, '503') !== 0) // Already authenticated
+ {
+ return TRUE;
+ }
+
if (strpos($reply, '334') !== 0)
{
$this->_set_error_message('lang:email_failed_smtp_login', $reply);