diff --git a/src/Core/Connection.php b/src/Core/Connection.php index ee5bc60..1752250 100644 --- a/src/Core/Connection.php +++ b/src/Core/Connection.php @@ -5,6 +5,8 @@ namespace Clivern\Imap\Core; +use Clivern\Imap\Core\Exception\ConnectionError; + /** * Connection Class * @@ -72,10 +74,15 @@ class Connection * Connect to IMAP Email * * @return Connection + * @throws ConnectionError */ public function connect() { - $this->stream = imap_open("{" . $this->server . ":" . $this->port . $this->flag . "}" . $this->folder, $this->email, $this->password); + try { + $this->stream = imap_open("{" . $this->server . ":" . $this->port . $this->flag . "}" . $this->folder, $this->email, $this->password); + } catch (\Exception $e) { + throw new ConnectionError("Error! Connecting to Imap Email."); + } return $this; } diff --git a/src/Core/Exception/.gitkeep b/src/Core/Exception/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/src/Core/Exception/ConnectionError.php b/src/Core/Exception/ConnectionError.php new file mode 100644 index 0000000..4e212d2 --- /dev/null +++ b/src/Core/Exception/ConnectionError.php @@ -0,0 +1,13 @@ + + */ + +namespace Clivern\Imap\Core\Exception; + +/** + * Connection Error Class + * + * @package Clivern\Imap\Core\Exception + */ +class ConnectionError extends \Exception{} diff --git a/src/Core/Stats.php b/src/Core/Stats.php index b0b8511..40a0415 100644 --- a/src/Core/Stats.php +++ b/src/Core/Stats.php @@ -4,6 +4,7 @@ */ namespace Clivern\Imap\Core; + use Clivern\Imap\Core\Connection; /** @@ -22,12 +23,16 @@ class Stats public function getQuota($folder = 'INBOX') { - return imap_get_quotaroot($this->connection->getStream(), $folder); + $data = imap_get_quotaroot($this->connection->getStream(), $folder); + + return $data; } public function getStatus($folder = 'INBOX', $flag = SA_ALL) { - return imap_status($this->connection->getStream(), "{" . $this->connection->getServer() . "}" . $folder, $flag); + $data = imap_status($this->connection->getStream(), "{" . $this->connection->getServer() . "}" . $folder, $flag); + + return $data; } } \ No newline at end of file