MAPIException   A
last analyzed

Complexity

Total Complexity 21

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 21
eloc 32
c 3
b 0
f 0
dl 0
loc 50
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
D getDisplayMessage() 0 43 21
1
<?php
2
/*
3
 * SPDX-License-Identifier: AGPL-3.0-only
4
 * SPDX-FileCopyrightText: Copyright 2005-2016 Zarafa Deutschland GmbH
5
 * SPDX-FileCopyrightText: Copyright 2020-2024 grommunio GmbH
6
 */
7
8
/**
9
 * MAPIException
10
 * if enabled using mapi_enable_exceptions then php-ext can throw exceptions when
11
 * any error occurs in mapi calls. this exception will only be thrown when severity bit is set in
12
 * error code that means it will be thrown only for mapi errors not for mapi warnings.
13
 */
14
class MAPIException extends BaseException {
15
	/**
16
	 * Returns display message of exception if its set by the callee.
17
	 * If it is not set then we are generating some default display messages based
18
	 * on mapi error code.
19
	 *
20
	 */
21
	public function getDisplayMessage(): string {
22
		if (!empty($this->displayMessage)) {
23
			return $this->displayMessage;
24
		}
25
26
		switch ($this->getCode()) {
27
			/* see also class.webappauthentication.php:getErrorMessage for more instances */
28
29
			case MAPI_E_NO_ACCESS:
30
				return dgettext("zarafa", "You have insufficient privileges to open this object.");
31
32
			case ecUnknownUser:
33
			case MAPI_E_LOGON_FAILED:
34
			case MAPI_E_UNCONFIGURED:
35
				return dgettext("zarafa", "Logon Failed. Please check your name/password.");
36
37
			case MAPI_E_NETWORK_ERROR:
38
				return dgettext("zarafa", "Can not connect to Gromox.");
39
40
			case MAPI_E_UNKNOWN_ENTRYID:
41
				return dgettext("zarafa", "Can not open object with provided id.");
42
43
			case MAPI_E_NO_RECIPIENTS:
44
				return dgettext("zarafa", "There are no recipients in the message.");
45
46
			case MAPI_E_NOT_FOUND:
47
				return dgettext("zarafa", "Can not find object.");
48
49
			case MAPI_E_NOT_ENOUGH_MEMORY:
50
				return dgettext("zarafa", "Operation failed: Server does not have enough memory.");
51
52
			case MAPI_E_INTERFACE_NOT_SUPPORTED:
53
			case MAPI_E_INVALID_PARAMETER:
54
			case MAPI_E_INVALID_ENTRYID:
55
			case MAPI_E_INVALID_OBJECT:
56
			case MAPI_E_TOO_COMPLEX:
57
			case MAPI_E_CORRUPT_DATA:
58
			case MAPI_E_END_OF_SESSION:
59
			case MAPI_E_AMBIGUOUS_RECIP:
60
			case MAPI_E_COLLISION:
61
			case MAPI_E_UNCONFIGURED:
62
			default:
63
				return sprintf(dgettext("zarafa", "Unknown MAPI Error: %s"), get_mapi_error_name($this->getCode()));
64
		}
65
	}
66
}
67
68
// Tell the PHP extension which exception class to instantiate
69
if (function_exists('mapi_enable_exceptions')) {
70
	mapi_enable_exceptions("mapiexception");
71
}
72