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 |
|
|
|
|
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, |
|
|
|
|
25
|
|
|
[ |
26
|
|
|
RELOP => RELOP_GE, |
|
|
|
|
27
|
|
|
ULPROPTAG => PR_MESSAGE_DELIVERY_TIME, |
|
|
|
|
28
|
|
|
VALUE => $timestamp, |
|
|
|
|
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 |
|
|
|
|
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); |
|
|
|
|
50
|
|
|
|
51
|
|
|
// ATTENTION: ON CHANGING THIS RESTRICTION, MAPIUtils::IsInCalendarSyncInterval() also needs to be changed |
52
|
|
|
return [ |
53
|
|
|
RES_OR, |
|
|
|
|
54
|
|
|
[ |
55
|
|
|
// OR |
56
|
|
|
// item.end > window.start && item.start < window.end |
57
|
|
|
[ |
58
|
|
|
RES_AND, |
|
|
|
|
59
|
|
|
[ |
60
|
|
|
[ |
61
|
|
|
RES_PROPERTY, |
|
|
|
|
62
|
|
|
[ |
63
|
|
|
RELOP => RELOP_LE, |
|
|
|
|
64
|
|
|
ULPROPTAG => $props["starttime"], |
|
|
|
|
65
|
|
|
VALUE => $end, |
|
|
|
|
66
|
|
|
], |
67
|
|
|
], |
68
|
|
|
[ |
69
|
|
|
RES_PROPERTY, |
70
|
|
|
[ |
71
|
|
|
RELOP => RELOP_GE, |
|
|
|
|
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, |
|
|
|
|
89
|
|
|
[ULPROPTAG => $props["recurrenceend"], |
90
|
|
|
], |
91
|
|
|
], |
92
|
|
|
[ |
93
|
|
|
RES_PROPERTY, |
94
|
|
|
[ |
95
|
|
|
RELOP => RELOP_EQ, |
|
|
|
|
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, |
|
|
|
|
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, |
|
|
|
|
157
|
|
|
[ |
158
|
|
|
RELOP => RELOP_EQ, |
|
|
|
|
159
|
|
|
ULPROPTAG => mapi_prop_tag(PT_BOOLEAN, 0x7FFF), |
|
|
|
|
160
|
|
|
VALUE => true, |
|
|
|
|
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, |
|
|
|
|
175
|
|
|
[ |
176
|
|
|
[ |
177
|
|
|
RES_OR, |
|
|
|
|
178
|
|
|
[ |
179
|
|
|
[ |
180
|
|
|
RES_CONTENT, |
|
|
|
|
181
|
|
|
[ |
182
|
|
|
FUZZYLEVEL => FL_SUBSTRING | FL_IGNORECASE, |
|
|
|
|
183
|
|
|
ULPROPTAG => PR_DISPLAY_NAME, |
|
|
|
|
184
|
|
|
VALUE => $query, |
|
|
|
|
185
|
|
|
], |
186
|
|
|
], |
187
|
|
|
[ |
188
|
|
|
RES_CONTENT, |
189
|
|
|
[ |
190
|
|
|
FUZZYLEVEL => FL_SUBSTRING | FL_IGNORECASE, |
191
|
|
|
ULPROPTAG => PR_ACCOUNT, |
|
|
|
|
192
|
|
|
VALUE => $query, |
193
|
|
|
], |
194
|
|
|
], |
195
|
|
|
[ |
196
|
|
|
RES_CONTENT, |
197
|
|
|
[ |
198
|
|
|
FUZZYLEVEL => FL_SUBSTRING | FL_IGNORECASE, |
199
|
|
|
ULPROPTAG => PR_SMTP_ADDRESS, |
|
|
|
|
200
|
|
|
VALUE => $query, |
201
|
|
|
], |
202
|
|
|
], |
203
|
|
|
], // RES_OR |
204
|
|
|
], |
205
|
|
|
[ |
206
|
|
|
RES_OR, |
207
|
|
|
[ |
208
|
|
|
[ |
209
|
|
|
RES_PROPERTY, |
|
|
|
|
210
|
|
|
[ |
211
|
|
|
RELOP => RELOP_EQ, |
|
|
|
|
212
|
|
|
ULPROPTAG => PR_OBJECT_TYPE, |
|
|
|
|
213
|
|
|
VALUE => MAPI_MAILUSER, |
|
|
|
|
214
|
|
|
], |
215
|
|
|
], |
216
|
|
|
[ |
217
|
|
|
RES_PROPERTY, |
218
|
|
|
[ |
219
|
|
|
RELOP => RELOP_EQ, |
220
|
|
|
ULPROPTAG => PR_OBJECT_TYPE, |
221
|
|
|
VALUE => MAPI_DISTLIST, |
|
|
|
|
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); |
|
|
|
|
241
|
|
|
|
242
|
|
|
return [ |
243
|
|
|
RES_OR, |
|
|
|
|
244
|
|
|
[ |
245
|
|
|
[ |
246
|
|
|
RES_PROPERTY, |
|
|
|
|
247
|
|
|
[ |
248
|
|
|
RELOP => RELOP_EQ, |
|
|
|
|
249
|
|
|
ULPROPTAG => $props['emailaddress1'], |
|
|
|
|
250
|
|
|
VALUE => [$props['emailaddress1'] => $email], |
|
|
|
|
251
|
|
|
], |
252
|
|
|
], |
253
|
|
|
[ |
254
|
|
|
RES_PROPERTY, |
255
|
|
|
[ |
256
|
|
|
RELOP => RELOP_EQ, |
257
|
|
|
ULPROPTAG => $props['emailaddress2'], |
258
|
|
|
VALUE => [$props['emailaddress2'] => $email], |
259
|
|
|
], |
260
|
|
|
], |
261
|
|
|
[ |
262
|
|
|
RES_PROPERTY, |
263
|
|
|
[ |
264
|
|
|
RELOP => RELOP_EQ, |
265
|
|
|
ULPROPTAG => $props['emailaddress3'], |
266
|
|
|
VALUE => [$props['emailaddress3'] => $email], |
267
|
|
|
], |
268
|
|
|
], |
269
|
|
|
], |
270
|
|
|
]; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* Create a MAPI restriction for a certain folder type. |
275
|
|
|
* |
276
|
|
|
* @param string $foldertype folder type for restriction |
277
|
|
|
* |
278
|
|
|
* @return array |
279
|
|
|
*/ |
280
|
|
|
public static function GetFolderTypeRestriction($foldertype) { |
281
|
|
|
return [ |
282
|
|
|
RES_PROPERTY, |
|
|
|
|
283
|
|
|
[ |
284
|
|
|
RELOP => RELOP_EQ, |
|
|
|
|
285
|
|
|
ULPROPTAG => PR_CONTAINER_CLASS, |
|
|
|
|
286
|
|
|
VALUE => [PR_CONTAINER_CLASS => $foldertype], |
|
|
|
|
287
|
|
|
], |
288
|
|
|
]; |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* Returns subfolders of given type for a folder or false if there are none. |
293
|
|
|
* |
294
|
|
|
* @param MAPIFolder $folder |
|
|
|
|
295
|
|
|
* @param string $type |
296
|
|
|
* |
297
|
|
|
* @return bool|MAPITable |
|
|
|
|
298
|
|
|
*/ |
299
|
|
|
public static function GetSubfoldersForType($folder, $type) { |
300
|
|
|
$subfolders = mapi_folder_gethierarchytable($folder, CONVENIENT_DEPTH); |
|
|
|
|
301
|
|
|
mapi_table_restrict($subfolders, MAPIUtils::GetFolderTypeRestriction($type)); |
302
|
|
|
if (mapi_table_getrowcount($subfolders) > 0) { |
303
|
|
|
return mapi_table_queryallrows($subfolders, [PR_ENTRYID]); |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
return false; |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
/** |
310
|
|
|
* Checks if mapimessage is inside the synchronization interval |
311
|
|
|
* also defined by MAPIUtils::GetEmailRestriction(). |
312
|
|
|
* |
313
|
|
|
* @param MAPIStore $store mapi store |
314
|
|
|
* @param MAPIMessage $mapimessage the mapi message to be checked |
|
|
|
|
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]); |
|
|
|
|
321
|
|
|
|
322
|
|
|
if (isset($p[PR_MESSAGE_DELIVERY_TIME]) && $p[PR_MESSAGE_DELIVERY_TIME] >= $timestamp) { |
323
|
|
|
SLog::Write(LOGLEVEL_DEBUG, "MAPIUtils->IsInEmailSyncInterval: Message is in the synchronization interval"); |
324
|
|
|
|
325
|
|
|
return true; |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
SLog::Write(LOGLEVEL_WARN, "MAPIUtils->IsInEmailSyncInterval: Message is OUTSIDE the synchronization interval"); |
329
|
|
|
|
330
|
|
|
return false; |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
/** |
334
|
|
|
* Checks if mapimessage is inside the synchronization interval |
335
|
|
|
* also defined by MAPIUtils::GetCalendarRestriction(). |
336
|
|
|
* |
337
|
|
|
* @param MAPIStore $store mapi store |
338
|
|
|
* @param MAPIMessage $mapimessage the mapi message to be checked |
339
|
|
|
* @param long $timestamp the lower time limit |
340
|
|
|
* |
341
|
|
|
* @return bool |
342
|
|
|
*/ |
343
|
|
|
public static function IsInCalendarSyncInterval($store, $mapimessage, $timestamp) { |
344
|
|
|
// This is our viewing window |
345
|
|
|
$start = $timestamp; |
346
|
|
|
$end = 0x7FFFFFFF; // infinite end |
347
|
|
|
|
348
|
|
|
$props = MAPIMapping::GetAppointmentProperties(); |
349
|
|
|
$props = getPropIdsFromStrings($store, $props); |
|
|
|
|
350
|
|
|
|
351
|
|
|
$p = mapi_getprops($mapimessage, [$props["starttime"], $props["endtime"], $props["recurrenceend"], $props["isrecurring"], $props["recurrenceend"]]); |
352
|
|
|
|
353
|
|
|
if ( |
354
|
|
|
( |
355
|
|
|
isset($p[$props["endtime"]], $p[$props["starttime"]]) && |
356
|
|
|
// item.end > window.start && item.start < window.end |
357
|
|
|
$p[$props["endtime"]] > $start && $p[$props["starttime"]] < $end |
358
|
|
|
) || |
359
|
|
|
( |
360
|
|
|
isset($p[$props["isrecurring"]], $p[$props["recurrenceend"]]) && |
361
|
|
|
// (EXIST(recurrence_enddate_property) && item[isRecurring] == true && recurrence_enddate_property >= start) |
362
|
|
|
$p[$props["isrecurring"]] == true && $p[$props["recurrenceend"]] >= $start |
363
|
|
|
) || |
364
|
|
|
( |
365
|
|
|
isset($p[$props["isrecurring"]], $p[$props["starttime"]]) && |
366
|
|
|
// (!EXIST(recurrence_enddate_property) && item[isRecurring] == true && item[start] <= end) |
367
|
|
|
!isset($p[$props["recurrenceend"]]) && $p[$props["isrecurring"]] == true && $p[$props["starttime"]] <= $end |
368
|
|
|
) |
369
|
|
|
) { |
370
|
|
|
SLog::Write(LOGLEVEL_DEBUG, "MAPIUtils->IsInCalendarSyncInterval: Message is in the synchronization interval"); |
371
|
|
|
|
372
|
|
|
return true; |
373
|
|
|
} |
374
|
|
|
|
375
|
|
|
SLog::Write(LOGLEVEL_WARN, "MAPIUtils->IsInCalendarSyncInterval: Message is OUTSIDE the synchronization interval"); |
376
|
|
|
|
377
|
|
|
return false; |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
/** |
381
|
|
|
* Checks if mapimessage is in a shared folder and private. |
382
|
|
|
* |
383
|
|
|
* @param string $folderid binary folderid of the message |
384
|
|
|
* @param MAPIMessage $mapimessage the mapi message to be checked |
385
|
|
|
* |
386
|
|
|
* @return bool |
387
|
|
|
*/ |
388
|
|
|
public static function IsMessageSharedAndPrivate($folderid, $mapimessage) { |
389
|
|
|
$sensitivity = mapi_getprops($mapimessage, [PR_SENSITIVITY]); |
|
|
|
|
390
|
|
|
if (isset($sensitivity[PR_SENSITIVITY]) && $sensitivity[PR_SENSITIVITY] >= SENSITIVITY_PRIVATE) { |
|
|
|
|
391
|
|
|
$hexFolderid = bin2hex($folderid); |
392
|
|
|
$shortId = GSync::GetDeviceManager()->GetFolderIdForBackendId($hexFolderid); |
393
|
|
|
if (Utils::GetFolderOriginFromId($shortId) == DeviceManager::FLD_ORIGIN_IMPERSONATED) { |
394
|
|
|
SLog::Write(LOGLEVEL_DEBUG, sprintf("MAPIUtils->IsMessageSharedAndPrivate(): Message is in impersonated store '%s' and marked as private", GSync::GetBackend()->GetImpersonatedUser())); |
395
|
|
|
|
396
|
|
|
return true; |
397
|
|
|
} |
398
|
|
|
$sharedUser = GSync::GetAdditionalSyncFolderStore($hexFolderid); |
399
|
|
|
if (Utils::GetFolderOriginFromId($shortId) != DeviceManager::FLD_ORIGIN_USER && $sharedUser != false && $sharedUser != 'SYSTEM') { |
|
|
|
|
400
|
|
|
SLog::Write(LOGLEVEL_DEBUG, sprintf("MAPIUtils->IsMessageSharedAndPrivate(): Message is in shared store '%s' and marked as private", $sharedUser)); |
401
|
|
|
|
402
|
|
|
return true; |
403
|
|
|
} |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
return false; |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
/** |
410
|
|
|
* Reads data of large properties from a stream. |
411
|
|
|
* |
412
|
|
|
* @param MAPIMessage $message |
413
|
|
|
* @param long $prop |
414
|
|
|
* |
415
|
|
|
* @return string |
416
|
|
|
*/ |
417
|
|
|
public static function readPropStream($message, $prop) { |
418
|
|
|
$stream = mapi_openproperty($message, $prop, IID_IStream, 0, 0); |
|
|
|
|
419
|
|
|
$ret = mapi_last_hresult(); |
420
|
|
|
if ($ret == MAPI_E_NOT_FOUND) { |
|
|
|
|
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 = ""; |
|
|
|
|
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]); |
|
|
|
|
450
|
|
|
if (isset($supportmask[PR_STORE_SUPPORT_MASK]) && ($supportmask[PR_STORE_SUPPORT_MASK] & STORE_UNICODE_OK)) { |
|
|
|
|
451
|
|
|
SLog::Write(LOGLEVEL_DEBUG, "Store supports properties containing Unicode characters."); |
452
|
|
|
define('STORE_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; |
|
|
|
|
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])) { |
|
|
|
|
544
|
|
|
$messageprops[PR_BODY] = self::GetError(PR_BODY, $messageprops); |
545
|
|
|
} |
546
|
|
|
if (!isset($messageprops[PR_RTF_COMPRESSED])) { |
|
|
|
|
547
|
|
|
$messageprops[PR_RTF_COMPRESSED] = self::GetError(PR_RTF_COMPRESSED, $messageprops); |
548
|
|
|
} |
549
|
|
|
if (!isset($messageprops[PR_HTML])) { |
|
|
|
|
550
|
|
|
$messageprops[PR_HTML] = self::GetError(PR_HTML, $messageprops); |
551
|
|
|
} |
552
|
|
|
if (!isset($messageprops[PR_RTF_IN_SYNC])) { |
|
|
|
|
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) && |
|
|
|
|
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) && |
|
|
|
|
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)); |
|
|
|
|
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; |
|
|
|
|
650
|
|
|
} |
651
|
|
|
} |
652
|
|
|
|
653
|
|
|
return MAPI_E_NOT_FOUND; |
|
|
|
|
654
|
|
|
} |
655
|
|
|
|
656
|
|
|
/** |
657
|
|
|
* Function will be used to decode smime messages and convert it to normal messages. |
658
|
|
|
* |
659
|
|
|
* @param MAPISession $session |
|
|
|
|
660
|
|
|
* @param MAPIStore $store |
661
|
|
|
* @param MAPIAdressBook $addressBook |
|
|
|
|
662
|
|
|
* @param mixed $mapimessage |
663
|
|
|
*/ |
664
|
|
|
public static function ParseSmime($session, $store, $addressBook, &$mapimessage) { |
665
|
|
|
$props = mapi_getprops($mapimessage, [ |
666
|
|
|
PR_MESSAGE_CLASS, |
|
|
|
|
667
|
|
|
PR_SUBJECT, |
|
|
|
|
668
|
|
|
PR_MESSAGE_DELIVERY_TIME, |
|
|
|
|
669
|
|
|
PR_SENT_REPRESENTING_NAME, |
|
|
|
|
670
|
|
|
PR_SENT_REPRESENTING_ENTRYID, |
|
|
|
|
671
|
|
|
PR_SENT_REPRESENTING_SEARCH_KEY, |
|
|
|
|
672
|
|
|
PR_SENT_REPRESENTING_EMAIL_ADDRESS, |
|
|
|
|
673
|
|
|
PR_SENT_REPRESENTING_SMTP_ADDRESS, |
|
|
|
|
674
|
|
|
PR_SENT_REPRESENTING_ADDRTYPE, |
|
|
|
|
675
|
|
|
PR_CLIENT_SUBMIT_TIME, |
|
|
|
|
676
|
|
|
PR_MESSAGE_FLAGS, |
|
|
|
|
677
|
|
|
]); |
678
|
|
|
$read = $props[PR_MESSAGE_FLAGS] & MSGFLAG_READ; |
|
|
|
|
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]); |
|
|
|
|
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]); |
|
|
|
|
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); |
|
|
|
|
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); |
|
|
|
|
724
|
|
|
} |
725
|
|
|
} |
726
|
|
|
// TODO check if we need to do this for encrypted (and signed?) message as well |
727
|
|
|
} |
728
|
|
|
} |
729
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths