Test Failed
Push — master ( 5ef0bf...1ac602 )
by
unknown
08:18
created

mapi_strerror()   D

Complexity

Conditions 77
Paths 77

Size

Total Lines 155
Code Lines 78

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 77
eloc 78
c 1
b 0
f 0
nop 1
dl 0
loc 155
rs 4.1666
nc 77

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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-2022 grommunio GmbH
6
 */
7
8
 /**
9
 * Status codes returned by MAPI functions.
10
 */
11
12
/* From winerror.h */
13
//
14
// Success codes
15
//
16
define('S_OK', 0x00000000);
17
define('S_FALSE', 0x00000001);
18
define('SEVERITY_ERROR', 1);
19
20
/* from winerror.h */
21
22
/**
23
 * Function to make an error.
24
 *
25
 * @param mixed $code
26
 */
27
function make_mapi_e($code) {
28
	return (int) mapi_make_scode(1, $code);
0 ignored issues
show
Bug introduced by
The function mapi_make_scode was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
	return (int) /** @scrutinizer ignore-call */ mapi_make_scode(1, $code);
Loading history...
29
}
30
31
/**
32
 * Function to make a warning.
33
 *
34
 * @param mixed $code
35
 */
36
function make_mapi_s($code) {
37
	return (int) mapi_make_scode(0, $code);
0 ignored issues
show
Bug introduced by
The function mapi_make_scode was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
	return (int) /** @scrutinizer ignore-call */ mapi_make_scode(0, $code);
Loading history...
38
}
39
40
/* From mapicode.h */
41
/*
42
 *  On Windows NT 3.5 and Windows 95, scodes are 32-bit values
43
 *  laid out as follows:
44
 *
45
 *    3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
46
 *    1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
47
 *   +-+-+-+-+-+---------------------+-------------------------------+
48
 *   |S|R|C|N|r|    Facility         |               Code            |
49
 *   +-+-+-+-+-+---------------------+-------------------------------+
50
 *
51
 *   where
52
 *
53
 *      S - Severity - indicates success/fail
54
 *
55
 *          0 - Success
56
 *          1 - Fail (COERROR)
57
 *
58
 *      R - reserved portion of the facility code, corresponds to NT's
59
 *          second severity bit.
60
 *
61
 *      C - reserved portion of the facility code, corresponds to NT's
62
 *          C field.
63
 *
64
 *      N - reserved portion of the facility code. Used to indicate a
65
 *          mapped NT status value.
66
 *
67
 *      r - reserved portion of the facility code. Reserved for internal
68
 *          use. Used to indicate HRESULT values that are not status
69
 *          values, but are instead message ids for display strings.
70
 *
71
 *      Facility - is the facility code
72
 *          FACILITY_NULL                    0x0
73
 *          FACILITY_RPC                     0x1
74
 *          FACILITY_DISPATCH                0x2
75
 *          FACILITY_STORAGE                 0x3
76
 *          FACILITY_ITF                     0x4
77
 *          FACILITY_WIN32                   0x7
78
 *          FACILITY_WINDOWS                 0x8
79
 *
80
 *      Code - is the facility's status code
81
 *
82
 */
83
define('NOERROR', 0);
84
85
// The following codes don't use make_mapi_e because they are in the 0x000FF000 range,
86
// but we cannot use the HEX value as would make most sense as that would break in 64bit PHP
87
// (Gromox server will return a negative value, but PHP would convert this define into a positive
88
// value). Hence we declare the value exactly as we need it as integer and bypass the
89
// 32bit/64bit hell.
90
define('ecUnknownUser', 0x000003EB);
91
define('ecLoginPerm', 0x000003F2);
92
define('ecMsgCycle', 0x00000504);
93
define('MAPI_E_CALL_FAILED', 0x80004005);
94
define('MAPI_E_NOT_ENOUGH_MEMORY', 0x8007000E);
95
define('MAPI_E_INVALID_PARAMETER', 0x80070057);
96
define('MAPI_E_INTERFACE_NOT_SUPPORTED', 0x80004002);
97
define('MAPI_E_NO_ACCESS', 0x80070005);
98
99
define('MAPI_E_NO_SUPPORT', make_mapi_e(0x102));
100
define('MAPI_E_BAD_CHARWIDTH', make_mapi_e(0x103));
101
define('MAPI_E_STRING_TOO_LONG', make_mapi_e(0x105));
102
define('MAPI_E_UNKNOWN_FLAGS', make_mapi_e(0x106));
103
define('MAPI_E_INVALID_ENTRYID', make_mapi_e(0x107));
104
define('MAPI_E_INVALID_OBJECT', make_mapi_e(0x108));
105
define('MAPI_E_OBJECT_CHANGED', make_mapi_e(0x109));
106
define('MAPI_E_OBJECT_DELETED', make_mapi_e(0x10A));
107
define('MAPI_E_BUSY', make_mapi_e(0x10B));
108
define('MAPI_E_NOT_ENOUGH_DISK', make_mapi_e(0x10D));
109
define('MAPI_E_NOT_ENOUGH_RESOURCES', make_mapi_e(0x10E));
110
define('MAPI_E_NOT_FOUND', make_mapi_e(0x10F));
111
define('MAPI_E_VERSION', make_mapi_e(0x110));
112
define('MAPI_E_LOGON_FAILED', make_mapi_e(0x111));
113
define('MAPI_E_SESSION_LIMIT', make_mapi_e(0x112));
114
define('MAPI_E_USER_CANCEL', make_mapi_e(0x113));
115
define('MAPI_E_UNABLE_TO_ABORT', make_mapi_e(0x114));
116
define('MAPI_E_NETWORK_ERROR', make_mapi_e(0x115));
117
define('MAPI_E_DISK_ERROR', make_mapi_e(0x116));
118
define('MAPI_E_TOO_COMPLEX', make_mapi_e(0x117));
119
define('MAPI_E_BAD_COLUMN', make_mapi_e(0x118));
120
define('MAPI_E_EXTENDED_ERROR', make_mapi_e(0x119));
121
define('MAPI_E_COMPUTED', make_mapi_e(0x11A));
122
define('MAPI_E_CORRUPT_DATA', make_mapi_e(0x11B));
123
define('MAPI_E_UNCONFIGURED', make_mapi_e(0x11C));
124
define('MAPI_E_FAILONEPROVIDER', make_mapi_e(0x11D));
125
define('MAPI_E_UNKNOWN_CPID', make_mapi_e(0x11E));
126
define('MAPI_E_UNKNOWN_LCID', make_mapi_e(0x11F));
127
128
/* Flavors of E_ACCESSDENIED, used at logon */
129
130
define('MAPI_E_PASSWORD_CHANGE_REQUIRED', make_mapi_e(0x120));
131
define('MAPI_E_PASSWORD_EXPIRED', make_mapi_e(0x121));
132
define('MAPI_E_INVALID_WORKSTATION_ACCOUNT', make_mapi_e(0x122));
133
define('MAPI_E_INVALID_ACCESS_TIME', make_mapi_e(0x123));
134
define('MAPI_E_ACCOUNT_DISABLED', make_mapi_e(0x124));
135
define('MAPI_E_WEBAPP_FEATURE_DISABLED', make_mapi_e(0x125));
136
137
/* MAPI base function and status object specific errors and warnings */
138
139
define('MAPI_E_END_OF_SESSION', make_mapi_e(0x200));
140
define('MAPI_E_UNKNOWN_ENTRYID', make_mapi_e(0x201));
141
define('MAPI_E_MISSING_REQUIRED_COLUMN', make_mapi_e(0x202));
142
define('MAPI_W_NO_SERVICE', make_mapi_s(0x203));
143
144
/* Property specific errors and warnings */
145
146
define('MAPI_E_BAD_VALUE', make_mapi_e(0x301));
147
define('MAPI_E_INVALID_TYPE', make_mapi_e(0x302));
148
define('MAPI_E_TYPE_NO_SUPPORT', make_mapi_e(0x303));
149
define('MAPI_E_UNEXPECTED_TYPE', make_mapi_e(0x304));
150
define('MAPI_E_TOO_BIG', make_mapi_e(0x305));
151
define('MAPI_E_DECLINE_COPY', make_mapi_e(0x306));
152
define('MAPI_E_UNEXPECTED_ID', make_mapi_e(0x307));
153
154
define('MAPI_W_ERRORS_RETURNED', make_mapi_s(0x380));
155
156
/* Table specific errors and warnings */
157
158
define('MAPI_E_UNABLE_TO_COMPLETE', make_mapi_e(0x400));
159
define('MAPI_E_TIMEOUT', make_mapi_e(0x401));
160
define('MAPI_E_TABLE_EMPTY', make_mapi_e(0x402));
161
define('MAPI_E_TABLE_TOO_BIG', make_mapi_e(0x403));
162
163
define('MAPI_E_INVALID_BOOKMARK', make_mapi_e(0x405));
164
165
define('MAPI_W_POSITION_CHANGED', make_mapi_s(0x481));
166
define('MAPI_W_APPROX_COUNT', make_mapi_s(0x482));
167
168
/* Transport specific errors and warnings */
169
170
define('MAPI_E_WAIT', make_mapi_e(0x500));
171
define('MAPI_E_CANCEL', make_mapi_e(0x501));
172
define('MAPI_E_NOT_ME', make_mapi_e(0x502));
173
174
define('MAPI_W_CANCEL_MESSAGE', make_mapi_s(0x580));
175
176
/* Message Store, Folder, and Message specific errors and warnings */
177
178
define('MAPI_E_CORRUPT_STORE', make_mapi_e(0x600));
179
define('MAPI_E_NOT_IN_QUEUE', make_mapi_e(0x601));
180
define('MAPI_E_NO_SUPPRESS', make_mapi_e(0x602));
181
define('MAPI_E_COLLISION', make_mapi_e(0x604));
182
define('MAPI_E_NOT_INITIALIZED', make_mapi_e(0x605));
183
define('MAPI_E_NON_STANDARD', make_mapi_e(0x606));
184
define('MAPI_E_NO_RECIPIENTS', make_mapi_e(0x607));
185
define('MAPI_E_SUBMITTED', make_mapi_e(0x608));
186
define('MAPI_E_HAS_FOLDERS', make_mapi_e(0x609));
187
define('MAPI_E_HAS_MESSAGES', make_mapi_e(0x60A));
188
define('MAPI_E_FOLDER_CYCLE', make_mapi_e(0x60B));
189
define('MAPI_E_STORE_FULL', make_mapi_e(0x60C));
190
191
define('MAPI_W_PARTIAL_COMPLETION', make_mapi_s(0x680));
192
193
/* Address Book specific errors and warnings */
194
195
define('MAPI_E_AMBIGUOUS_RECIP', make_mapi_e(0x700));
196
197
/* ICS errors and warnings */
198
199
define('SYNC_E_UNKNOWN_FLAGS', MAPI_E_UNKNOWN_FLAGS);
200
define('SYNC_E_INVALID_PARAMETER', MAPI_E_INVALID_PARAMETER);
201
define('SYNC_E_ERROR', MAPI_E_CALL_FAILED);
202
define('SYNC_E_OBJECT_DELETED', make_mapi_e(0x800));
203
define('SYNC_E_IGNORE', make_mapi_e(0x801));
204
define('SYNC_E_CONFLICT', make_mapi_e(0x802));
205
define('SYNC_E_NO_PARENT', make_mapi_e(0x803));
206
define('SYNC_E_INCEST', make_mapi_e(0x804));
207
define('SYNC_E_UNSYNCHRONIZED', make_mapi_e(0x805));
208
209
define('SYNC_W_PROGRESS', make_mapi_s(0x820));
210
define('SYNC_W_CLIENT_CHANGE_NEWER', make_mapi_s(0x821));
211
212
function mapi_strerror($e) {
213
	switch ($e) {
214
		case S_OK: return "success";
215
216
		case MAPI_E_CALL_FAILED: return "An error of unexpected or unknown origin occurred";
217
218
		case MAPI_E_NOT_ENOUGH_MEMORY: return "Not enough memory was available to complete the operation";
219
220
		case MAPI_E_INVALID_PARAMETER: return "An invalid parameter was passed to a function or remote procedure call";
221
222
		case MAPI_E_INTERFACE_NOT_SUPPORTED: return "MAPI interface not supported";
223
224
		case MAPI_E_NO_ACCESS: return "An attempt was made to access a message store or object for which the user has insufficient permissions";
225
226
		case MAPI_E_NO_SUPPORT: return "Function is not implemented";
227
228
		case MAPI_E_BAD_CHARWIDTH: return "An incompatibility exists in the character sets supported by the caller and the implementation";
229
230
		case MAPI_E_STRING_TOO_LONG: return "In the context of this method call, a string exceeds the maximum permitted length";
231
232
		case MAPI_E_UNKNOWN_FLAGS: return "One or more values for a flags parameter were not valid";
233
234
		case MAPI_E_INVALID_ENTRYID: return "invalid entryid";
235
236
		case MAPI_E_INVALID_OBJECT: return "A method call was made using a reference to an object that has been destroyed or is not in a viable state";
237
238
		case MAPI_E_OBJECT_CHANGED: return "An attempt to commit changes failed because the object was changed separately";
239
240
		case MAPI_E_OBJECT_DELETED: return "An operation failed because the object was deleted separately";
241
242
		case MAPI_E_BUSY: return "A table operation failed because a separate operation was in progress at the same time";
243
244
		case MAPI_E_NOT_ENOUGH_DISK: return "Not enough disk space was available to complete the operation";
245
246
		case MAPI_E_NOT_ENOUGH_RESOURCES: return "Not enough system resources were available to complete the operation";
247
248
		case MAPI_E_NOT_FOUND: return "The requested object could not be found at the server";
249
250
		case MAPI_E_VERSION: return "Client and server versions are not compatible";
251
252
		case MAPI_E_LOGON_FAILED: return "A client was unable to log on to the server";
253
254
		case MAPI_E_SESSION_LIMIT: return "A server or service is unable to create any more sessions";
255
256
		case MAPI_E_USER_CANCEL: return "An operation failed because a user cancelled it";
257
258
		case MAPI_E_UNABLE_TO_ABORT: return "A ropAbort or ropAbortSubmit ROP request was unsuccessful";
259
260
		case MAPI_E_NETWORK_ERROR: return "An operation was unsuccessful because of a problem with network operations or services";
261
262
		case MAPI_E_DISK_ERROR: return "There was a problem writing to or reading from disk";
263
264
		case MAPI_E_TOO_COMPLEX: return "The operation requested is too complex for the server to handle (often w.r.t. restrictions)";
265
266
		case MAPI_E_BAD_COLUMN: return "The column requested is not allowed in this type of table";
267
268
		case MAPI_E_EXTENDED_ERROR: return "extended error";
269
270
		case MAPI_E_COMPUTED: return "A property cannot be updated because it is read-only, computed by the server";
271
272
		case MAPI_E_CORRUPT_DATA: return "There is an internal inconsistency in a database, or in a complex property value";
273
274
		case MAPI_E_UNCONFIGURED: return "unconfigured";
275
276
		case MAPI_E_FAILONEPROVIDER: return "failoneprovider";
277
278
		case MAPI_E_UNKNOWN_CPID: return "The server is not configured to support the code page requested by the client";
279
280
		case MAPI_E_UNKNOWN_LCID: return "The server is not configured to support the locale requested by the client";
281
282
		case MAPI_E_PASSWORD_CHANGE_REQUIRED: return "password change required";
283
284
		case MAPI_E_PASSWORD_EXPIRED: return "password expired";
285
286
		case MAPI_E_INVALID_WORKSTATION_ACCOUNT: return "invalid workstation account";
287
288
		case MAPI_E_INVALID_ACCESS_TIME: return "The operation failed due to clock skew between servers";
289
290
		case MAPI_E_ACCOUNT_DISABLED: return "account disabled";
291
292
		case MAPI_E_END_OF_SESSION: return "The server session has been destroyed, possibly by a server restart";
293
294
		case MAPI_E_UNKNOWN_ENTRYID: return "The EntryID passed to OpenEntry was created by a different MAPI provider";
295
296
		case MAPI_E_MISSING_REQUIRED_COLUMN: return "missing required column";
297
298
		case MAPI_W_NO_SERVICE: return "no service";
299
300
		case MAPI_E_BAD_VALUE: return "bad value";
301
302
		case MAPI_E_INVALID_TYPE: return "invalid type";
303
304
		case MAPI_E_TYPE_NO_SUPPORT: return "type no support";
305
306
		case MAPI_E_UNEXPECTED_TYPE: return "unexpected_type";
307
308
		case MAPI_E_TOO_BIG: return "The table is too big for the requested operation to complete";
309
310
		case MAPI_E_DECLINE_COPY: return "The provider implements this method by calling a support object method, and the caller has passed the MAPI_DECLINE_OK flag";
311
312
		case MAPI_E_UNEXPECTED_ID: return "unexpected id";
313
314
		case MAPI_W_ERRORS_RETURNED: return "The call succeeded, but the message store provider has error information available";
315
316
		case MAPI_E_UNABLE_TO_COMPLETE: return "A complex operation such as building a table row set could not be completed";
317
318
		case MAPI_E_TIMEOUT: return "An asynchronous operation did not succeed within the specified time-out";
319
320
		case MAPI_E_TABLE_EMPTY: return "A table essential to the operation is empty";
321
322
		case MAPI_E_TABLE_TOO_BIG: return "The table is too big for the requested operation to complete";
323
324
		case MAPI_E_INVALID_BOOKMARK: return "The bookmark passed to a table operation was not created on the same table";
325
326
		case MAPI_W_POSITION_CHANGED: return "position changed";
327
328
		case MAPI_W_APPROX_COUNT: return "approx count";
329
330
		case MAPI_E_WAIT: return "A wait time-out has expired";
331
332
		case MAPI_E_CANCEL: return "The operation had to be canceled";
333
334
		case MAPI_E_NOT_ME: return "not me";
335
336
		case MAPI_W_CANCEL_MESSAGE: return "cancel message";
337
338
		case MAPI_E_CORRUPT_STORE: return "corrupt store";
339
340
		case MAPI_E_NOT_IN_QUEUE: return "not in queue";
341
342
		case MAPI_E_NO_SUPPRESS: return "The server does not support the suppression of read receipts";
343
344
		case MAPI_E_COLLISION: return "A folder or item cannot be created because one with the same name or other criteria already exists";
345
346
		case MAPI_E_NOT_INITIALIZED: return "The subsystem is not ready";
347
348
		case MAPI_E_NON_STANDARD: return "non standard";
349
350
		case MAPI_E_NO_RECIPIENTS: return "A message cannot be sent because it has no recipients";
351
352
		case MAPI_E_SUBMITTED: return "A message cannot be opened for modification because it has already been sent";
353
354
		case MAPI_E_HAS_FOLDERS: return "A folder cannot be deleted because it still contains subfolders";
355
356
		case MAPI_E_HAS_MESSAGES: return "A folder cannot be deleted because it still contains messages";
357
358
		case MAPI_E_FOLDER_CYCLE: return "A folder move or copy operation would create a cycle";
359
360
		case MAPI_W_PARTIAL_COMPLETION: return "The call succeeded, but not all entries were successfully operated on";
361
362
		case MAPI_E_AMBIGUOUS_RECIP: return "An unresolved recipient matches more than one directory entry";
363
364
		case MAPI_E_STORE_FULL: return "Store full";
365
366
		default: return sprintf("%xh", $e);
367
	}
368
}
369