MAPIUtils::IsMessageSharedAndPrivate()   B
last analyzed

Complexity

Conditions 7
Paths 4

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 12
nop 2
dl 0
loc 19
rs 8.8333
c 0
b 0
f 0
nc 4
1
<?php
2
3
/*
4
 * SPDX-License-Identifier: AGPL-3.0-only
5
 * SPDX-FileCopyrightText: Copyright 2007-2013,2016 Zarafa Deutschland GmbH
6
 * SPDX-FileCopyrightText: Copyright 2020-2025 grommunio GmbH
7
 */
8
9
/**
10
 * MAPI utility functions.
11
 */
12
class MAPIUtils {
13
	/**
14
	 * Create a MAPI restriction to use within an email folder which will
15
	 * return all messages since since $timestamp.
16
	 *
17
	 * @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...
18
	 *
19
	 * @return array
20
	 */
21
	public static function GetEmailRestriction($timestamp) {
22
		// ATTENTION: ON CHANGING THIS RESTRICTION, MAPIUtils::IsInEmailSyncInterval() also needs to be changed
23
		return [
24
			RES_PROPERTY,
0 ignored issues
show
Bug introduced by
The constant RES_PROPERTY was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
25
			[
26
				RELOP => RELOP_GE,
0 ignored issues
show
Bug introduced by
The constant RELOP was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant RELOP_GE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
27
				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...
Bug introduced by
The constant ULPROPTAG was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
28
				VALUE => $timestamp,
0 ignored issues
show
Bug introduced by
The constant VALUE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
29
			],
30
		];
31
	}
32
33
	/**
34
	 * Create a MAPI restriction to use in the calendar which will
35
	 * return all future calendar items, plus those since $timestamp.
36
	 *
37
	 * @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...
38
	 * @param long      $timestamp Timestamp since when to include messages
39
	 *
40
	 * @return array
41
	 */
42
	// TODO getting named properties
43
	public static function GetCalendarRestriction($store, $timestamp) {
44
		// This is our viewing window
45
		$start = $timestamp;
46
		$end = 0x7FFFFFFF; // infinite end
47
48
		$props = MAPIMapping::GetAppointmentProperties();
49
		$props = getPropIdsFromStrings($store, $props);
0 ignored issues
show
Bug introduced by
The function getPropIdsFromStrings 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

49
		$props = /** @scrutinizer ignore-call */ getPropIdsFromStrings($store, $props);
Loading history...
50
51
		// ATTENTION: ON CHANGING THIS RESTRICTION, MAPIUtils::IsInCalendarSyncInterval() also needs to be changed
52
		return [
53
			RES_OR,
0 ignored issues
show
Bug introduced by
The constant RES_OR was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
54
			[
55
				// OR
56
				// item.end > window.start && item.start < window.end
57
				[
58
					RES_AND,
0 ignored issues
show
Bug introduced by
The constant RES_AND was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
59
					[
60
						[
61
							RES_PROPERTY,
0 ignored issues
show
Bug introduced by
The constant RES_PROPERTY was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
62
							[
63
								RELOP => RELOP_LE,
0 ignored issues
show
Bug introduced by
The constant RELOP_LE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant RELOP was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
64
								ULPROPTAG => $props["starttime"],
0 ignored issues
show
Bug introduced by
The constant ULPROPTAG was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
65
								VALUE => $end,
0 ignored issues
show
Bug introduced by
The constant VALUE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
66
							],
67
						],
68
						[
69
							RES_PROPERTY,
70
							[
71
								RELOP => RELOP_GE,
0 ignored issues
show
Bug introduced by
The constant RELOP_GE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
72
								ULPROPTAG => $props["endtime"],
73
								VALUE => $start,
74
							],
75
						],
76
					],
77
				],
78
				// OR
79
				[
80
					RES_OR,
81
					[
82
						// OR
83
						// (EXIST(recurrence_enddate_property) && item[isRecurring] == true && recurrence_enddate_property >= start)
84
						[
85
							RES_AND,
86
							[
87
								[
88
									RES_EXIST,
0 ignored issues
show
Bug introduced by
The constant RES_EXIST was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
89
									[ULPROPTAG => $props["recurrenceend"],
90
									],
91
								],
92
								[
93
									RES_PROPERTY,
94
									[
95
										RELOP => RELOP_EQ,
0 ignored issues
show
Bug introduced by
The constant RELOP_EQ was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
96
										ULPROPTAG => $props["isrecurring"],
97
										VALUE => true,
98
									],
99
								],
100
								[
101
									RES_PROPERTY,
102
									[
103
										RELOP => RELOP_GE,
104
										ULPROPTAG => $props["recurrenceend"],
105
										VALUE => $start,
106
									],
107
								],
108
							],
109
						],
110
						// OR
111
						// (!EXIST(recurrence_enddate_property) && item[isRecurring] == true && item[start] <= end)
112
						[
113
							RES_AND,
114
							[
115
								[
116
									RES_NOT,
0 ignored issues
show
Bug introduced by
The constant RES_NOT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
117
									[
118
										[
119
											RES_EXIST,
120
											[ULPROPTAG => $props["recurrenceend"],
121
											],
122
										],
123
									],
124
								],
125
								[
126
									RES_PROPERTY,
127
									[
128
										RELOP => RELOP_LE,
129
										ULPROPTAG => $props["starttime"],
130
										VALUE => $end,
131
									],
132
								],
133
								[
134
									RES_PROPERTY,
135
									[
136
										RELOP => RELOP_EQ,
137
										ULPROPTAG => $props["isrecurring"],
138
										VALUE => true,
139
									],
140
								],
141
							],
142
						],
143
					],
144
				], // EXISTS OR
145
			],
146
		];        // global OR
147
	}
148
149
	/**
150
	 * Create a MAPI restriction in order to check if a contact has a picture.
151
	 *
152
	 * @return array
153
	 */
154
	public static function GetContactPicRestriction() {
155
		return [
156
			RES_PROPERTY,
0 ignored issues
show
Bug introduced by
The constant RES_PROPERTY was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
157
			[
158
				RELOP => RELOP_EQ,
0 ignored issues
show
Bug introduced by
The constant RELOP was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant RELOP_EQ was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
159
				ULPROPTAG => mapi_prop_tag(PT_BOOLEAN, 0x7FFF),
0 ignored issues
show
Bug introduced by
The constant PT_BOOLEAN was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant ULPROPTAG was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
160
				VALUE => true,
0 ignored issues
show
Bug introduced by
The constant VALUE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
161
			],
162
		];
163
	}
164
165
	/**
166
	 * Create a MAPI restriction for search.
167
	 *
168
	 * @param string $query
169
	 *
170
	 * @return array
171
	 */
172
	public static function GetSearchRestriction($query) {
173
		return [
174
			RES_AND,
0 ignored issues
show
Bug introduced by
The constant RES_AND was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
175
			[
176
				[
177
					RES_OR,
0 ignored issues
show
Bug introduced by
The constant RES_OR was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
178
					[
179
						[
180
							RES_CONTENT,
0 ignored issues
show
Bug introduced by
The constant RES_CONTENT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
181
							[
182
								FUZZYLEVEL => FL_SUBSTRING | FL_IGNORECASE,
0 ignored issues
show
Bug introduced by
The constant FL_SUBSTRING was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant FUZZYLEVEL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant FL_IGNORECASE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
183
								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...
Bug introduced by
The constant ULPROPTAG was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
184
								VALUE => $query,
0 ignored issues
show
Bug introduced by
The constant VALUE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
185
							],
186
						],
187
						[
188
							RES_CONTENT,
189
							[
190
								FUZZYLEVEL => FL_SUBSTRING | FL_IGNORECASE,
191
								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...
192
								VALUE => $query,
193
							],
194
						],
195
						[
196
							RES_CONTENT,
197
							[
198
								FUZZYLEVEL => FL_SUBSTRING | FL_IGNORECASE,
199
								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...
200
								VALUE => $query,
201
							],
202
						],
203
					], // RES_OR
204
				],
205
				[
206
					RES_OR,
207
					[
208
						[
209
							RES_PROPERTY,
0 ignored issues
show
Bug introduced by
The constant RES_PROPERTY was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
210
							[
211
								RELOP => RELOP_EQ,
0 ignored issues
show
Bug introduced by
The constant RELOP was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant RELOP_EQ was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
212
								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...
213
								VALUE => MAPI_MAILUSER,
0 ignored issues
show
Bug introduced by
The constant MAPI_MAILUSER was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
214
							],
215
						],
216
						[
217
							RES_PROPERTY,
218
							[
219
								RELOP => RELOP_EQ,
220
								ULPROPTAG => PR_OBJECT_TYPE,
221
								VALUE => MAPI_DISTLIST,
0 ignored issues
show
Bug introduced by
The constant MAPI_DISTLIST was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
222
							],
223
						],
224
					],
225
				], // RES_OR
226
			], // RES_AND
227
		];
228
	}
229
230
	/**
231
	 * Create a MAPI restriction for a certain email address.
232
	 *
233
	 * @param MAPIStore $store the MAPI store
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);
0 ignored issues
show
Bug introduced by
The function getPropIdsFromStrings 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

240
		$props = /** @scrutinizer ignore-call */ getPropIdsFromStrings($store, $props);
Loading history...
241
242
		return [
243
			RES_OR,
0 ignored issues
show
Bug introduced by
The constant RES_OR was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
244
			[
245
				[
246
					RES_PROPERTY,
0 ignored issues
show
Bug introduced by
The constant RES_PROPERTY was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
247
					[
248
						RELOP => RELOP_EQ,
0 ignored issues
show
Bug introduced by
The constant RELOP_EQ was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant RELOP was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
249
						ULPROPTAG => $props['emailaddress1'],
0 ignored issues
show
Bug introduced by
The constant ULPROPTAG was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
250
						VALUE => [$props['emailaddress1'] => $email],
0 ignored issues
show
Bug introduced by
The constant VALUE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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,
0 ignored issues
show
Bug introduced by
The constant RES_PROPERTY was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
283
			[
284
				RELOP => RELOP_EQ,
0 ignored issues
show
Bug introduced by
The constant RELOP was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant RELOP_EQ was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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...
Bug introduced by
The constant ULPROPTAG was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
286
				VALUE => [PR_CONTAINER_CLASS => $foldertype],
0 ignored issues
show
Bug introduced by
The constant VALUE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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);
0 ignored issues
show
Bug introduced by
The constant CONVENIENT_DEPTH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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);
0 ignored issues
show
Bug introduced by
The function getPropIdsFromStrings 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

349
		$props = /** @scrutinizer ignore-call */ getPropIdsFromStrings($store, $props);
Loading history...
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) {
0 ignored issues
show
Bug introduced by
The constant SENSITIVITY_PRIVATE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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);
0 ignored issues
show
Bug introduced by
The constant IID_IStream was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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, sprintf("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)) {
0 ignored issues
show
Bug introduced by
The constant STORE_UNICODE_OK was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
451
			SLog::Write(LOGLEVEL_DEBUG, "Store supports properties containing Unicode characters.");
452
			define('STORE_INTERNET_CPID', INTERNET_CPID_UTF8);
453
		}
454
	}
455
456
	/**
457
	 * Returns the MAPI PR_CONTAINER_CLASS string for an ActiveSync Foldertype.
458
	 *
459
	 * @param int $foldertype
460
	 *
461
	 * @return string
462
	 */
463
	public static function GetContainerClassFromFolderType($foldertype) {
464
		return match ($foldertype) {
465
			SYNC_FOLDER_TYPE_TASK, SYNC_FOLDER_TYPE_USER_TASK => "IPF.Task",
466
			SYNC_FOLDER_TYPE_APPOINTMENT, SYNC_FOLDER_TYPE_USER_APPOINTMENT => "IPF.Appointment",
467
			SYNC_FOLDER_TYPE_CONTACT, SYNC_FOLDER_TYPE_USER_CONTACT => "IPF.Contact",
468
			SYNC_FOLDER_TYPE_NOTE, SYNC_FOLDER_TYPE_USER_NOTE => "IPF.StickyNote",
469
			SYNC_FOLDER_TYPE_JOURNAL, SYNC_FOLDER_TYPE_USER_JOURNAL => "IPF.Journal",
470
			default => "IPF.Note",
471
		};
472
	}
473
474
	/**
475
	 * Returns the ActiveSync (USER) Foldertype from MAPI PR_CONTAINER_CLASS.
476
	 *
477
	 * @param mixed $class
478
	 *
479
	 * @return int
480
	 */
481
	public static function GetFolderTypeFromContainerClass($class) {
482
		if ($class == "IPF.Note") {
483
			return SYNC_FOLDER_TYPE_USER_MAIL;
484
		}
485
		if ($class == "IPF.Task") {
486
			return SYNC_FOLDER_TYPE_USER_TASK;
487
		}
488
		if ($class == "IPF.Appointment") {
489
			return SYNC_FOLDER_TYPE_USER_APPOINTMENT;
490
		}
491
		if ($class == "IPF.Contact") {
492
			return SYNC_FOLDER_TYPE_USER_CONTACT;
493
		}
494
		if ($class == "IPF.StickyNote") {
495
			return SYNC_FOLDER_TYPE_USER_NOTE;
496
		}
497
		if ($class == "IPF.Journal") {
498
			return SYNC_FOLDER_TYPE_USER_JOURNAL;
499
		}
500
501
		return SYNC_FOLDER_TYPE_OTHER;
502
	}
503
504
	/**
505
	 * Calculates the native body type of a message using available properties. Refer to oxbbody.
506
	 *
507
	 * @param array $messageprops
508
	 *
509
	 * @return int
510
	 */
511
	public static function GetNativeBodyType($messageprops) {
512
		// check if the properties are set and get the error code if needed
513
		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...
514
			$messageprops[PR_BODY] = self::GetError(PR_BODY, $messageprops);
515
		}
516
		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...
517
			$messageprops[PR_RTF_COMPRESSED] = self::GetError(PR_RTF_COMPRESSED, $messageprops);
518
		}
519
		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...
520
			$messageprops[PR_HTML] = self::GetError(PR_HTML, $messageprops);
521
		}
522
		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...
523
			$messageprops[PR_RTF_IN_SYNC] = self::GetError(PR_RTF_IN_SYNC, $messageprops);
524
		}
525
526
		if ( // 1
527
			($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...
528
			($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_FOUND) &&
529
			($messageprops[PR_HTML] == MAPI_E_NOT_FOUND)) {
530
			return SYNC_BODYPREFERENCE_PLAIN;
531
		}
532
		if ( // 2
533
			($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...
534
			($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_FOUND) &&
535
			($messageprops[PR_HTML] == MAPI_E_NOT_FOUND)) {
536
			return SYNC_BODYPREFERENCE_PLAIN;
537
		}
538
		if ( // 3
539
			($messageprops[PR_BODY] == MAPI_E_NOT_ENOUGH_MEMORY) &&
540
			($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) &&
541
			($messageprops[PR_HTML] == MAPI_E_NOT_FOUND)) {
542
			return SYNC_BODYPREFERENCE_PLAIN;
543
		}
544
		if ( // 4
545
			($messageprops[PR_BODY] == MAPI_E_NOT_ENOUGH_MEMORY) &&
546
			($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) &&
547
			($messageprops[PR_HTML] == MAPI_E_NOT_ENOUGH_MEMORY) &&
548
			$messageprops[PR_RTF_IN_SYNC]) {
549
			return SYNC_BODYPREFERENCE_PLAIN;
550
		}
551
		if ( // 5
552
			($messageprops[PR_BODY] == MAPI_E_NOT_ENOUGH_MEMORY) &&
553
			($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) &&
554
			($messageprops[PR_HTML] == MAPI_E_NOT_ENOUGH_MEMORY) &&
555
			(!$messageprops[PR_RTF_IN_SYNC])) {
556
			return SYNC_BODYPREFERENCE_HTML;
557
		}
558
		if ( // 6
559
			($messageprops[PR_RTF_COMPRESSED] != MAPI_E_NOT_FOUND || $messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) &&
560
			($messageprops[PR_HTML] != MAPI_E_NOT_FOUND || $messageprops[PR_HTML] == MAPI_E_NOT_ENOUGH_MEMORY) &&
561
			$messageprops[PR_RTF_IN_SYNC]) {
562
			return SYNC_BODYPREFERENCE_PLAIN;
563
		}
564
		if ( // 7
565
			($messageprops[PR_RTF_COMPRESSED] != MAPI_E_NOT_FOUND || $messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) &&
566
			($messageprops[PR_HTML] != MAPI_E_NOT_FOUND || $messageprops[PR_HTML] == MAPI_E_NOT_ENOUGH_MEMORY) &&
567
			(!$messageprops[PR_RTF_IN_SYNC])) {
568
			return SYNC_BODYPREFERENCE_HTML;
569
		}
570
		if ( // 8
571
			($messageprops[PR_BODY] != MAPI_E_NOT_FOUND || $messageprops[PR_BODY] == MAPI_E_NOT_ENOUGH_MEMORY) &&
572
			($messageprops[PR_RTF_COMPRESSED] != MAPI_E_NOT_FOUND || $messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) &&
573
			$messageprops[PR_RTF_IN_SYNC]) {
574
			return SYNC_BODYPREFERENCE_PLAIN;
575
		}
576
		if ( // 9.1
577
			($messageprops[PR_BODY] != MAPI_E_NOT_FOUND || $messageprops[PR_BODY] == MAPI_E_NOT_ENOUGH_MEMORY) &&
578
			($messageprops[PR_RTF_COMPRESSED] != MAPI_E_NOT_FOUND || $messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) &&
579
			(!$messageprops[PR_RTF_IN_SYNC])) {
580
			return SYNC_BODYPREFERENCE_PLAIN;
581
		}
582
		if ( // 9.2
583
			($messageprops[PR_RTF_COMPRESSED] != MAPI_E_NOT_FOUND || $messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) &&
584
			($messageprops[PR_BODY] == MAPI_E_NOT_FOUND) &&
585
			($messageprops[PR_HTML] == MAPI_E_NOT_FOUND)) {
586
			return SYNC_BODYPREFERENCE_PLAIN;
587
		}
588
		if ( // 9.3
589
			($messageprops[PR_BODY] != MAPI_E_NOT_FOUND || $messageprops[PR_BODY] == MAPI_E_NOT_ENOUGH_MEMORY) &&
590
			($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_FOUND) &&
591
			($messageprops[PR_HTML] == MAPI_E_NOT_FOUND)) {
592
			return SYNC_BODYPREFERENCE_PLAIN;
593
		}
594
		if ( // 9.4
595
			($messageprops[PR_HTML] != MAPI_E_NOT_FOUND || $messageprops[PR_HTML] == MAPI_E_NOT_ENOUGH_MEMORY) &&
596
			($messageprops[PR_BODY] == MAPI_E_NOT_FOUND) &&
597
			($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_FOUND)) {
598
			return SYNC_BODYPREFERENCE_HTML;
599
		}
600
601
		// 10
602
		return SYNC_BODYPREFERENCE_PLAIN;
603
	}
604
605
	/**
606
	 * Returns the error code for a given property.
607
	 * Helper for MAPIUtils::GetNativeBodyType() function but also used in other places.
608
	 *
609
	 * @param int   $tag
610
	 * @param array $messageprops
611
	 *
612
	 * @return int (MAPI_ERROR_CODE)
613
	 */
614
	public static function GetError($tag, $messageprops) {
615
		$prBodyError = mapi_prop_tag(PT_ERROR, mapi_prop_id($tag));
0 ignored issues
show
Bug introduced by
The constant PT_ERROR was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
616
		if (isset($messageprops[$prBodyError]) && mapi_is_error($messageprops[$prBodyError])) {
617
			if ($messageprops[$prBodyError] == MAPI_E_NOT_ENOUGH_MEMORY_32BIT ||
618
					$messageprops[$prBodyError] == MAPI_E_NOT_ENOUGH_MEMORY_64BIT) {
619
				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...
620
			}
621
		}
622
623
		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...
624
	}
625
626
	/**
627
	 * Function will be used to decode smime messages and convert it to normal messages.
628
	 *
629
	 * @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...
630
	 * @param MAPIStore      $store
631
	 * @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...
632
	 * @param mixed          $mapimessage
633
	 */
634
	public static function ParseSmime($session, $store, $addressBook, &$mapimessage) {
635
		$props = mapi_getprops($mapimessage, [
636
			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...
637
			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...
638
			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...
639
			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...
640
			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...
641
			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...
642
			PR_SENT_REPRESENTING_EMAIL_ADDRESS,
0 ignored issues
show
Bug introduced by
The constant PR_SENT_REPRESENTING_EMAIL_ADDRESS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
643
			PR_SENT_REPRESENTING_SMTP_ADDRESS,
0 ignored issues
show
Bug introduced by
The constant PR_SENT_REPRESENTING_SMTP_ADDRESS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
644
			PR_SENT_REPRESENTING_ADDRTYPE,
0 ignored issues
show
Bug introduced by
The constant PR_SENT_REPRESENTING_ADDRTYPE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
645
			PR_CLIENT_SUBMIT_TIME,
0 ignored issues
show
Bug introduced by
The constant PR_CLIENT_SUBMIT_TIME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
646
			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...
647
		]);
648
		$read = $props[PR_MESSAGE_FLAGS] & MSGFLAG_READ;
0 ignored issues
show
Bug introduced by
The constant MSGFLAG_READ was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
649
650
		if (isset($props[PR_MESSAGE_CLASS]) && stripos((string) $props[PR_MESSAGE_CLASS], 'IPM.Note.SMIME.MultipartSigned') !== false) {
651
			// also copy recipients because they are lost after mapi_inetmapi_imtomapi
652
			$origRcptTable = mapi_message_getrecipienttable($mapimessage);
653
			$origRecipients = mapi_table_queryallrows($origRcptTable, [PR_ENTRYID, PR_SEARCH_KEY, PR_ROWID, PR_DISPLAY_NAME, PR_DISPLAY_TYPE, PR_DISPLAY_TYPE_EX, PR_ADDRTYPE, PR_EMAIL_ADDRESS, PR_SMTP_ADDRESS, PR_OBJECT_TYPE, PR_RECIPIENT_FLAGS, PR_RECIPIENT_TYPE, PR_RECIPIENT_TRACKSTATUS, PR_RECIPIENT_TRACKSTATUS_TIME, PR_RECIPIENT_PROPOSED, PR_RECIPIENT_PROPOSEDSTARTTIME, PR_RECIPIENT_PROPOSEDENDTIME, PR_CREATION_TIME]);
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...
Bug introduced by
The constant PR_ROWID was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant PR_SMTP_ADDRESS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant PR_RECIPIENT_PROPOSEDENDTIME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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...
Bug introduced by
The constant PR_RECIPIENT_FLAGS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant PR_RECIPIENT_TYPE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant PR_OBJECT_TYPE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant PR_CREATION_TIME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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...
Bug introduced by
The constant PR_DISPLAY_TYPE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant PR_RECIPIENT_TRACKSTATUS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant PR_SEARCH_KEY was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant PR_ADDRTYPE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant PR_RECIPIENT_PROPOSED was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant PR_RECIPIENT_PROPOSEDSTARTTIME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant PR_DISPLAY_NAME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
654
655
			// this is a signed message. decode it.
656
			$attachTable = mapi_message_getattachmenttable($mapimessage);
657
			$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...
658
			$attnum = false;
659
660
			foreach ($rows as $row) {
661
				if (isset($row[PR_ATTACH_MIME_TAG]) && $row[PR_ATTACH_MIME_TAG] == 'multipart/signed') {
662
					$attnum = $row[PR_ATTACH_NUM];
663
				}
664
			}
665
666
			if ($attnum !== false) {
667
				$att = mapi_message_openattach($mapimessage, $attnum);
668
				$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...
669
				mapi_message_deleteattach($mapimessage, $attnum);
670
				mapi_inetmapi_imtomapi($session, $store, $addressBook, $mapimessage, $data, ["parse_smime_signed" => 1]);
671
				SLog::Write(LOGLEVEL_DEBUG, "Convert a smime signed message to a normal message.");
672
			}
673
			$mprops = mapi_getprops($mapimessage, [PR_MESSAGE_FLAGS]);
674
			// Workaround for issue 13
675
			mapi_setprops($mapimessage, [
676
				PR_MESSAGE_CLASS => 'IPM.Note.SMIME.MultipartSigned',
677
				PR_SUBJECT => $props[PR_SUBJECT],
678
				PR_MESSAGE_DELIVERY_TIME => $props[PR_MESSAGE_DELIVERY_TIME],
679
				PR_SENT_REPRESENTING_NAME => $props[PR_SENT_REPRESENTING_NAME],
680
				PR_SENT_REPRESENTING_ENTRYID => $props[PR_SENT_REPRESENTING_ENTRYID],
681
				PR_SENT_REPRESENTING_SEARCH_KEY => $props[PR_SENT_REPRESENTING_SEARCH_KEY],
682
				PR_SENT_REPRESENTING_EMAIL_ADDRESS => $props[PR_SENT_REPRESENTING_EMAIL_ADDRESS] ?? '',
683
				PR_SENT_REPRESENTING_SMTP_ADDRESS => $props[PR_SENT_REPRESENTING_SMTP_ADDRESS] ?? '',
684
				PR_SENT_REPRESENTING_ADDRTYPE => $props[PR_SENT_REPRESENTING_ADDRTYPE] ?? 'SMTP',
685
				PR_CLIENT_SUBMIT_TIME => $props[PR_CLIENT_SUBMIT_TIME] ?? time(),
686
				// mark the message as read if the main message has read flag
687
				PR_MESSAGE_FLAGS => $read ? $mprops[PR_MESSAGE_FLAGS] | MSGFLAG_READ : $mprops[PR_MESSAGE_FLAGS],
688
			]);
689
			// readd recipients from original message
690
			$decapRcptTable = mapi_message_getrecipienttable($mapimessage);
691
			$decapRecipients = mapi_table_queryallrows($decapRcptTable, [PR_ENTRYID, PR_SEARCH_KEY, PR_ROWID, PR_DISPLAY_NAME]);
692
			if (empty($decapRecipients) && !empty($origRecipients)) {
693
				mapi_message_modifyrecipients($mapimessage, MODRECIP_ADD, $origRecipients);
0 ignored issues
show
Bug introduced by
The constant MODRECIP_ADD was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
694
			}
695
		}
696
		// TODO check if we need to do this for encrypted (and signed?) message as well
697
	}
698
}
699