diff options
author | Andrey Andreev <narf@bofh.bg> | 2013-02-18 13:48:59 +0100 |
---|---|---|
committer | Andrey Andreev <narf@bofh.bg> | 2013-02-18 13:48:59 +0100 |
commit | 6244086d6e251fc4b3c71d23da625ffb59b85d77 (patch) | |
tree | 9072f3ef9f252e2f975f232ddb367edafe0f00b7 /system | |
parent | 8917ff32a90663c96e923e82d90d83f386694015 (diff) | |
parent | 73c75cbfa066b4e72b8e691199ad964d1c2b3719 (diff) |
Merge pull request #2256 from nisheeth-barthwal/develop
Added keep-alive connection to SMTP. Fixed socket read/write timeouts. Added PHP useragent.
Diffstat (limited to 'system')
-rw-r--r-- | system/libraries/Email.php | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 997757b0a..1bf1da15e 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -94,6 +94,13 @@ class CI_Email { * @var int */ public $smtp_timeout = 5; + + /** + * SMTP persistent connection + * + * @var bool + */ + public $smtp_keepalive = FALSE; /** * SMTP Encryption @@ -401,6 +408,21 @@ class CI_Email { } // -------------------------------------------------------------------- + + /** + * Destructor - Releases Resources + * + * @return void + */ + public function __destruct() + { + if (is_resource($this->_smtp_connect)) + { + $this->_send_command('quit'); + } + } + + // -------------------------------------------------------------------- /** * Initialize preferences @@ -1824,7 +1846,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 +1867,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 +1886,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 +1960,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 +2014,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); |