diff --git a/src/Core/Connection.php b/src/Core/Connection.php index cd51944..08bd554 100644 --- a/src/Core/Connection.php +++ b/src/Core/Connection.php @@ -5,7 +5,7 @@ namespace Clivern\Imap\Core; -use Clivern\Imap\Core\Exception\ConnectionError; +use Clivern\Imap\Core\Exception\AuthenticationFailedException; /** * Connection Class @@ -85,14 +85,14 @@ class Connection * Connect to IMAP Email * * @return Connection - * @throws ConnectionError + * @throws AuthenticationFailedException */ public function connect() { 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."); + throw new AuthenticationFailedException("Error! Connecting to Imap Email."); } return $this; @@ -103,7 +103,7 @@ class Connection try { imap_reopen($this->stream, "{" . $this->server . ":" . $this->port . $this->flag . "}" . $folder); } catch (\Exception $e) { - throw new ConnectionError("Error! Connecting to Imap Email."); + throw new AuthenticationFailedException("Error! Connecting to Imap Email."); } } diff --git a/src/Core/Exception/AuthenticationFailedException.php b/src/Core/Exception/AuthenticationFailedException.php new file mode 100644 index 0000000..125f41d --- /dev/null +++ b/src/Core/Exception/AuthenticationFailedException.php @@ -0,0 +1,28 @@ + + */ + +namespace Clivern\Imap\Core\Exception; + +/** + * Connection Error Class + * + * @package Clivern\Imap\Core\Exception + */ +class AuthenticationFailedException extends \Exception +{ + + public function __construct($error = null) + { + parent::__construct( + sprintf( + "Authentication failed with error: %s", + $server, + $port, + $email, + $error + ) + ); + } +} \ No newline at end of file diff --git a/src/Core/Exception/ConnectionError.php b/src/Core/Exception/ConnectionError.php deleted file mode 100644 index 4e212d2..0000000 --- a/src/Core/Exception/ConnectionError.php +++ /dev/null @@ -1,13 +0,0 @@ - - */ - -namespace Clivern\Imap\Core\Exception; - -/** - * Connection Error Class - * - * @package Clivern\Imap\Core\Exception - */ -class ConnectionError extends \Exception{} diff --git a/src/Core/Exception/MessageDeleteException.php b/src/Core/Exception/MessageDeleteException.php new file mode 100644 index 0000000..2c54f87 --- /dev/null +++ b/src/Core/Exception/MessageDeleteException.php @@ -0,0 +1,25 @@ + + */ + +namespace Clivern\Imap\Core\Exception; + +/** + * Connection Error Class + * + * @package Clivern\Imap\Core\Exception + */ +class MessageDeleteException extends \Exception +{ + + /** + * Class Constructor + * + * @param integer $message_number + */ + public function __construct($message_number) + { + parent::__construct(sprintf('Message %s cannot be deleted', $message_number)); + } +} \ No newline at end of file diff --git a/src/Core/Exception/MessageDoesNotExistException.php b/src/Core/Exception/MessageDoesNotExistException.php new file mode 100644 index 0000000..f16074b --- /dev/null +++ b/src/Core/Exception/MessageDoesNotExistException.php @@ -0,0 +1,25 @@ + + */ + +namespace Clivern\Imap\Core\Exception; + +/** + * Connection Error Class + * + * @package Clivern\Imap\Core\Exception + */ +class MessageDoesNotExistException extends \Exception +{ + /** + * Class Constructor + * + * @param integer $number + * @param string $error + */ + public function __construct($number, $error) + { + parent::__construct(sprintf('Message %s does not exist: %s', $number, $error)); + } +} \ No newline at end of file diff --git a/src/Core/Exception/MessageMoveException.php b/src/Core/Exception/MessageMoveException.php new file mode 100644 index 0000000..2584632 --- /dev/null +++ b/src/Core/Exception/MessageMoveException.php @@ -0,0 +1,26 @@ + + */ + +namespace Clivern\Imap\Core\Exception; + +/** + * Connection Error Class + * + * @package Clivern\Imap\Core\Exception + */ +class MessageMoveException extends \Exception +{ + + /** + * Class Constructor + * + * @param integer $message_number + * @param string $mailbox + */ + public function __construct($message_number, $mailbox) + { + parent::__construct(sprintf('Message %s cannot be moved to %s', $message_number, $mailbox)); + } +} \ No newline at end of file