From 38a62d80e6f46713f41e835f59cb0da12e8b0913 Mon Sep 17 00:00:00 2001 From: Miguel Guerreiro Date: Tue, 27 Jan 2015 10:03:54 +0000 Subject: [PATCH] Added function to explicitly close imap resource Calling imap_errors() to clear the error stack and prevent errors and notices from popping up. Function is implicitly called on class destruction. --- src/Fetch/Server.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/Fetch/Server.php b/src/Fetch/Server.php index 5368781..944a170 100644 --- a/src/Fetch/Server.php +++ b/src/Fetch/Server.php @@ -135,6 +135,33 @@ public function __construct($serverPath, $port = 143, $service = 'imap') $this->service = $service; } + /** + * This destructor function closes the imap resource via closeImapStream() + * + * @return void + */ + public function __destruct() + { + $this->closeImapStream(); + } + + /** + * This function closes the current imap resource and returns an array with any errors on the stack + * + * @return false|array + */ + public function closeImapStream() + { + $imapErrors = imap_errors(); + + if (isset($this->imapStream)) { + imap_close($this->imapStream); + $this->imapStream = null; + } + + return $imapErrors; + } + /** * This function sets the username and password used to connect to the server. *