MAPIUtils::ParseSmime()   B
last analyzed

Complexity

Conditions 10
Paths 13

Size

Total Lines 60
Code Lines 45

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 2 Features 0
Metric Value
cc 10
eloc 45
c 5
b 2
f 0
nc 13
nop 4
dl 0
loc 60
rs 7.3333

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