1: <?php
2: /**
3: * Copyright 2011-2014 Horde LLC (http://www.horde.org/)
4: *
5: * See the enclosed file COPYING for license information (GPL). If you
6: * did not receive this file, see http://www.horde.org/licenses/gpl.
7: *
8: * @category Horde
9: * @copyright 2011-2014 Horde LLC
10: * @license http://www.horde.org/licenses/gpl GPL
11: * @package IMP
12: */
13:
14: /**
15: * Exception class for handling Horde_Imap_Client exceptions in IMP.
16: *
17: * @author Michael Slusarz <slusarz@horde.org>
18: * @category Horde
19: * @copyright 2011-2014 Horde LLC
20: * @license http://www.horde.org/licenses/gpl GPL
21: * @package IMP
22: *
23: * @property-read boolean $notified Sent notification of the error?
24: */
25: class IMP_Imap_Exception extends Horde_Imap_Client_Exception
26: {
27: /**
28: * Sent the error to the notification system.
29: *
30: * @var boolean
31: */
32: public $_notified = false;
33:
34: /**
35: * Send notification of the error.
36: *
37: * @param string $msg Notification message.
38: * @param string $level Notification level.
39: * @param boolean $force Force notification, even if already done?
40: */
41: public function notify($msg = null, $level = null, $force = false)
42: {
43: if (!$this->_notified || $force) {
44: $GLOBALS['notification']->push(
45: is_null($msg) ? $this->getMessage() : $msg,
46: is_null($level) ? 'horde.error' : $level
47: );
48:
49: $this->_notified = true;
50: }
51: }
52:
53: /**
54: * Generates an authentication exception.
55: *
56: * @param boolean $default Return exception, even if no code exists?
57: *
58: * @return Horde_Auth_Exception An authentication exception.
59: */
60: public function authException($default = true)
61: {
62: switch ($this->getCode()) {
63: case self::LOGIN_AUTHENTICATIONFAILED:
64: case self::LOGIN_AUTHORIZATIONFAILED:
65: $code = Horde_Auth::REASON_BADLOGIN;
66: break;
67:
68: case self::LOGIN_EXPIRED:
69: $code = Horde_Auth::REASON_EXPIRED;
70: break;
71:
72: case self::SERVER_CONNECT:
73: case self::LOGIN_UNAVAILABLE:
74: $code = Horde_Auth::REASON_MESSAGE;
75: break;
76:
77: case self::LOGIN_NOAUTHMETHOD:
78: case self::LOGIN_PRIVACYREQUIRED:
79: case self::LOGIN_TLSFAILURE:
80: $code = Horde_Auth::REASON_FAILED;
81: break;
82:
83: default:
84: $code = $default
85: ? Horde_Auth::REASON_FAILED
86: : null;
87: break;
88: }
89:
90: return is_null($code)
91: ? null
92: : new Horde_Auth_Exception($this, $code);
93: }
94:
95: /**
96: */
97: public function __get($name)
98: {
99: switch ($name) {
100: case 'notified':
101: return $this->_notified;
102: }
103: }
104:
105: }
106: