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