Total Complexity | 152 |
Total Lines | 914 |
Duplicated Lines | 0 % |
Changes | 3 | ||
Bugs | 1 | Features | 0 |
Complex classes like MAPIUtils often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use MAPIUtils, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
11 | class MAPIUtils { |
||
12 | /** |
||
13 | * Create a MAPI restriction to use within an email folder which will |
||
14 | * return all messages since since $timestamp. |
||
15 | * |
||
16 | * @param long $timestamp Timestamp since when to include messages |
||
|
|||
17 | * |
||
18 | * @return array |
||
19 | */ |
||
20 | public static function GetEmailRestriction($timestamp) { |
||
21 | // ATTENTION: ON CHANGING THIS RESTRICTION, MAPIUtils::IsInEmailSyncInterval() also needs to be changed |
||
22 | return [ |
||
23 | RES_PROPERTY, |
||
24 | [ |
||
25 | RELOP => RELOP_GE, |
||
26 | ULPROPTAG => PR_MESSAGE_DELIVERY_TIME, |
||
27 | VALUE => $timestamp, |
||
28 | ], |
||
29 | ]; |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * Create a MAPI restriction to use in the calendar which will |
||
34 | * return all future calendar items, plus those since $timestamp. |
||
35 | * |
||
36 | * @param MAPIStore $store the MAPI store |
||
37 | * @param long $timestamp Timestamp since when to include messages |
||
38 | * |
||
39 | * @return array |
||
40 | */ |
||
41 | // TODO getting named properties |
||
42 | public static function GetCalendarRestriction($store, $timestamp) { |
||
43 | // This is our viewing window |
||
44 | $start = $timestamp; |
||
45 | $end = 0x7FFFFFFF; // infinite end |
||
46 | |||
47 | $props = MAPIMapping::GetAppointmentProperties(); |
||
48 | $props = getPropIdsFromStrings($store, $props); |
||
49 | |||
50 | // ATTENTION: ON CHANGING THIS RESTRICTION, MAPIUtils::IsInCalendarSyncInterval() also needs to be changed |
||
51 | return [ |
||
52 | RES_OR, |
||
53 | [ |
||
54 | // OR |
||
55 | // item.end > window.start && item.start < window.end |
||
56 | [ |
||
57 | RES_AND, |
||
58 | [ |
||
59 | [ |
||
60 | RES_PROPERTY, |
||
61 | [ |
||
62 | RELOP => RELOP_LE, |
||
63 | ULPROPTAG => $props["starttime"], |
||
64 | VALUE => $end, |
||
65 | ], |
||
66 | ], |
||
67 | [ |
||
68 | RES_PROPERTY, |
||
69 | [ |
||
70 | RELOP => RELOP_GE, |
||
71 | ULPROPTAG => $props["endtime"], |
||
72 | VALUE => $start, |
||
73 | ], |
||
74 | ], |
||
75 | ], |
||
76 | ], |
||
77 | // OR |
||
78 | [ |
||
79 | RES_OR, |
||
80 | [ |
||
81 | // OR |
||
82 | // (EXIST(recurrence_enddate_property) && item[isRecurring] == true && recurrence_enddate_property >= start) |
||
83 | [ |
||
84 | RES_AND, |
||
85 | [ |
||
86 | [ |
||
87 | RES_EXIST, |
||
88 | [ULPROPTAG => $props["recurrenceend"], |
||
89 | ], |
||
90 | ], |
||
91 | [ |
||
92 | RES_PROPERTY, |
||
93 | [ |
||
94 | RELOP => RELOP_EQ, |
||
95 | ULPROPTAG => $props["isrecurring"], |
||
96 | VALUE => true, |
||
97 | ], |
||
98 | ], |
||
99 | [ |
||
100 | RES_PROPERTY, |
||
101 | [ |
||
102 | RELOP => RELOP_GE, |
||
103 | ULPROPTAG => $props["recurrenceend"], |
||
104 | VALUE => $start, |
||
105 | ], |
||
106 | ], |
||
107 | ], |
||
108 | ], |
||
109 | // OR |
||
110 | // (!EXIST(recurrence_enddate_property) && item[isRecurring] == true && item[start] <= end) |
||
111 | [ |
||
112 | RES_AND, |
||
113 | [ |
||
114 | [ |
||
115 | RES_NOT, |
||
116 | [ |
||
117 | [ |
||
118 | RES_EXIST, |
||
119 | [ULPROPTAG => $props["recurrenceend"], |
||
120 | ], |
||
121 | ], |
||
122 | ], |
||
123 | ], |
||
124 | [ |
||
125 | RES_PROPERTY, |
||
126 | [ |
||
127 | RELOP => RELOP_LE, |
||
128 | ULPROPTAG => $props["starttime"], |
||
129 | VALUE => $end, |
||
130 | ], |
||
131 | ], |
||
132 | [ |
||
133 | RES_PROPERTY, |
||
134 | [ |
||
135 | RELOP => RELOP_EQ, |
||
136 | ULPROPTAG => $props["isrecurring"], |
||
137 | VALUE => true, |
||
138 | ], |
||
139 | ], |
||
140 | ], |
||
141 | ], |
||
142 | ], |
||
143 | ], // EXISTS OR |
||
144 | ], |
||
145 | ]; // global OR |
||
146 | } |
||
147 | |||
148 | /** |
||
149 | * Create a MAPI restriction in order to check if a contact has a picture. |
||
150 | * |
||
151 | * @return array |
||
152 | */ |
||
153 | public static function GetContactPicRestriction() { |
||
160 | ], |
||
161 | ]; |
||
162 | } |
||
163 | |||
164 | /** |
||
165 | * Create a MAPI restriction for search. |
||
166 | * |
||
167 | * @param string $query |
||
168 | * |
||
169 | * @return array |
||
170 | */ |
||
171 | public static function GetSearchRestriction($query) { |
||
172 | return [ |
||
173 | RES_AND, |
||
174 | [ |
||
175 | [ |
||
176 | RES_OR, |
||
177 | [ |
||
178 | [ |
||
179 | RES_CONTENT, |
||
180 | [ |
||
181 | FUZZYLEVEL => FL_SUBSTRING | FL_IGNORECASE, |
||
182 | ULPROPTAG => PR_DISPLAY_NAME, |
||
183 | VALUE => $query, |
||
184 | ], |
||
185 | ], |
||
186 | [ |
||
187 | RES_CONTENT, |
||
188 | [ |
||
189 | FUZZYLEVEL => FL_SUBSTRING | FL_IGNORECASE, |
||
190 | ULPROPTAG => PR_ACCOUNT, |
||
191 | VALUE => $query, |
||
192 | ], |
||
193 | ], |
||
194 | [ |
||
195 | RES_CONTENT, |
||
196 | [ |
||
197 | FUZZYLEVEL => FL_SUBSTRING | FL_IGNORECASE, |
||
198 | ULPROPTAG => PR_SMTP_ADDRESS, |
||
199 | VALUE => $query, |
||
200 | ], |
||
201 | ], |
||
202 | ], // RES_OR |
||
203 | ], |
||
204 | [ |
||
205 | RES_OR, |
||
206 | [ |
||
207 | [ |
||
208 | RES_PROPERTY, |
||
209 | [ |
||
210 | RELOP => RELOP_EQ, |
||
211 | ULPROPTAG => PR_OBJECT_TYPE, |
||
212 | VALUE => MAPI_MAILUSER, |
||
213 | ], |
||
214 | ], |
||
215 | [ |
||
216 | RES_PROPERTY, |
||
217 | [ |
||
218 | RELOP => RELOP_EQ, |
||
219 | ULPROPTAG => PR_OBJECT_TYPE, |
||
220 | VALUE => MAPI_DISTLIST, |
||
221 | ], |
||
222 | ], |
||
223 | ], |
||
224 | ], // RES_OR |
||
225 | ], // RES_AND |
||
226 | ]; |
||
227 | } |
||
228 | |||
229 | /** |
||
230 | * Create a MAPI restriction for a certain email address. |
||
231 | * |
||
232 | * @param MAPIStore $store the MAPI store |
||
233 | * @param string $query email address |
||
234 | * @param mixed $email |
||
235 | * |
||
236 | * @return array |
||
237 | */ |
||
238 | public static function GetEmailAddressRestriction($store, $email) { |
||
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) { |
||
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) { |
||
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_SUPPORTS_UNICODE', true); |
||
453 | define('STORE_INTERNET_CPID', INTERNET_CPID_UTF8); |
||
454 | } |
||
455 | } |
||
456 | |||
457 | /** |
||
458 | * Returns the MAPI PR_CONTAINER_CLASS string for an ActiveSync Foldertype. |
||
459 | * |
||
460 | * @param int $foldertype |
||
461 | * |
||
462 | * @return string |
||
463 | */ |
||
464 | public static function GetContainerClassFromFolderType($foldertype) { |
||
465 | switch ($foldertype) { |
||
466 | case SYNC_FOLDER_TYPE_TASK: |
||
467 | case SYNC_FOLDER_TYPE_USER_TASK: |
||
468 | return "IPF.Task"; |
||
469 | break; |
||
470 | |||
471 | case SYNC_FOLDER_TYPE_APPOINTMENT: |
||
472 | case SYNC_FOLDER_TYPE_USER_APPOINTMENT: |
||
473 | return "IPF.Appointment"; |
||
474 | break; |
||
475 | |||
476 | case SYNC_FOLDER_TYPE_CONTACT: |
||
477 | case SYNC_FOLDER_TYPE_USER_CONTACT: |
||
478 | return "IPF.Contact"; |
||
479 | break; |
||
480 | |||
481 | case SYNC_FOLDER_TYPE_NOTE: |
||
482 | case SYNC_FOLDER_TYPE_USER_NOTE: |
||
483 | return "IPF.StickyNote"; |
||
484 | break; |
||
485 | |||
486 | case SYNC_FOLDER_TYPE_JOURNAL: |
||
487 | case SYNC_FOLDER_TYPE_USER_JOURNAL: |
||
488 | return "IPF.Journal"; |
||
489 | break; |
||
490 | |||
491 | case SYNC_FOLDER_TYPE_INBOX: |
||
492 | case SYNC_FOLDER_TYPE_DRAFTS: |
||
493 | case SYNC_FOLDER_TYPE_WASTEBASKET: |
||
494 | case SYNC_FOLDER_TYPE_SENTMAIL: |
||
495 | case SYNC_FOLDER_TYPE_OUTBOX: |
||
496 | case SYNC_FOLDER_TYPE_USER_MAIL: |
||
497 | case SYNC_FOLDER_TYPE_OTHER: |
||
498 | case SYNC_FOLDER_TYPE_UNKNOWN: |
||
499 | default: |
||
500 | return "IPF.Note"; |
||
501 | break; |
||
502 | } |
||
503 | } |
||
504 | |||
505 | /** |
||
506 | * Returns the ActiveSync (USER) Foldertype from MAPI PR_CONTAINER_CLASS. |
||
507 | * |
||
508 | * @param string $foldertype |
||
509 | * @param mixed $class |
||
510 | * |
||
511 | * @return int |
||
512 | */ |
||
513 | public static function GetFolderTypeFromContainerClass($class) { |
||
514 | if ($class == "IPF.Note") { |
||
515 | return SYNC_FOLDER_TYPE_USER_MAIL; |
||
516 | } |
||
517 | if ($class == "IPF.Task") { |
||
518 | return SYNC_FOLDER_TYPE_USER_TASK; |
||
519 | } |
||
520 | if ($class == "IPF.Appointment") { |
||
521 | return SYNC_FOLDER_TYPE_USER_APPOINTMENT; |
||
522 | } |
||
523 | if ($class == "IPF.Contact") { |
||
524 | return SYNC_FOLDER_TYPE_USER_CONTACT; |
||
525 | } |
||
526 | if ($class == "IPF.StickyNote") { |
||
527 | return SYNC_FOLDER_TYPE_USER_NOTE; |
||
528 | } |
||
529 | if ($class == "IPF.Journal") { |
||
530 | return SYNC_FOLDER_TYPE_USER_JOURNAL; |
||
531 | } |
||
532 | |||
533 | return SYNC_FOLDER_TYPE_OTHER; |
||
534 | } |
||
535 | |||
536 | public static function GetSignedAttachmentRestriction() { |
||
537 | return [ |
||
538 | RES_PROPERTY, |
||
539 | [ |
||
540 | RELOP => RELOP_EQ, |
||
541 | ULPROPTAG => PR_ATTACH_MIME_TAG, |
||
542 | VALUE => [PR_ATTACH_MIME_TAG => 'multipart/signed'], |
||
543 | ], |
||
544 | ]; |
||
545 | } |
||
546 | |||
547 | /** |
||
548 | * Calculates the native body type of a message using available properties. Refer to oxbbody. |
||
549 | * |
||
550 | * @param array $messageprops |
||
551 | * |
||
552 | * @return int |
||
553 | */ |
||
554 | public static function GetNativeBodyType($messageprops) { |
||
555 | // check if the properties are set and get the error code if needed |
||
556 | if (!isset($messageprops[PR_BODY])) { |
||
557 | $messageprops[PR_BODY] = self::GetError(PR_BODY, $messageprops); |
||
558 | } |
||
559 | if (!isset($messageprops[PR_RTF_COMPRESSED])) { |
||
560 | $messageprops[PR_RTF_COMPRESSED] = self::GetError(PR_RTF_COMPRESSED, $messageprops); |
||
561 | } |
||
562 | if (!isset($messageprops[PR_HTML])) { |
||
563 | $messageprops[PR_HTML] = self::GetError(PR_HTML, $messageprops); |
||
564 | } |
||
565 | if (!isset($messageprops[PR_RTF_IN_SYNC])) { |
||
566 | $messageprops[PR_RTF_IN_SYNC] = self::GetError(PR_RTF_IN_SYNC, $messageprops); |
||
567 | } |
||
568 | |||
569 | if ( // 1 |
||
570 | ($messageprops[PR_BODY] == MAPI_E_NOT_FOUND) && |
||
571 | ($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_FOUND) && |
||
572 | ($messageprops[PR_HTML] == MAPI_E_NOT_FOUND)) { |
||
573 | return SYNC_BODYPREFERENCE_PLAIN; |
||
574 | } |
||
575 | if ( // 2 |
||
576 | ($messageprops[PR_BODY] == MAPI_E_NOT_ENOUGH_MEMORY) && |
||
577 | ($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_FOUND) && |
||
578 | ($messageprops[PR_HTML] == MAPI_E_NOT_FOUND)) { |
||
579 | return SYNC_BODYPREFERENCE_PLAIN; |
||
580 | } |
||
581 | if ( // 3 |
||
582 | ($messageprops[PR_BODY] == MAPI_E_NOT_ENOUGH_MEMORY) && |
||
583 | ($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) && |
||
584 | ($messageprops[PR_HTML] == MAPI_E_NOT_FOUND)) { |
||
585 | return SYNC_BODYPREFERENCE_RTF; |
||
586 | } |
||
587 | if ( // 4 |
||
588 | ($messageprops[PR_BODY] == MAPI_E_NOT_ENOUGH_MEMORY) && |
||
589 | ($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) && |
||
590 | ($messageprops[PR_HTML] == MAPI_E_NOT_ENOUGH_MEMORY) && |
||
591 | $messageprops[PR_RTF_IN_SYNC]) { |
||
592 | return SYNC_BODYPREFERENCE_RTF; |
||
593 | } |
||
594 | if ( // 5 |
||
595 | ($messageprops[PR_BODY] == MAPI_E_NOT_ENOUGH_MEMORY) && |
||
596 | ($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) && |
||
597 | ($messageprops[PR_HTML] == MAPI_E_NOT_ENOUGH_MEMORY) && |
||
598 | (!$messageprops[PR_RTF_IN_SYNC])) { |
||
599 | return SYNC_BODYPREFERENCE_HTML; |
||
600 | } |
||
601 | if ( // 6 |
||
602 | ($messageprops[PR_RTF_COMPRESSED] != MAPI_E_NOT_FOUND || $messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) && |
||
603 | ($messageprops[PR_HTML] != MAPI_E_NOT_FOUND || $messageprops[PR_HTML] == MAPI_E_NOT_ENOUGH_MEMORY) && |
||
604 | $messageprops[PR_RTF_IN_SYNC]) { |
||
605 | return SYNC_BODYPREFERENCE_RTF; |
||
606 | } |
||
607 | if ( // 7 |
||
608 | ($messageprops[PR_RTF_COMPRESSED] != MAPI_E_NOT_FOUND || $messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) && |
||
609 | ($messageprops[PR_HTML] != MAPI_E_NOT_FOUND || $messageprops[PR_HTML] == MAPI_E_NOT_ENOUGH_MEMORY) && |
||
610 | (!$messageprops[PR_RTF_IN_SYNC])) { |
||
611 | return SYNC_BODYPREFERENCE_HTML; |
||
612 | } |
||
613 | if ( // 8 |
||
614 | ($messageprops[PR_BODY] != MAPI_E_NOT_FOUND || $messageprops[PR_BODY] == MAPI_E_NOT_ENOUGH_MEMORY) && |
||
615 | ($messageprops[PR_RTF_COMPRESSED] != MAPI_E_NOT_FOUND || $messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) && |
||
616 | $messageprops[PR_RTF_IN_SYNC]) { |
||
617 | return SYNC_BODYPREFERENCE_RTF; |
||
618 | } |
||
619 | if ( // 9.1 |
||
620 | ($messageprops[PR_BODY] != MAPI_E_NOT_FOUND || $messageprops[PR_BODY] == MAPI_E_NOT_ENOUGH_MEMORY) && |
||
621 | ($messageprops[PR_RTF_COMPRESSED] != MAPI_E_NOT_FOUND || $messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) && |
||
622 | (!$messageprops[PR_RTF_IN_SYNC])) { |
||
623 | return SYNC_BODYPREFERENCE_PLAIN; |
||
624 | } |
||
625 | if ( // 9.2 |
||
626 | ($messageprops[PR_RTF_COMPRESSED] != MAPI_E_NOT_FOUND || $messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) && |
||
627 | ($messageprops[PR_BODY] == MAPI_E_NOT_FOUND) && |
||
628 | ($messageprops[PR_HTML] == MAPI_E_NOT_FOUND)) { |
||
629 | return SYNC_BODYPREFERENCE_RTF; |
||
630 | } |
||
631 | if ( // 9.3 |
||
632 | ($messageprops[PR_BODY] != MAPI_E_NOT_FOUND || $messageprops[PR_BODY] == MAPI_E_NOT_ENOUGH_MEMORY) && |
||
633 | ($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_FOUND) && |
||
634 | ($messageprops[PR_HTML] == MAPI_E_NOT_FOUND)) { |
||
635 | return SYNC_BODYPREFERENCE_PLAIN; |
||
636 | } |
||
637 | if ( // 9.4 |
||
638 | ($messageprops[PR_HTML] != MAPI_E_NOT_FOUND || $messageprops[PR_HTML] == MAPI_E_NOT_ENOUGH_MEMORY) && |
||
639 | ($messageprops[PR_BODY] == MAPI_E_NOT_FOUND) && |
||
640 | ($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_FOUND)) { |
||
641 | return SYNC_BODYPREFERENCE_HTML; |
||
642 | } |
||
643 | // 10 |
||
644 | return SYNC_BODYPREFERENCE_PLAIN; |
||
645 | } |
||
646 | |||
647 | /** |
||
648 | * Returns the error code for a given property. |
||
649 | * Helper for MAPIUtils::GetNativeBodyType() function but also used in other places. |
||
650 | * |
||
651 | * @param int $tag |
||
652 | * @param array $messageprops |
||
653 | * |
||
654 | * @return int (MAPI_ERROR_CODE) |
||
655 | */ |
||
656 | public static function GetError($tag, $messageprops) { |
||
657 | $prBodyError = mapi_prop_tag(PT_ERROR, mapi_prop_id($tag)); |
||
658 | if (isset($messageprops[$prBodyError]) && mapi_is_error($messageprops[$prBodyError])) { |
||
659 | if ($messageprops[$prBodyError] == MAPI_E_NOT_ENOUGH_MEMORY_32BIT || |
||
660 | $messageprops[$prBodyError] == MAPI_E_NOT_ENOUGH_MEMORY_64BIT) { |
||
661 | return MAPI_E_NOT_ENOUGH_MEMORY; |
||
662 | } |
||
663 | } |
||
664 | |||
665 | return MAPI_E_NOT_FOUND; |
||
666 | } |
||
667 | |||
668 | /** |
||
669 | * Function will be used to decode smime messages and convert it to normal messages. |
||
670 | * |
||
671 | * @param MAPISession $session |
||
672 | * @param MAPIStore $store |
||
673 | * @param MAPIAdressBook $addressBook |
||
674 | * @param MAPIMessage $message smime message |
||
675 | * @param mixed $mapimessage |
||
676 | */ |
||
677 | public static function ParseSmime($session, $store, $addressBook, &$mapimessage) { |
||
678 | $props = mapi_getprops($mapimessage, [ |
||
679 | PR_MESSAGE_CLASS, |
||
680 | PR_SUBJECT, |
||
681 | PR_MESSAGE_DELIVERY_TIME, |
||
682 | PR_SENT_REPRESENTING_NAME, |
||
683 | PR_SENT_REPRESENTING_ENTRYID, |
||
684 | PR_SENT_REPRESENTING_SEARCH_KEY, |
||
685 | PR_MESSAGE_FLAGS, |
||
686 | ]); |
||
687 | $read = $props[PR_MESSAGE_FLAGS] & MSGFLAG_READ; |
||
688 | |||
689 | if (isset($props[PR_MESSAGE_CLASS]) && stripos($props[PR_MESSAGE_CLASS], 'IPM.Note.SMIME.MultipartSigned') !== false) { |
||
690 | // this is a signed message. decode it. |
||
691 | $attachTable = mapi_message_getattachmenttable($mapimessage); |
||
692 | $rows = mapi_table_queryallrows($attachTable, [PR_ATTACH_MIME_TAG, PR_ATTACH_NUM]); |
||
693 | $attnum = false; |
||
694 | |||
695 | foreach ($rows as $row) { |
||
696 | if (isset($row[PR_ATTACH_MIME_TAG]) && $row[PR_ATTACH_MIME_TAG] == 'multipart/signed') { |
||
697 | $attnum = $row[PR_ATTACH_NUM]; |
||
698 | } |
||
699 | } |
||
700 | |||
701 | if ($attnum !== false) { |
||
702 | $att = mapi_message_openattach($mapimessage, $attnum); |
||
703 | $data = mapi_openproperty($att, PR_ATTACH_DATA_BIN); |
||
704 | mapi_message_deleteattach($mapimessage, $attnum); |
||
705 | // also copy recipients because they are lost after mapi_inetmapi_imtomapi |
||
706 | $recipienttable = mapi_message_getrecipienttable($mapimessage); |
||
707 | $messageRecipients = mapi_table_queryallrows($recipienttable, [ |
||
708 | PR_ENTRYID, |
||
709 | PR_SEARCH_KEY, |
||
710 | PR_ROWID, |
||
711 | PR_DISPLAY_NAME, |
||
712 | PR_DISPLAY_TYPE, |
||
713 | PR_DISPLAY_TYPE_EX, |
||
714 | PR_ADDRTYPE, |
||
715 | PR_EMAIL_ADDRESS, |
||
716 | PR_SMTP_ADDRESS, |
||
717 | PR_OBJECT_TYPE, |
||
718 | PR_RECIPIENT_FLAGS, |
||
719 | PR_RECIPIENT_TYPE, |
||
720 | PR_RECIPIENT_TRACKSTATUS, |
||
721 | PR_RECIPIENT_TRACKSTATUS_TIME, |
||
722 | PR_CREATION_TIME, |
||
723 | ]); |
||
724 | mapi_inetmapi_imtomapi($session, $store, $addressBook, $mapimessage, $data, ["parse_smime_signed" => 1]); |
||
725 | if (!empty($messageRecipients)) { |
||
726 | mapi_message_modifyrecipients($mapimessage, MODRECIP_ADD, $messageRecipients); |
||
727 | } |
||
728 | SLog::Write(LOGLEVEL_DEBUG, "Convert a smime signed message to a normal message."); |
||
729 | } |
||
730 | $mprops = mapi_getprops($mapimessage, [PR_MESSAGE_FLAGS]); |
||
731 | // Workaround for issue 13 |
||
732 | mapi_setprops($mapimessage, [ |
||
733 | PR_MESSAGE_CLASS => 'IPM.Note.SMIME.MultipartSigned', |
||
734 | PR_SUBJECT => $props[PR_SUBJECT], |
||
735 | PR_MESSAGE_DELIVERY_TIME => $props[PR_MESSAGE_DELIVERY_TIME], |
||
736 | PR_SENT_REPRESENTING_NAME => $props[PR_SENT_REPRESENTING_NAME], |
||
737 | PR_SENT_REPRESENTING_ENTRYID => $props[PR_SENT_REPRESENTING_ENTRYID], |
||
738 | PR_SENT_REPRESENTING_SEARCH_KEY => $props[PR_SENT_REPRESENTING_SEARCH_KEY], |
||
739 | // mark the message as read if the main message has read flag |
||
740 | PR_MESSAGE_FLAGS => $read ? $mprops[PR_MESSAGE_FLAGS] | MSGFLAG_READ : $mprops[PR_MESSAGE_FLAGS], |
||
741 | ]); |
||
742 | } |
||
743 | // TODO check if we need to do this for encrypted (and signed?) message as well |
||
744 | } |
||
745 | |||
746 | /** |
||
747 | * Compares two entryIds. It is possible to have two different entryIds that should match as they |
||
748 | * represent the same object (in multiserver environments). |
||
749 | * |
||
750 | * @param string $entryId1 |
||
751 | * @param string $entryId2 |
||
752 | * |
||
753 | * @return bool |
||
754 | */ |
||
755 | public static function CompareEntryIds($entryId1, $entryId2) { |
||
756 | if (!is_string($entryId1) || !is_string($entryId2)) { |
||
757 | return false; |
||
758 | } |
||
759 | |||
760 | if ($entryId1 === $entryId2) { |
||
761 | // if normal comparison succeeds then we can directly say that entryids are same |
||
762 | return true; |
||
763 | } |
||
764 | |||
765 | $eid1 = self::createEntryIdObj($entryId1); |
||
766 | $eid2 = self::createEntryIdObj($entryId2); |
||
767 | |||
768 | if ($eid1['length'] != $eid2['length'] || |
||
769 | $eid1['abFlags'] != $eid2['abFlags'] || |
||
770 | $eid1['version'] != $eid2['version'] || |
||
771 | $eid1['type'] != $eid2['type']) { |
||
772 | return false; |
||
773 | } |
||
774 | |||
775 | if ($eid1['name'] == 'EID_V0') { |
||
776 | if ($eid1['length'] < $eid1['min_length'] || $eid1['id'] != $eid2['id']) { |
||
777 | return false; |
||
778 | } |
||
779 | } |
||
780 | elseif ($eid1['length'] < $eid1['min_length'] || $eid1['uniqueId'] != $eid2['uniqueId']) { |
||
781 | return false; |
||
782 | } |
||
783 | |||
784 | return true; |
||
785 | } |
||
786 | |||
787 | /** |
||
788 | * Creates an object that has split up all the components of an entryID. |
||
789 | * |
||
790 | * @param string $entryid Entryid |
||
791 | * |
||
792 | * @return object EntryID object |
||
793 | */ |
||
794 | private static function createEntryIdObj($entryid) { |
||
797 | } |
||
798 | |||
799 | /** |
||
800 | * The entryid from the begin of zarafa till 5.20. |
||
801 | * |
||
802 | * @param string $entryid |
||
803 | * |
||
804 | * @return object EntryID object |
||
805 | */ |
||
806 | private static function getEID_V0Version($entryid) { |
||
848 | } |
||
849 | |||
850 | /** |
||
851 | * Entryid from version 6. |
||
852 | * |
||
853 | * @param string $entryid |
||
854 | * |
||
855 | * @return null[]|number[]|string[] |
||
856 | */ |
||
857 | private static function getEIDVersion($entryid) { |
||
858 | // always make entryids in uppercase so comparison will be case insensitive |
||
859 | $entryId = strtoupper($entryid); |
||
860 | |||
861 | $res = [ |
||
862 | 'abFlags' => '', // BYTE[4], 4 bytes, 8 hex characters |
||
863 | 'guid' => '', // GUID, 16 bytes, 32 hex characters |
||
864 | 'version' => '', // ULONG, 4 bytes, 8 hex characters |
||
865 | 'type' => '', // ULONG, 4 bytes, 8 hex characters |
||
866 | 'uniqueId' => '', // ULONG, 16 bytes, 32 hex characters |
||
867 | 'server' => '', // CHAR, variable length |
||
868 | 'padding' => '', // TCHAR[3], 4 bytes, 8 hex characters (upto 4 bytes) |
||
869 | ]; |
||
870 | |||
871 | $res['length'] = strlen($entryId); |
||
872 | $offset = 0; |
||
873 | |||
874 | // First determine padding, and remove if from the entryId |
||
875 | $res['padding'] = self::getPadding($entryId); |
||
876 | $entryId = substr($entryId, 0, strlen($entryId) - strlen($res['padding'])); |
||
877 | |||
878 | $res['abFlags'] = substr($entryId, $offset, 8); |
||
879 | $offset = +8; |
||
880 | |||
881 | $res['guid'] = substr($entryId, $offset, 32); |
||
882 | $offset += 32; |
||
883 | |||
884 | $res['version'] = substr($entryId, $offset, 8); |
||
885 | $offset += 8; |
||
886 | |||
887 | $res['type'] = substr($entryId, $offset, 8); |
||
888 | $offset += 8; |
||
889 | |||
890 | $res['uniqueId'] = substr($entryId, $offset, 32); |
||
891 | $offset += 32; |
||
892 | |||
893 | $res['server'] = substr($entryId, $offset); |
||
894 | |||
895 | $res['min_length'] = 88; |
||
896 | $res['name'] = 'EID'; |
||
897 | |||
898 | return $res; |
||
899 | } |
||
900 | |||
901 | /** |
||
902 | * Detect padding (max 3 bytes) from the entryId. |
||
903 | * |
||
904 | * @param string $entryId |
||
905 | * |
||
906 | * @return string |
||
907 | */ |
||
908 | private static function getPadding($entryId) { |
||
925 | } |
||
926 | } |
||
927 |
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