Passed
Push — master ( 6522b6...8c95d3 )
by
unknown
04:16 queued 01:06
created

MAPIUtils::GetFolderTypeFromContainerClass()   B

Complexity

Conditions 7
Paths 7

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 13
nc 7
nop 1
dl 0
loc 21
rs 8.8333
c 0
b 0
f 0
1
<?php
2
/*
3
 * SPDX-License-Identifier: AGPL-3.0-only
4
 * SPDX-FileCopyrightText: Copyright 2007-2013,2016 Zarafa Deutschland GmbH
5
 * SPDX-FileCopyrightText: Copyright 2020-2022 grommunio GmbH
6
 */
7
8
/**
9
 * MAPI to AS mapping class.
10
 */
11
class MAPIUtils {
12
	/**
13
	 * Create a MAPI restriction to use within an email folder which will
14
	 * return all messages since since $timestamp.
15
	 *
16
	 * @param long $timestamp Timestamp since when to include messages
0 ignored issues
show
Bug introduced by
The type long was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
	 *
18
	 * @return array
19
	 */
20
	public static function GetEmailRestriction($timestamp) {
21
		// ATTENTION: ON CHANGING THIS RESTRICTION, MAPIUtils::IsInEmailSyncInterval() also needs to be changed
22
		return [
23
			RES_PROPERTY,
24
			[
25
				RELOP => RELOP_GE,
26
				ULPROPTAG => PR_MESSAGE_DELIVERY_TIME,
0 ignored issues
show
Bug introduced by
The constant PR_MESSAGE_DELIVERY_TIME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
27
				VALUE => $timestamp,
28
			],
29
		];
30
	}
31
32
	/**
33
	 * Create a MAPI restriction to use in the calendar which will
34
	 * return all future calendar items, plus those since $timestamp.
35
	 *
36
	 * @param MAPIStore $store     the MAPI store
0 ignored issues
show
Bug introduced by
The type MAPIStore was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
37
	 * @param long      $timestamp Timestamp since when to include messages
38
	 *
39
	 * @return array
40
	 */
41
	// TODO getting named properties
42
	public static function GetCalendarRestriction($store, $timestamp) {
43
		// This is our viewing window
44
		$start = $timestamp;
45
		$end = 0x7FFFFFFF; // infinite end
46
47
		$props = MAPIMapping::GetAppointmentProperties();
48
		$props = getPropIdsFromStrings($store, $props);
49
50
		// ATTENTION: ON CHANGING THIS RESTRICTION, MAPIUtils::IsInCalendarSyncInterval() also needs to be changed
51
		return [
52
			RES_OR,
53
			[
54
				// OR
55
				// item.end > window.start && item.start < window.end
56
				[
57
					RES_AND,
58
					[
59
						[
60
							RES_PROPERTY,
61
							[
62
								RELOP => RELOP_LE,
63
								ULPROPTAG => $props["starttime"],
64
								VALUE => $end,
65
							],
66
						],
67
						[
68
							RES_PROPERTY,
69
							[
70
								RELOP => RELOP_GE,
71
								ULPROPTAG => $props["endtime"],
72
								VALUE => $start,
73
							],
74
						],
75
					],
76
				],
77
				// OR
78
				[
79
					RES_OR,
80
					[
81
						// OR
82
						// (EXIST(recurrence_enddate_property) && item[isRecurring] == true && recurrence_enddate_property >= start)
83
						[
84
							RES_AND,
85
							[
86
								[
87
									RES_EXIST,
88
									[ULPROPTAG => $props["recurrenceend"],
89
									],
90
								],
91
								[
92
									RES_PROPERTY,
93
									[
94
										RELOP => RELOP_EQ,
95
										ULPROPTAG => $props["isrecurring"],
96
										VALUE => true,
97
									],
98
								],
99
								[
100
									RES_PROPERTY,
101
									[
102
										RELOP => RELOP_GE,
103
										ULPROPTAG => $props["recurrenceend"],
104
										VALUE => $start,
105
									],
106
								],
107
							],
108
						],
109
						// OR
110
						// (!EXIST(recurrence_enddate_property) && item[isRecurring] == true && item[start] <= end)
111
						[
112
							RES_AND,
113
							[
114
								[
115
									RES_NOT,
116
									[
117
										[
118
											RES_EXIST,
119
											[ULPROPTAG => $props["recurrenceend"],
120
											],
121
										],
122
									],
123
								],
124
								[
125
									RES_PROPERTY,
126
									[
127
										RELOP => RELOP_LE,
128
										ULPROPTAG => $props["starttime"],
129
										VALUE => $end,
130
									],
131
								],
132
								[
133
									RES_PROPERTY,
134
									[
135
										RELOP => RELOP_EQ,
136
										ULPROPTAG => $props["isrecurring"],
137
										VALUE => true,
138
									],
139
								],
140
							],
141
						],
142
					],
143
				], // EXISTS OR
144
			],
145
		];        // global OR
146
	}
147
148
	/**
149
	 * Create a MAPI restriction in order to check if a contact has a picture.
150
	 *
151
	 * @return array
152
	 */
153
	public static function GetContactPicRestriction() {
154
		return [
155
			RES_PROPERTY,
156
			[
157
				RELOP => RELOP_EQ,
158
				ULPROPTAG => mapi_prop_tag(PT_BOOLEAN, 0x7FFF),
159
				VALUE => true,
160
			],
161
		];
162
	}
163
164
	/**
165
	 * Create a MAPI restriction for search.
166
	 *
167
	 * @param string $query
168
	 *
169
	 * @return array
170
	 */
171
	public static function GetSearchRestriction($query) {
172
		return [
173
			RES_AND,
174
			[
175
				[
176
					RES_OR,
177
					[
178
						[
179
							RES_CONTENT,
180
							[
181
								FUZZYLEVEL => FL_SUBSTRING | FL_IGNORECASE,
182
								ULPROPTAG => PR_DISPLAY_NAME,
0 ignored issues
show
Bug introduced by
The constant PR_DISPLAY_NAME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
183
								VALUE => $query,
184
							],
185
						],
186
						[
187
							RES_CONTENT,
188
							[
189
								FUZZYLEVEL => FL_SUBSTRING | FL_IGNORECASE,
190
								ULPROPTAG => PR_ACCOUNT,
0 ignored issues
show
Bug introduced by
The constant PR_ACCOUNT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
191
								VALUE => $query,
192
							],
193
						],
194
						[
195
							RES_CONTENT,
196
							[
197
								FUZZYLEVEL => FL_SUBSTRING | FL_IGNORECASE,
198
								ULPROPTAG => PR_SMTP_ADDRESS,
0 ignored issues
show
Bug introduced by
The constant PR_SMTP_ADDRESS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
199
								VALUE => $query,
200
							],
201
						],
202
					], // RES_OR
203
				],
204
				[
205
					RES_OR,
206
					[
207
						[
208
							RES_PROPERTY,
209
							[
210
								RELOP => RELOP_EQ,
211
								ULPROPTAG => PR_OBJECT_TYPE,
0 ignored issues
show
Bug introduced by
The constant PR_OBJECT_TYPE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
212
								VALUE => MAPI_MAILUSER,
213
							],
214
						],
215
						[
216
							RES_PROPERTY,
217
							[
218
								RELOP => RELOP_EQ,
219
								ULPROPTAG => PR_OBJECT_TYPE,
220
								VALUE => MAPI_DISTLIST,
221
							],
222
						],
223
					],
224
				], // RES_OR
225
			], // RES_AND
226
		];
227
	}
228
229
	/**
230
	 * Create a MAPI restriction for a certain email address.
231
	 *
232
	 * @param MAPIStore $store the MAPI store
233
	 * @param string    $query email address
234
	 * @param mixed     $email
235
	 *
236
	 * @return array
237
	 */
238
	public static function GetEmailAddressRestriction($store, $email) {
239
		$props = MAPIMapping::GetContactProperties();
240
		$props = getPropIdsFromStrings($store, $props);
241
242
		return [
243
			RES_OR,
244
			[
245
				[
246
					RES_PROPERTY,
247
					[
248
						RELOP => RELOP_EQ,
249
						ULPROPTAG => $props['emailaddress1'],
250
						VALUE => [$props['emailaddress1'] => $email],
251
					],
252
				],
253
				[
254
					RES_PROPERTY,
255
					[
256
						RELOP => RELOP_EQ,
257
						ULPROPTAG => $props['emailaddress2'],
258
						VALUE => [$props['emailaddress2'] => $email],
259
					],
260
				],
261
				[
262
					RES_PROPERTY,
263
					[
264
						RELOP => RELOP_EQ,
265
						ULPROPTAG => $props['emailaddress3'],
266
						VALUE => [$props['emailaddress3'] => $email],
267
					],
268
				],
269
			],
270
		];
271
	}
272
273
	/**
274
	 * Create a MAPI restriction for a certain folder type.
275
	 *
276
	 * @param string $foldertype folder type for restriction
277
	 *
278
	 * @return array
279
	 */
280
	public static function GetFolderTypeRestriction($foldertype) {
281
		return [
282
			RES_PROPERTY,
283
			[
284
				RELOP => RELOP_EQ,
285
				ULPROPTAG => PR_CONTAINER_CLASS,
0 ignored issues
show
Bug introduced by
The constant PR_CONTAINER_CLASS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
286
				VALUE => [PR_CONTAINER_CLASS => $foldertype],
287
			],
288
		];
289
	}
290
291
	/**
292
	 * Returns subfolders of given type for a folder or false if there are none.
293
	 *
294
	 * @param MAPIFolder $folder
0 ignored issues
show
Bug introduced by
The type MAPIFolder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
295
	 * @param string     $type
296
	 *
297
	 * @return bool|MAPITable
0 ignored issues
show
Bug introduced by
The type MAPITable was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
298
	 */
299
	public static function GetSubfoldersForType($folder, $type) {
300
		$subfolders = mapi_folder_gethierarchytable($folder, CONVENIENT_DEPTH);
301
		mapi_table_restrict($subfolders, MAPIUtils::GetFolderTypeRestriction($type));
302
		if (mapi_table_getrowcount($subfolders) > 0) {
303
			return mapi_table_queryallrows($subfolders, [PR_ENTRYID]);
304
		}
305
306
		return false;
307
	}
308
309
	/**
310
	 * Checks if mapimessage is inside the synchronization interval
311
	 * also defined by MAPIUtils::GetEmailRestriction().
312
	 *
313
	 * @param MAPIStore   $store       mapi store
314
	 * @param MAPIMessage $mapimessage the mapi message to be checked
0 ignored issues
show
Bug introduced by
The type MAPIMessage was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
315
	 * @param long        $timestamp   the lower time limit
316
	 *
317
	 * @return bool
318
	 */
319
	public static function IsInEmailSyncInterval($store, $mapimessage, $timestamp) {
320
		$p = mapi_getprops($mapimessage, [PR_MESSAGE_DELIVERY_TIME]);
0 ignored issues
show
Bug introduced by
The constant PR_MESSAGE_DELIVERY_TIME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
321
322
		if (isset($p[PR_MESSAGE_DELIVERY_TIME]) && $p[PR_MESSAGE_DELIVERY_TIME] >= $timestamp) {
323
			SLog::Write(LOGLEVEL_DEBUG, "MAPIUtils->IsInEmailSyncInterval: Message is in the synchronization interval");
324
325
			return true;
326
		}
327
328
		SLog::Write(LOGLEVEL_WARN, "MAPIUtils->IsInEmailSyncInterval: Message is OUTSIDE the synchronization interval");
329
330
		return false;
331
	}
332
333
	/**
334
	 * Checks if mapimessage is inside the synchronization interval
335
	 * also defined by MAPIUtils::GetCalendarRestriction().
336
	 *
337
	 * @param MAPIStore   $store       mapi store
338
	 * @param MAPIMessage $mapimessage the mapi message to be checked
339
	 * @param long        $timestamp   the lower time limit
340
	 *
341
	 * @return bool
342
	 */
343
	public static function IsInCalendarSyncInterval($store, $mapimessage, $timestamp) {
344
		// This is our viewing window
345
		$start = $timestamp;
346
		$end = 0x7FFFFFFF; // infinite end
347
348
		$props = MAPIMapping::GetAppointmentProperties();
349
		$props = getPropIdsFromStrings($store, $props);
350
351
		$p = mapi_getprops($mapimessage, [$props["starttime"], $props["endtime"], $props["recurrenceend"], $props["isrecurring"], $props["recurrenceend"]]);
352
353
		if (
354
				(
355
					isset($p[$props["endtime"]], $p[$props["starttime"]]) &&
356
					// item.end > window.start && item.start < window.end
357
					$p[$props["endtime"]] > $start && $p[$props["starttime"]] < $end
358
				) ||
359
				(
360
					isset($p[$props["isrecurring"]], $p[$props["recurrenceend"]]) &&
361
						// (EXIST(recurrence_enddate_property) && item[isRecurring] == true && recurrence_enddate_property >= start)
362
						$p[$props["isrecurring"]] == true && $p[$props["recurrenceend"]] >= $start
363
				) ||
364
				(
365
					isset($p[$props["isrecurring"]], $p[$props["starttime"]]) &&
366
						// (!EXIST(recurrence_enddate_property) && item[isRecurring] == true && item[start] <= end)
367
						!isset($p[$props["recurrenceend"]]) && $p[$props["isrecurring"]] == true && $p[$props["starttime"]] <= $end
368
				)
369
			) {
370
			SLog::Write(LOGLEVEL_DEBUG, "MAPIUtils->IsInCalendarSyncInterval: Message is in the synchronization interval");
371
372
			return true;
373
		}
374
375
		SLog::Write(LOGLEVEL_WARN, "MAPIUtils->IsInCalendarSyncInterval: Message is OUTSIDE the synchronization interval");
376
377
		return false;
378
	}
379
380
	/**
381
	 * Checks if mapimessage is in a shared folder and private.
382
	 *
383
	 * @param string      $folderid    binary folderid of the message
384
	 * @param MAPIMessage $mapimessage the mapi message to be checked
385
	 *
386
	 * @return bool
387
	 */
388
	public static function IsMessageSharedAndPrivate($folderid, $mapimessage) {
389
		$sensitivity = mapi_getprops($mapimessage, [PR_SENSITIVITY]);
0 ignored issues
show
Bug introduced by
The constant PR_SENSITIVITY was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
390
		if (isset($sensitivity[PR_SENSITIVITY]) && $sensitivity[PR_SENSITIVITY] >= SENSITIVITY_PRIVATE) {
391
			$hexFolderid = bin2hex($folderid);
392
			$shortId = GSync::GetDeviceManager()->GetFolderIdForBackendId($hexFolderid);
393
			if (Utils::GetFolderOriginFromId($shortId) == DeviceManager::FLD_ORIGIN_IMPERSONATED) {
394
				SLog::Write(LOGLEVEL_DEBUG, sprintf("MAPIUtils->IsMessageSharedAndPrivate(): Message is in impersonated store '%s' and marked as private", GSync::GetBackend()->GetImpersonatedUser()));
395
396
				return true;
397
			}
398
			$sharedUser = GSync::GetAdditionalSyncFolderStore($hexFolderid);
399
			if (Utils::GetFolderOriginFromId($shortId) != DeviceManager::FLD_ORIGIN_USER && $sharedUser != false && $sharedUser != 'SYSTEM') {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $sharedUser of type string to the boolean false. If you are specifically checking for a non-empty string, consider using the more explicit !== '' instead.
Loading history...
400
				SLog::Write(LOGLEVEL_DEBUG, sprintf("MAPIUtils->IsMessageSharedAndPrivate(): Message is in shared store '%s' and marked as private", $sharedUser));
401
402
				return true;
403
			}
404
		}
405
406
		return false;
407
	}
408
409
	/**
410
	 * Reads data of large properties from a stream.
411
	 *
412
	 * @param MAPIMessage $message
413
	 * @param long        $prop
414
	 *
415
	 * @return string
416
	 */
417
	public static function readPropStream($message, $prop) {
418
		$stream = mapi_openproperty($message, $prop, IID_IStream, 0, 0);
419
		$ret = mapi_last_hresult();
420
		if ($ret == MAPI_E_NOT_FOUND) {
0 ignored issues
show
Bug introduced by
The constant MAPI_E_NOT_FOUND was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
421
			SLog::Write(LOGLEVEL_DEBUG, sprintf("MAPIUtils->readPropStream: property 0x%08X not found. It is either empty or not set. It will be ignored.", $prop));
422
423
			return "";
424
		}
425
		if ($ret) {
426
			SLog::Write(LOGLEVEL_ERROR, "MAPIUtils->readPropStream error opening stream: 0x%08X", $ret);
427
428
			return "";
429
		}
430
		$data = "";
0 ignored issues
show
Unused Code introduced by
The assignment to $data is dead and can be removed.
Loading history...
431
		$string = "";
432
		while (1) {
433
			$data = mapi_stream_read($stream, 1024);
434
			if (strlen($data) == 0) {
435
				break;
436
			}
437
			$string .= $data;
438
		}
439
440
		return $string;
441
	}
442
443
	/**
444
	 * Checks if a store supports properties containing unicode characters.
445
	 *
446
	 * @param MAPIStore $store
447
	 */
448
	public static function IsUnicodeStore($store) {
449
		$supportmask = mapi_getprops($store, [PR_STORE_SUPPORT_MASK]);
0 ignored issues
show
Bug introduced by
The constant PR_STORE_SUPPORT_MASK was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
450
		if (isset($supportmask[PR_STORE_SUPPORT_MASK]) && ($supportmask[PR_STORE_SUPPORT_MASK] & STORE_UNICODE_OK)) {
451
			SLog::Write(LOGLEVEL_DEBUG, "Store supports properties containing Unicode characters.");
452
			define('STORE_SUPPORTS_UNICODE', true);
453
			define('STORE_INTERNET_CPID', INTERNET_CPID_UTF8);
454
		}
455
	}
456
457
	/**
458
	 * Returns the MAPI PR_CONTAINER_CLASS string for an ActiveSync Foldertype.
459
	 *
460
	 * @param int $foldertype
461
	 *
462
	 * @return string
463
	 */
464
	public static function GetContainerClassFromFolderType($foldertype) {
465
		switch ($foldertype) {
466
			case SYNC_FOLDER_TYPE_TASK:
467
			case SYNC_FOLDER_TYPE_USER_TASK:
468
				return "IPF.Task";
469
				break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
470
471
			case SYNC_FOLDER_TYPE_APPOINTMENT:
472
			case SYNC_FOLDER_TYPE_USER_APPOINTMENT:
473
				return "IPF.Appointment";
474
				break;
475
476
			case SYNC_FOLDER_TYPE_CONTACT:
477
			case SYNC_FOLDER_TYPE_USER_CONTACT:
478
				return "IPF.Contact";
479
				break;
480
481
			case SYNC_FOLDER_TYPE_NOTE:
482
			case SYNC_FOLDER_TYPE_USER_NOTE:
483
				return "IPF.StickyNote";
484
				break;
485
486
			case SYNC_FOLDER_TYPE_JOURNAL:
487
			case SYNC_FOLDER_TYPE_USER_JOURNAL:
488
				return "IPF.Journal";
489
				break;
490
491
			case SYNC_FOLDER_TYPE_INBOX:
492
			case SYNC_FOLDER_TYPE_DRAFTS:
493
			case SYNC_FOLDER_TYPE_WASTEBASKET:
494
			case SYNC_FOLDER_TYPE_SENTMAIL:
495
			case SYNC_FOLDER_TYPE_OUTBOX:
496
			case SYNC_FOLDER_TYPE_USER_MAIL:
497
			case SYNC_FOLDER_TYPE_OTHER:
498
			case SYNC_FOLDER_TYPE_UNKNOWN:
499
			default:
500
				return "IPF.Note";
501
				break;
502
		}
503
	}
504
505
	/**
506
	 * Returns the ActiveSync (USER) Foldertype from MAPI PR_CONTAINER_CLASS.
507
	 *
508
	 * @param string $foldertype
509
	 * @param mixed  $class
510
	 *
511
	 * @return int
512
	 */
513
	public static function GetFolderTypeFromContainerClass($class) {
514
		if ($class == "IPF.Note") {
515
			return SYNC_FOLDER_TYPE_USER_MAIL;
516
		}
517
		if ($class == "IPF.Task") {
518
			return SYNC_FOLDER_TYPE_USER_TASK;
519
		}
520
		if ($class == "IPF.Appointment") {
521
			return SYNC_FOLDER_TYPE_USER_APPOINTMENT;
522
		}
523
		if ($class == "IPF.Contact") {
524
			return SYNC_FOLDER_TYPE_USER_CONTACT;
525
		}
526
		if ($class == "IPF.StickyNote") {
527
			return SYNC_FOLDER_TYPE_USER_NOTE;
528
		}
529
		if ($class == "IPF.Journal") {
530
			return SYNC_FOLDER_TYPE_USER_JOURNAL;
531
		}
532
533
		return SYNC_FOLDER_TYPE_OTHER;
534
	}
535
536
	public static function GetSignedAttachmentRestriction() {
537
		return [
538
			RES_PROPERTY,
539
			[
540
				RELOP => RELOP_EQ,
541
				ULPROPTAG => PR_ATTACH_MIME_TAG,
0 ignored issues
show
Bug introduced by
The constant PR_ATTACH_MIME_TAG was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
542
				VALUE => [PR_ATTACH_MIME_TAG => 'multipart/signed'],
543
			],
544
		];
545
	}
546
547
	/**
548
	 * Calculates the native body type of a message using available properties. Refer to oxbbody.
549
	 *
550
	 * @param array $messageprops
551
	 *
552
	 * @return int
553
	 */
554
	public static function GetNativeBodyType($messageprops) {
555
		// check if the properties are set and get the error code if needed
556
		if (!isset($messageprops[PR_BODY])) {
0 ignored issues
show
Bug introduced by
The constant PR_BODY was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
557
			$messageprops[PR_BODY] = self::GetError(PR_BODY, $messageprops);
558
		}
559
		if (!isset($messageprops[PR_RTF_COMPRESSED])) {
0 ignored issues
show
Bug introduced by
The constant PR_RTF_COMPRESSED was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
560
			$messageprops[PR_RTF_COMPRESSED] = self::GetError(PR_RTF_COMPRESSED, $messageprops);
561
		}
562
		if (!isset($messageprops[PR_HTML])) {
0 ignored issues
show
Bug introduced by
The constant PR_HTML was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
563
			$messageprops[PR_HTML] = self::GetError(PR_HTML, $messageprops);
564
		}
565
		if (!isset($messageprops[PR_RTF_IN_SYNC])) {
0 ignored issues
show
Bug introduced by
The constant PR_RTF_IN_SYNC was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
566
			$messageprops[PR_RTF_IN_SYNC] = self::GetError(PR_RTF_IN_SYNC, $messageprops);
567
		}
568
569
		if ( // 1
570
				($messageprops[PR_BODY] == MAPI_E_NOT_FOUND) &&
0 ignored issues
show
Bug introduced by
The constant MAPI_E_NOT_FOUND was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
571
				($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_FOUND) &&
572
				($messageprops[PR_HTML] == MAPI_E_NOT_FOUND)) {
573
			return SYNC_BODYPREFERENCE_PLAIN;
574
		}
575
		if ( // 2
576
				($messageprops[PR_BODY] == MAPI_E_NOT_ENOUGH_MEMORY) &&
0 ignored issues
show
Bug introduced by
The constant MAPI_E_NOT_ENOUGH_MEMORY was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
577
				($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_FOUND) &&
578
				($messageprops[PR_HTML] == MAPI_E_NOT_FOUND)) {
579
			return SYNC_BODYPREFERENCE_PLAIN;
580
		}
581
		if ( // 3
582
				($messageprops[PR_BODY] == MAPI_E_NOT_ENOUGH_MEMORY) &&
583
				($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) &&
584
				($messageprops[PR_HTML] == MAPI_E_NOT_FOUND)) {
585
			return SYNC_BODYPREFERENCE_RTF;
586
		}
587
		if ( // 4
588
				($messageprops[PR_BODY] == MAPI_E_NOT_ENOUGH_MEMORY) &&
589
				($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) &&
590
				($messageprops[PR_HTML] == MAPI_E_NOT_ENOUGH_MEMORY) &&
591
				$messageprops[PR_RTF_IN_SYNC]) {
592
			return SYNC_BODYPREFERENCE_RTF;
593
		}
594
		if ( // 5
595
				($messageprops[PR_BODY] == MAPI_E_NOT_ENOUGH_MEMORY) &&
596
				($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) &&
597
				($messageprops[PR_HTML] == MAPI_E_NOT_ENOUGH_MEMORY) &&
598
				(!$messageprops[PR_RTF_IN_SYNC])) {
599
			return SYNC_BODYPREFERENCE_HTML;
600
		}
601
		if ( // 6
602
				($messageprops[PR_RTF_COMPRESSED] != MAPI_E_NOT_FOUND || $messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) &&
603
				($messageprops[PR_HTML] != MAPI_E_NOT_FOUND || $messageprops[PR_HTML] == MAPI_E_NOT_ENOUGH_MEMORY) &&
604
				$messageprops[PR_RTF_IN_SYNC]) {
605
			return SYNC_BODYPREFERENCE_RTF;
606
		}
607
		if ( // 7
608
				($messageprops[PR_RTF_COMPRESSED] != MAPI_E_NOT_FOUND || $messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) &&
609
				($messageprops[PR_HTML] != MAPI_E_NOT_FOUND || $messageprops[PR_HTML] == MAPI_E_NOT_ENOUGH_MEMORY) &&
610
				(!$messageprops[PR_RTF_IN_SYNC])) {
611
			return SYNC_BODYPREFERENCE_HTML;
612
		}
613
		if ( // 8
614
				($messageprops[PR_BODY] != MAPI_E_NOT_FOUND || $messageprops[PR_BODY] == MAPI_E_NOT_ENOUGH_MEMORY) &&
615
				($messageprops[PR_RTF_COMPRESSED] != MAPI_E_NOT_FOUND || $messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) &&
616
				$messageprops[PR_RTF_IN_SYNC]) {
617
			return SYNC_BODYPREFERENCE_RTF;
618
		}
619
		if ( // 9.1
620
				($messageprops[PR_BODY] != MAPI_E_NOT_FOUND || $messageprops[PR_BODY] == MAPI_E_NOT_ENOUGH_MEMORY) &&
621
				($messageprops[PR_RTF_COMPRESSED] != MAPI_E_NOT_FOUND || $messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) &&
622
				(!$messageprops[PR_RTF_IN_SYNC])) {
623
			return SYNC_BODYPREFERENCE_PLAIN;
624
		}
625
		if ( // 9.2
626
				($messageprops[PR_RTF_COMPRESSED] != MAPI_E_NOT_FOUND || $messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) &&
627
				($messageprops[PR_BODY] == MAPI_E_NOT_FOUND) &&
628
				($messageprops[PR_HTML] == MAPI_E_NOT_FOUND)) {
629
			return SYNC_BODYPREFERENCE_RTF;
630
		}
631
		if ( // 9.3
632
				($messageprops[PR_BODY] != MAPI_E_NOT_FOUND || $messageprops[PR_BODY] == MAPI_E_NOT_ENOUGH_MEMORY) &&
633
				($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_FOUND) &&
634
				($messageprops[PR_HTML] == MAPI_E_NOT_FOUND)) {
635
			return SYNC_BODYPREFERENCE_PLAIN;
636
		}
637
		if ( // 9.4
638
				($messageprops[PR_HTML] != MAPI_E_NOT_FOUND || $messageprops[PR_HTML] == MAPI_E_NOT_ENOUGH_MEMORY) &&
639
				($messageprops[PR_BODY] == MAPI_E_NOT_FOUND) &&
640
				($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_FOUND)) {
641
			return SYNC_BODYPREFERENCE_HTML;
642
		}
643
		// 10
644
		return SYNC_BODYPREFERENCE_PLAIN;
645
	}
646
647
	/**
648
	 * Returns the error code for a given property.
649
	 * Helper for MAPIUtils::GetNativeBodyType() function but also used in other places.
650
	 *
651
	 * @param int   $tag
652
	 * @param array $messageprops
653
	 *
654
	 * @return int (MAPI_ERROR_CODE)
655
	 */
656
	public static function GetError($tag, $messageprops) {
657
		$prBodyError = mapi_prop_tag(PT_ERROR, mapi_prop_id($tag));
658
		if (isset($messageprops[$prBodyError]) && mapi_is_error($messageprops[$prBodyError])) {
659
			if ($messageprops[$prBodyError] == MAPI_E_NOT_ENOUGH_MEMORY_32BIT ||
660
					$messageprops[$prBodyError] == MAPI_E_NOT_ENOUGH_MEMORY_64BIT) {
661
				return MAPI_E_NOT_ENOUGH_MEMORY;
0 ignored issues
show
Bug introduced by
The constant MAPI_E_NOT_ENOUGH_MEMORY was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
662
			}
663
		}
664
665
		return MAPI_E_NOT_FOUND;
0 ignored issues
show
Bug introduced by
The constant MAPI_E_NOT_FOUND was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
666
	}
667
668
	/**
669
	 * Function will be used to decode smime messages and convert it to normal messages.
670
	 *
671
	 * @param MAPISession    $session
0 ignored issues
show
Bug introduced by
The type MAPISession was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
672
	 * @param MAPIStore      $store
673
	 * @param MAPIAdressBook $addressBook
0 ignored issues
show
Bug introduced by
The type MAPIAdressBook was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
674
	 * @param MAPIMessage    $message     smime message
675
	 * @param mixed          $mapimessage
676
	 */
677
	public static function ParseSmime($session, $store, $addressBook, &$mapimessage) {
678
		$props = mapi_getprops($mapimessage, [
679
			PR_MESSAGE_CLASS,
0 ignored issues
show
Bug introduced by
The constant PR_MESSAGE_CLASS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
680
			PR_SUBJECT,
0 ignored issues
show
Bug introduced by
The constant PR_SUBJECT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
681
			PR_MESSAGE_DELIVERY_TIME,
0 ignored issues
show
Bug introduced by
The constant PR_MESSAGE_DELIVERY_TIME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
682
			PR_SENT_REPRESENTING_NAME,
0 ignored issues
show
Bug introduced by
The constant PR_SENT_REPRESENTING_NAME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
683
			PR_SENT_REPRESENTING_ENTRYID,
0 ignored issues
show
Bug introduced by
The constant PR_SENT_REPRESENTING_ENTRYID was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
684
			PR_SENT_REPRESENTING_SEARCH_KEY,
0 ignored issues
show
Bug introduced by
The constant PR_SENT_REPRESENTING_SEARCH_KEY was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
685
			PR_MESSAGE_FLAGS,
0 ignored issues
show
Bug introduced by
The constant PR_MESSAGE_FLAGS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
686
		]);
687
		$read = $props[PR_MESSAGE_FLAGS] & MSGFLAG_READ;
688
689
		if (isset($props[PR_MESSAGE_CLASS]) && stripos($props[PR_MESSAGE_CLASS], 'IPM.Note.SMIME.MultipartSigned') !== false) {
690
			// this is a signed message. decode it.
691
			$attachTable = mapi_message_getattachmenttable($mapimessage);
692
			$rows = mapi_table_queryallrows($attachTable, [PR_ATTACH_MIME_TAG, PR_ATTACH_NUM]);
0 ignored issues
show
Bug introduced by
The constant PR_ATTACH_MIME_TAG was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant PR_ATTACH_NUM was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
693
			$attnum = false;
694
695
			foreach ($rows as $row) {
696
				if (isset($row[PR_ATTACH_MIME_TAG]) && $row[PR_ATTACH_MIME_TAG] == 'multipart/signed') {
697
					$attnum = $row[PR_ATTACH_NUM];
698
				}
699
			}
700
701
			if ($attnum !== false) {
702
				$att = mapi_message_openattach($mapimessage, $attnum);
703
				$data = mapi_openproperty($att, PR_ATTACH_DATA_BIN);
0 ignored issues
show
Bug introduced by
The constant PR_ATTACH_DATA_BIN was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
704
				mapi_message_deleteattach($mapimessage, $attnum);
705
				// also copy recipients because they are lost after mapi_inetmapi_imtomapi
706
				$recipienttable = mapi_message_getrecipienttable($mapimessage);
707
				$messageRecipients = mapi_table_queryallrows($recipienttable, [
708
					PR_ENTRYID,
709
					PR_SEARCH_KEY,
0 ignored issues
show
Bug introduced by
The constant PR_SEARCH_KEY was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
710
					PR_ROWID,
0 ignored issues
show
Bug introduced by
The constant PR_ROWID was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
711
					PR_DISPLAY_NAME,
0 ignored issues
show
Bug introduced by
The constant PR_DISPLAY_NAME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
712
					PR_DISPLAY_TYPE,
0 ignored issues
show
Bug introduced by
The constant PR_DISPLAY_TYPE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
713
					PR_DISPLAY_TYPE_EX,
0 ignored issues
show
Bug introduced by
The constant PR_DISPLAY_TYPE_EX was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
714
					PR_ADDRTYPE,
0 ignored issues
show
Bug introduced by
The constant PR_ADDRTYPE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
715
					PR_EMAIL_ADDRESS,
0 ignored issues
show
Bug introduced by
The constant PR_EMAIL_ADDRESS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
716
					PR_SMTP_ADDRESS,
0 ignored issues
show
Bug introduced by
The constant PR_SMTP_ADDRESS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
717
					PR_OBJECT_TYPE,
0 ignored issues
show
Bug introduced by
The constant PR_OBJECT_TYPE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
718
					PR_RECIPIENT_FLAGS,
0 ignored issues
show
Bug introduced by
The constant PR_RECIPIENT_FLAGS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
719
					PR_RECIPIENT_TYPE,
0 ignored issues
show
Bug introduced by
The constant PR_RECIPIENT_TYPE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
720
					PR_RECIPIENT_TRACKSTATUS,
0 ignored issues
show
Bug introduced by
The constant PR_RECIPIENT_TRACKSTATUS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
721
					PR_RECIPIENT_TRACKSTATUS_TIME,
0 ignored issues
show
Bug introduced by
The constant PR_RECIPIENT_TRACKSTATUS_TIME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
722
					PR_CREATION_TIME,
0 ignored issues
show
Bug introduced by
The constant PR_CREATION_TIME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
723
				]);
724
				mapi_inetmapi_imtomapi($session, $store, $addressBook, $mapimessage, $data, ["parse_smime_signed" => 1]);
725
				if (!empty($messageRecipients)) {
726
					mapi_message_modifyrecipients($mapimessage, MODRECIP_ADD, $messageRecipients);
727
				}
728
				SLog::Write(LOGLEVEL_DEBUG, "Convert a smime signed message to a normal message.");
729
			}
730
			$mprops = mapi_getprops($mapimessage, [PR_MESSAGE_FLAGS]);
731
			// Workaround for issue 13
732
			mapi_setprops($mapimessage, [
733
				PR_MESSAGE_CLASS => 'IPM.Note.SMIME.MultipartSigned',
734
				PR_SUBJECT => $props[PR_SUBJECT],
735
				PR_MESSAGE_DELIVERY_TIME => $props[PR_MESSAGE_DELIVERY_TIME],
736
				PR_SENT_REPRESENTING_NAME => $props[PR_SENT_REPRESENTING_NAME],
737
				PR_SENT_REPRESENTING_ENTRYID => $props[PR_SENT_REPRESENTING_ENTRYID],
738
				PR_SENT_REPRESENTING_SEARCH_KEY => $props[PR_SENT_REPRESENTING_SEARCH_KEY],
739
				// mark the message as read if the main message has read flag
740
				PR_MESSAGE_FLAGS => $read ? $mprops[PR_MESSAGE_FLAGS] | MSGFLAG_READ : $mprops[PR_MESSAGE_FLAGS],
741
			]);
742
		}
743
		// TODO check if we need to do this for encrypted (and signed?) message as well
744
	}
745
746
	/**
747
	 * Compares two entryIds. It is possible to have two different entryIds that should match as they
748
	 * represent the same object (in multiserver environments).
749
	 *
750
	 * @param string $entryId1
751
	 * @param string $entryId2
752
	 *
753
	 * @return bool
754
	 */
755
	public static function CompareEntryIds($entryId1, $entryId2) {
756
		if (!is_string($entryId1) || !is_string($entryId2)) {
0 ignored issues
show
introduced by
The condition is_string($entryId2) is always true.
Loading history...
introduced by
The condition is_string($entryId1) is always true.
Loading history...
757
			return false;
758
		}
759
760
		if ($entryId1 === $entryId2) {
761
			// if normal comparison succeeds then we can directly say that entryids are same
762
			return true;
763
		}
764
765
		$eid1 = self::createEntryIdObj($entryId1);
766
		$eid2 = self::createEntryIdObj($entryId2);
767
768
		if ($eid1['length'] != $eid2['length'] ||
769
				$eid1['abFlags'] != $eid2['abFlags'] ||
770
				$eid1['version'] != $eid2['version'] ||
771
				$eid1['type'] != $eid2['type']) {
772
			return false;
773
		}
774
775
		if ($eid1['name'] == 'EID_V0') {
776
			if ($eid1['length'] < $eid1['min_length'] || $eid1['id'] != $eid2['id']) {
777
				return false;
778
			}
779
		}
780
		elseif ($eid1['length'] < $eid1['min_length'] || $eid1['uniqueId'] != $eid2['uniqueId']) {
781
			return false;
782
		}
783
784
		return true;
785
	}
786
787
	/**
788
	 * Creates an object that has split up all the components of an entryID.
789
	 *
790
	 * @param string $entryid Entryid
791
	 *
792
	 * @return object EntryID object
793
	 */
794
	private static function createEntryIdObj($entryid) {
795
		// check if we are dealing with old or new object entryids
796
		return (substr($entryid, 40, 8) == '00000000') ? self::getEID_V0Version($entryid) : self::getEIDVersion($entryid);
0 ignored issues
show
Bug Best Practice introduced by
The expression return substr($entryid, ...getEIDVersion($entryid) also could return the type array<string,string> which is incompatible with the documented return type object.
Loading history...
797
	}
798
799
	/**
800
	 * The entryid from the begin of zarafa till 5.20.
801
	 *
802
	 * @param string $entryid
803
	 *
804
	 * @return object EntryID object
805
	 */
806
	private static function getEID_V0Version($entryid) {
807
		// always make entryids in uppercase so comparison will be case insensitive
808
		$entryId = strtoupper($entryid);
809
810
		$res = [
811
			'abFlags' => '',  // BYTE[4],  4 bytes,  8 hex characters
812
			'guid' => '',  // GUID,    16 bytes, 32 hex characters
813
			'version' => '',  // ULONG,    4 bytes,  8 hex characters
814
			'type' => '',  // ULONG,    4 bytes,  8 hex characters
815
			'id' => '',  // ULONG,    4 bytes,  8 hex characters
816
			'server' => '',  // CHAR,    variable length
817
			'padding' => '',  // TCHAR[3], 4 bytes,  8 hex characters (upto 4 bytes)
818
		];
819
820
		$res['length'] = strlen($entryId);
821
		$offset = 0;
822
823
		// First determine padding, and remove if from the entryId
824
		$res['padding'] = self::getPadding($entryId);
825
		$entryId = substr($entryId, 0, strlen($entryId) - strlen($res['padding']));
826
827
		$res['abFlags'] = substr($entryId, $offset, 8);
828
		$offset = +8;
829
830
		$res['guid'] = substr($entryId, $offset, 32);
831
		$offset += 32;
832
833
		$res['version'] = substr($entryId, $offset, 8);
834
		$offset += 8;
835
836
		$res['type'] = substr($entryId, $offset, 8);
837
		$offset += 8;
838
839
		$res['id'] = substr($entryId, $offset, 8);
840
		$offset += 8;
841
842
		$res['server'] = substr($entryId, $offset);
843
844
		$res['min_length'] = 64;
845
		$res['name'] = 'EID_V0';
846
847
		return $res;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $res returns the type array<string,string> which is incompatible with the documented return type object.
Loading history...
848
	}
849
850
	/**
851
	 * Entryid from version 6.
852
	 *
853
	 * @param string $entryid
854
	 *
855
	 * @return null[]|number[]|string[]
856
	 */
857
	private static function getEIDVersion($entryid) {
858
		// always make entryids in uppercase so comparison will be case insensitive
859
		$entryId = strtoupper($entryid);
860
861
		$res = [
862
			'abFlags' => '',  // BYTE[4],  4 bytes,  8 hex characters
863
			'guid' => '',  // GUID,    16 bytes, 32 hex characters
864
			'version' => '',  // ULONG,    4 bytes,  8 hex characters
865
			'type' => '',  // ULONG,    4 bytes,  8 hex characters
866
			'uniqueId' => '',  // ULONG,   16 bytes,  32 hex characters
867
			'server' => '',  // CHAR,    variable length
868
			'padding' => '',  // TCHAR[3], 4 bytes,  8 hex characters (upto 4 bytes)
869
		];
870
871
		$res['length'] = strlen($entryId);
872
		$offset = 0;
873
874
		// First determine padding, and remove if from the entryId
875
		$res['padding'] = self::getPadding($entryId);
876
		$entryId = substr($entryId, 0, strlen($entryId) - strlen($res['padding']));
877
878
		$res['abFlags'] = substr($entryId, $offset, 8);
879
		$offset = +8;
880
881
		$res['guid'] = substr($entryId, $offset, 32);
882
		$offset += 32;
883
884
		$res['version'] = substr($entryId, $offset, 8);
885
		$offset += 8;
886
887
		$res['type'] = substr($entryId, $offset, 8);
888
		$offset += 8;
889
890
		$res['uniqueId'] = substr($entryId, $offset, 32);
891
		$offset += 32;
892
893
		$res['server'] = substr($entryId, $offset);
894
895
		$res['min_length'] = 88;
896
		$res['name'] = 'EID';
897
898
		return $res;
899
	}
900
901
	/**
902
	 * Detect padding (max 3 bytes) from the entryId.
903
	 *
904
	 * @param string $entryId
905
	 *
906
	 * @return string
907
	 */
908
	private static function getPadding($entryId) {
909
		$len = strlen($entryId);
910
		$padding = '';
911
		$offset = 0;
912
913
		for ($iterations = 4; $iterations > 0; --$iterations) {
914
			if (substr($entryId, $len - ($offset + 2), $len - $offset) == '00') {
915
				$padding .= '00';
916
				$offset += 2;
917
			}
918
			else {
919
				// if non-null character found then break the loop
920
				break;
921
			}
922
		}
923
924
		return $padding;
925
	}
926
}
927