| Total Complexity | 182 |
| Total Lines | 987 |
| Duplicated Lines | 0 % |
| Changes | 6 | ||
| Bugs | 1 | Features | 0 |
Complex classes like ItemModule 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 ItemModule, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 8 | class ItemModule extends Module { |
||
| 9 | /** |
||
| 10 | * The setting whether Meeting Requests should be booked directly or not. |
||
| 11 | */ |
||
| 12 | public $directBookingMeetingRequest; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * The array of properties which should not be copied during the copy() action. |
||
| 16 | */ |
||
| 17 | public $skipCopyProperties; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Indicates that we are supporting only plain text body in the message props. |
||
| 21 | */ |
||
| 22 | public $plaintext; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Constructor. |
||
| 26 | * |
||
| 27 | * @param int $id unique id |
||
| 28 | * @param array $data list of all actions |
||
| 29 | */ |
||
| 30 | public function __construct($id, $data) { |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Executes all the actions in the $data variable. |
||
| 40 | */ |
||
| 41 | #[Override] |
||
| 294 | } |
||
| 295 | } |
||
| 296 | } |
||
| 297 | |||
| 298 | /** |
||
| 299 | * Function does customization of exception based on module data. |
||
| 300 | * like, here it will generate display message based on actionType |
||
| 301 | * for particular exception. |
||
| 302 | * |
||
| 303 | * @param object $e Exception object |
||
| 304 | * @param string $actionType the action type, sent by the client |
||
| 305 | * @param MAPIobject $store store object of message |
||
| 306 | * @param string $parententryid parent entryid of the message |
||
| 307 | * @param string $entryid entryid of the message |
||
| 308 | * @param array $action the action data, sent by the client |
||
| 309 | */ |
||
| 310 | #[Override] |
||
| 311 | public function handleException(&$e, $actionType = null, $store = null, $parententryid = null, $entryid = null, $action = null) { |
||
| 312 | if (is_null($e->displayMessage)) { |
||
| 313 | switch ($actionType) { |
||
| 314 | case "open": |
||
| 315 | if ($e->getCode() == MAPI_E_NO_ACCESS) { |
||
| 316 | $e->setDisplayMessage(_("You have insufficient privileges to open this message.")); |
||
| 317 | } |
||
| 318 | elseif ($e->getCode() == MAPI_E_NOT_FOUND) { |
||
| 319 | $e->setDisplayMessage(_("Could not find message, either it has been moved or deleted or you don't have access to open this message.")); |
||
| 320 | // Show error in console instead of a pop-up |
||
| 321 | if (isset($action["message_action"]['suppress_exception']) && $action["message_action"]['suppress_exception'] === true) { |
||
| 322 | $e->setNotificationType('console'); |
||
| 323 | } |
||
| 324 | } |
||
| 325 | else { |
||
| 326 | $e->setDisplayMessage(_("Could not open message.")); |
||
| 327 | $e->allowToShowDetailsMessage = true; |
||
| 328 | } |
||
| 329 | break; |
||
| 330 | |||
| 331 | case "save": |
||
| 332 | if ($e->getCode() == MAPI_E_NO_ACCESS) { |
||
| 333 | if (!empty($action["message_action"]["action_type"])) { |
||
| 334 | switch ($action["message_action"]["action_type"]) { |
||
| 335 | case "declineMeetingRequest": |
||
| 336 | $e->setDisplayMessage(_("You have insufficient privileges to decline this Meeting Request") . "."); |
||
| 337 | break; |
||
| 338 | |||
| 339 | case "acceptMeetingRequest": |
||
| 340 | $e->setDisplayMessage(_("You have insufficient privileges to accept this Meeting Request") . "."); |
||
| 341 | break; |
||
| 342 | |||
| 343 | case "copy": |
||
| 344 | $e->setDisplayMessage(_("Could not copy message") . "."); |
||
| 345 | break; |
||
| 346 | |||
| 347 | case "move": |
||
| 348 | $e->setDisplayMessage(_("Could not move message") . "."); |
||
| 349 | break; |
||
| 350 | } |
||
| 351 | } |
||
| 352 | |||
| 353 | if (empty($e->displayMessage)) { |
||
| 354 | $e->setDisplayMessage(_("You have insufficient privileges to save items in this folder") . "."); |
||
| 355 | } |
||
| 356 | } |
||
| 357 | elseif ($e->getCode() == MAPI_E_STORE_FULL) { |
||
| 358 | $e->setDisplayMessage($this->getOverQuotaMessage($store)); |
||
| 359 | } |
||
| 360 | else { |
||
| 361 | $e->setDisplayMessage(_("Could not save message") . "."); |
||
| 362 | $e->allowToShowDetailsMessage = true; |
||
| 363 | } |
||
| 364 | break; |
||
| 365 | |||
| 366 | case 'delete': |
||
| 367 | switch ($e->getCode()) { |
||
| 368 | case MAPI_E_NO_ACCESS: |
||
| 369 | if (!empty($action['message_action']['action_type'])) { |
||
| 370 | switch ($action['message_action']['action_type']) { |
||
| 371 | case 'removeFromCalendar': |
||
| 372 | $e->setDisplayMessage(_('You have insufficient privileges to remove item from the calendar.')); |
||
| 373 | break; |
||
| 374 | } |
||
| 375 | } |
||
| 376 | break; |
||
| 377 | |||
| 378 | case MAPI_E_NOT_IN_QUEUE: |
||
| 379 | $e->setDisplayMessage(_('Message is no longer in the outgoing queue, typically because it has already been sent.')); |
||
| 380 | break; |
||
| 381 | |||
| 382 | case MAPI_E_UNABLE_TO_ABORT: |
||
| 383 | $e->setDisplayMessage(_('Message cannot be aborted')); |
||
| 384 | break; |
||
| 385 | } |
||
| 386 | if (empty($e->displayMessage)) { |
||
| 387 | $e->setDisplayMessage(_("You have insufficient privileges to delete items in this folder") . "."); |
||
| 388 | } |
||
| 389 | break; |
||
| 390 | |||
| 391 | case "attach_items": |
||
| 392 | if ($e->getCode() == MAPI_E_NO_ACCESS) { |
||
| 393 | $e->setDisplayMessage(_("You have insufficient privileges to attach item as an attachment.")); |
||
| 394 | } |
||
| 395 | else { |
||
| 396 | $e->setDisplayMessage(_("Could not attach item as an attachment.")); |
||
| 397 | } |
||
| 398 | break; |
||
| 399 | |||
| 400 | case "reclaimownership": |
||
| 401 | if ($e->getCode() == MAPI_E_NO_ACCESS) { |
||
| 402 | $e->setDisplayMessage(_("You have insufficient privileges to reclaim the ownership for the Task Request.")); |
||
| 403 | } |
||
| 404 | else { |
||
| 405 | $e->setDisplayMessage(_("Could not reclaim the ownership for the Task Request.")); |
||
| 406 | } |
||
| 407 | break; |
||
| 408 | |||
| 409 | case "acceptTaskRequest": |
||
| 410 | if ($e->getCode() == MAPI_E_NO_ACCESS) { |
||
| 411 | $e->setDisplayMessage(_("You have insufficient privileges to accept this Task Request.")); |
||
| 412 | } |
||
| 413 | else { |
||
| 414 | $e->setDisplayMessage(_("Could not accept Task Request.")); |
||
| 415 | } |
||
| 416 | break; |
||
| 417 | |||
| 418 | case "declineTaskRequest": |
||
| 419 | if ($e->getCode() == MAPI_E_NO_ACCESS) { |
||
| 420 | $e->setDisplayMessage(_("You have insufficient privileges to decline this Task Request.")); |
||
| 421 | } |
||
| 422 | else { |
||
| 423 | $e->setDisplayMessage(_("Could not decline Task Request.")); |
||
| 424 | } |
||
| 425 | break; |
||
| 426 | } |
||
| 427 | Log::Write( |
||
| 428 | LOGLEVEL_ERROR, |
||
| 429 | "itemmodule::handleException():" . $actionType . ": " . $e->displayMessage |
||
| 430 | ); |
||
| 431 | } |
||
| 432 | |||
| 433 | parent::handleException($e, $actionType, $store, $parententryid, $entryid, $action); |
||
| 434 | } |
||
| 435 | |||
| 436 | /** |
||
| 437 | * Function which opens an item. |
||
| 438 | * |
||
| 439 | * @param object $store MAPI Message Store Object |
||
| 440 | * @param string $entryid entryid of the message |
||
| 441 | * @param array $action the action data, sent by the client |
||
| 442 | */ |
||
| 443 | public function open($store, $entryid, $action) { |
||
| 444 | $data = []; |
||
| 445 | |||
| 446 | if ($entryid) { |
||
| 447 | if ($store) { |
||
| 448 | $message = $GLOBALS['operations']->openMessage($store, $entryid); |
||
| 449 | } |
||
| 450 | else { |
||
| 451 | // store is not passed so we need to open the message first to get the store resource |
||
| 452 | $message = $GLOBALS['mapisession']->openMessage($entryid); |
||
| 453 | |||
| 454 | $messageStoreInfo = mapi_getprops($message, [PR_STORE_ENTRYID]); |
||
| 455 | $store = $GLOBALS['mapisession']->openMessageStore($messageStoreInfo[PR_STORE_ENTRYID]); |
||
| 456 | } |
||
| 457 | } |
||
| 458 | |||
| 459 | if (empty($message)) { |
||
| 460 | return; |
||
| 461 | } |
||
| 462 | |||
| 463 | // Detect whether S/MIME decoding or meeting request processing is required |
||
| 464 | $props = mapi_getprops($message, [PR_MESSAGE_CLASS]); |
||
| 465 | $messageClass = $props[PR_MESSAGE_CLASS] ?? ''; |
||
| 466 | $requiresSmime = stripos((string) $messageClass, 'SMIME') !== false; /* infix match(!), cannot use class_match_prefix */ |
||
| 467 | $requiresMeeting = class_match_prefix($messageClass, "IPM.Schedule.Meeting"); |
||
| 468 | |||
| 469 | // Decode S/MIME signed messages only when needed |
||
| 470 | if ($requiresSmime) { |
||
| 471 | parse_smime($store, $message); |
||
| 472 | } |
||
| 473 | |||
| 474 | // Open embedded message if requested |
||
| 475 | $attachNum = !empty($action['attach_num']) ? $action['attach_num'] : false; |
||
| 476 | |||
| 477 | if ($attachNum) { |
||
| 478 | // get message props of sub message |
||
| 479 | $parentMessage = $message; |
||
| 480 | $message = $GLOBALS['operations']->openMessage($store, $entryid, $attachNum, true); |
||
| 481 | |||
| 482 | if (empty($message)) { |
||
| 483 | return; |
||
| 484 | } |
||
| 485 | |||
| 486 | $data['item'] = $GLOBALS['operations']->getEmbeddedMessageProps($store, $message, $this->properties, $parentMessage, $attachNum); |
||
| 487 | } |
||
| 488 | else { |
||
| 489 | // get message props of the message |
||
| 490 | $data['item'] = $GLOBALS['operations']->getMessageProps($store, $message, $this->properties, $this->plaintext, true); |
||
| 491 | $messageClass = $data['item']['props']['message_class'] ?? $messageClass; |
||
| 492 | |||
| 493 | // Determine again if meeting processing is required after parsing |
||
| 494 | if (!$requiresMeeting) { |
||
| 495 | $requiresMeeting = class_match_prefix($messageClass, "IPM.Schedule.Meeting"); |
||
| 496 | } |
||
| 497 | |||
| 498 | // Check for meeting request, do processing if necessary |
||
| 499 | if ($requiresMeeting) { |
||
| 500 | $req = new Meetingrequest($store, $message, $GLOBALS['mapisession']->getSession(), $this->directBookingMeetingRequest); |
||
| 501 | |||
| 502 | try { |
||
| 503 | if ($req->isMeetingRequestResponse($messageClass)) { |
||
| 504 | if ($req->isLocalOrganiser()) { |
||
| 505 | // We received a meeting request response, and we're the delegate/organiser |
||
| 506 | $req->processMeetingRequestResponse(); |
||
| 507 | } |
||
| 508 | } |
||
| 509 | elseif ($req->isMeetingRequest($messageClass)) { |
||
| 510 | if (!$req->isLocalOrganiser()) { |
||
| 511 | if ($req->isMeetingOutOfDate()) { |
||
| 512 | // we know that meeting is out of date so directly set this properties |
||
| 513 | $data['item']['props']['meetingtype'] = mtgOutOfDate; |
||
| 514 | $data['item']['props']['icon_index'] = 1033; |
||
| 515 | |||
| 516 | // send update to maillistmodule that meeting request is updated with out of date flag |
||
| 517 | $messageProps = mapi_getprops($message, [PR_ENTRYID, PR_PARENT_ENTRYID, PR_STORE_ENTRYID]); |
||
| 518 | $GLOBALS['bus']->notify(bin2hex((string) $messageProps[PR_PARENT_ENTRYID]), TABLE_SAVE, $messageProps); |
||
| 519 | } |
||
| 520 | else { |
||
| 521 | /* |
||
| 522 | * if meeting request is not out of date then process it for the first time |
||
| 523 | * which will create corresponding appointment in the user's calendar |
||
| 524 | */ |
||
| 525 | $calItemEntryid = $req->doAccept(true, false, false); |
||
| 526 | // we need to set timezone information for all-day events |
||
| 527 | if (isset($data['item']['props']['alldayevent']) && |
||
| 528 | $data['item']['props']['alldayevent'] == true && |
||
| 529 | !empty($action["timezone_iana"]) && |
||
| 530 | is_string($calItemEntryid)) { |
||
| 531 | try { |
||
| 532 | $tzdef = mapi_ianatz_to_tzdef($action['timezone_iana']); |
||
| 533 | $tzdefObj = $GLOBALS['entryid']->createTimezoneDefinitionObject($tzdef); |
||
| 534 | $tzEffRuleIdx = getEffectiveTzreg($tzdefObj['rules']); |
||
| 535 | if (!is_null($tzEffRuleIdx)) { |
||
| 536 | $localStart = $data['item']['props']['appointment_startdate'] + $tzdefObj['rules'][$tzEffRuleIdx]['bias'] * 60; |
||
| 537 | if (isDst($tzdefObj['rules'][$tzEffRuleIdx], $data['item']['props']['appointment_startdate'])) { |
||
| 538 | $localStart += $tzdefObj['rules'][$tzEffRuleIdx]['dstbias'] * 60; |
||
| 539 | } |
||
| 540 | $duration = $data['item']['props']['appointment_duedate'] - $data['item']['props']['appointment_startdate']; |
||
| 541 | |||
| 542 | $calItem = $GLOBALS['mapisession']->openMessage($calItemEntryid); |
||
| 543 | mapi_setprops($calItem, [ |
||
| 544 | $this->properties['appointment_startdate'] => $localStart, |
||
| 545 | $this->properties['appointment_duedate'] => $localStart + $duration, |
||
| 546 | $this->properties['tzdefstart'] => $tzdef, |
||
| 547 | $this->properties['tzdefend'] => $tzdef, |
||
| 548 | ]); |
||
| 549 | mapi_savechanges($calItem); |
||
| 550 | $data['item']['props']['appointment_startdate'] = $localStart; |
||
| 551 | $data['item']['props']['appointment_duedate'] = $localStart + $duration; |
||
| 552 | } |
||
| 553 | } |
||
| 554 | catch (Exception $e) { |
||
| 555 | error_log(sprintf("Error setting timezone to an all-day event: %s", $e)); |
||
| 556 | } |
||
| 557 | } |
||
| 558 | } |
||
| 559 | |||
| 560 | // Show user whether meeting request conflict with other appointment or not. |
||
| 561 | $meetingConflicts = $req->isMeetingConflicting(); |
||
| 562 | |||
| 563 | /** |
||
| 564 | * if $meetingConflicts is boolean and true then its a normal meeting. |
||
| 565 | * if $meetingConflicts is integer then it indicates no of instances of a recurring meeting which conflicts with Calendar. |
||
| 566 | */ |
||
| 567 | if ($meetingConflicts !== false) { |
||
| 568 | if ($meetingConflicts === true) { |
||
| 569 | $data['item']['props']['conflictinfo'] = _('Conflicts with another appointment.'); |
||
| 570 | } |
||
| 571 | else { |
||
| 572 | $data['item']['props']['conflictinfo'] = sprintf(ngettext('%s occurrence of this recurring appointment conflicts with other appointment.', '%s occurrences of this recurring appointment conflicts with other appointments.', $meetingConflicts), $meetingConflicts); |
||
| 573 | } |
||
| 574 | } |
||
| 575 | } |
||
| 576 | } |
||
| 577 | elseif ($req->isMeetingCancellation()) { |
||
| 578 | $req->processMeetingCancellation(); |
||
| 579 | } |
||
| 580 | |||
| 581 | if ($req->isInCalendar()) { |
||
| 582 | $calendarItemProps = $this->getCalendarItemProps($req); |
||
| 583 | if (!empty($calendarItemProps)) { |
||
| 584 | $data['item']['props'] = array_merge($data['item']['props'], $calendarItemProps); |
||
| 585 | } |
||
| 586 | } |
||
| 587 | else { |
||
| 588 | $data['item']['props']['appointment_not_found'] = true; |
||
| 589 | } |
||
| 590 | } |
||
| 591 | catch (MAPIException $e) { |
||
| 592 | // if quota is exceeded or or we don't have permission to write in calendar folder than ignore the exception. |
||
| 593 | if ($e->getCode() !== MAPI_E_STORE_FULL && $e->getCode() !== MAPI_E_NO_ACCESS) { |
||
| 594 | // re-throw the exception if it is not one of quota/calendar permission. |
||
| 595 | throw $e; |
||
| 596 | } |
||
| 597 | } |
||
| 598 | if (!empty($data['item']['props']['appointment_recurring']) && |
||
| 599 | empty($data['item']['props']['appointment_recurring_pattern'])) { |
||
| 600 | $recurr = new Recurrence($store, $message); |
||
| 601 | $data['item']['props']['appointment_recurring_pattern'] = $recurr->saveRecurrencePattern(); |
||
| 602 | } |
||
| 603 | } |
||
| 604 | elseif (class_match_prefix($messageClass, "REPORT.IPM.NOTE.NDR")) { |
||
| 605 | // check if this message is a NDR (mail)message, if so, generate a new body message |
||
| 606 | $data['item']['props']['isHTML'] = false; |
||
| 607 | $data['item']['props']['body'] = $this->getNDRbody($message); |
||
| 608 | } |
||
| 609 | } |
||
| 610 | |||
| 611 | $userEntryId = ''; |
||
| 612 | if (isset($data['item']['props']['sent_representing_entryid'])) { |
||
| 613 | $userEntryId = hex2bin($data['item']['props']['sent_representing_entryid']); |
||
| 614 | } |
||
| 615 | elseif (isset($data['item']['props']['sender_entryid'])) { |
||
| 616 | $userEntryId = hex2bin($data['item']['props']['sender_entryid']); |
||
| 617 | } |
||
| 618 | |||
| 619 | // get user image saved in LDAP. |
||
| 620 | if (!empty($userEntryId)) { |
||
| 621 | $data['item']['props']['user_image'] = $GLOBALS['operations']->getCompressedUserImage($userEntryId); |
||
| 622 | } |
||
| 623 | |||
| 624 | // Allowing to hook in just before the data sent away to be sent to the client |
||
| 625 | $GLOBALS['PluginManager']->triggerHook('server.module.itemmodule.open.after', [ |
||
| 626 | 'moduleObject' => &$this, |
||
| 627 | 'store' => $store, |
||
| 628 | 'entryid' => $entryid, |
||
| 629 | 'action' => $action, |
||
| 630 | 'message' => &$message, |
||
| 631 | 'data' => &$data, |
||
| 632 | ]); |
||
| 633 | |||
| 634 | // ugly workaround to show clip icon for the signed/encrypted emails |
||
| 635 | if (isset($data['item']['props']['smime'])) { |
||
| 636 | $data['item']['props']['hasattach'] = true; |
||
| 637 | unset($data['item']['props']['hide_attachments']); |
||
| 638 | } |
||
| 639 | |||
| 640 | $this->addActionData('item', $data); |
||
| 641 | $GLOBALS['bus']->addData($this->getResponseData()); |
||
| 642 | } |
||
| 643 | |||
| 644 | /** |
||
| 645 | * Function which saves an item. |
||
| 646 | * |
||
| 647 | * @param object $store MAPI Message Store Object |
||
| 648 | * @param string $parententryid parent entryid of the message |
||
| 649 | * @param mixed $entryid entryid of the message |
||
| 650 | * @param array $action the action data, sent by the client |
||
| 651 | * @param string $actionType The action type which triggered this action |
||
| 652 | */ |
||
| 653 | public function save($store, $parententryid, $entryid, $action, $actionType = 'save') { |
||
| 654 | $result = false; |
||
| 655 | |||
| 656 | if (isset($action["props"])) { |
||
| 657 | if (!$store) { |
||
| 658 | $store = $GLOBALS['mapisession']->getDefaultMessageStore(); |
||
| 659 | } |
||
| 660 | if (!$parententryid) { |
||
| 661 | if (isset($action['props']['message_class'])) { |
||
| 662 | $parententryid = $this->getDefaultFolderEntryID($store, $action['props']['message_class']); |
||
| 663 | } |
||
| 664 | else { |
||
| 665 | $parententryid = $this->getDefaultFolderEntryID($store, ''); |
||
| 666 | } |
||
| 667 | } |
||
| 668 | |||
| 669 | if ($store && $parententryid) { |
||
| 670 | $props = Conversion::mapXML2MAPI($this->properties, $action["props"]); |
||
| 671 | |||
| 672 | $messageProps = []; // props returned from saveMessage |
||
| 673 | |||
| 674 | // Save message |
||
| 675 | if (!empty($props)) { |
||
| 676 | $result = $GLOBALS["operations"]->saveMessage($store, $entryid, $parententryid, $props, $messageProps, [], !empty($action['attachments']) ? $action['attachments'] : []); |
||
| 677 | } |
||
| 678 | |||
| 679 | if ($result) { |
||
| 680 | $GLOBALS["bus"]->notify(bin2hex($parententryid), TABLE_SAVE, $messageProps); |
||
| 681 | |||
| 682 | $this->addActionData("update", ["item" => Conversion::mapMAPI2XML($this->properties, $messageProps)]); |
||
| 683 | $GLOBALS["bus"]->addData($this->getResponseData()); |
||
| 684 | } |
||
| 685 | else { |
||
| 686 | $this->sendFeedback(false); |
||
| 687 | } |
||
| 688 | } |
||
| 689 | } |
||
| 690 | } |
||
| 691 | |||
| 692 | /** |
||
| 693 | * Function which deletes an item. |
||
| 694 | * |
||
| 695 | * @param object $store MAPI Message Store Object |
||
| 696 | * @param string $parententryid parent entryid of the message |
||
| 697 | * @param string $entryid entryid of the message |
||
| 698 | * @param array $action the action data, sent by the client |
||
| 699 | */ |
||
| 700 | public function delete($store, $parententryid, $entryid, $action) { |
||
| 701 | if (!$store || !$parententryid || !$entryid) { |
||
| 702 | return; |
||
| 703 | } |
||
| 704 | $props = []; |
||
| 705 | $props[PR_PARENT_ENTRYID] = $parententryid; |
||
| 706 | $props[PR_ENTRYID] = $entryid; |
||
| 707 | |||
| 708 | $storeprops = mapi_getprops($store, [PR_ENTRYID]); |
||
| 709 | $props[PR_STORE_ENTRYID] = $storeprops[PR_ENTRYID]; |
||
| 710 | |||
| 711 | $soft = $action['message_action']['soft_delete'] ?? false; |
||
| 712 | $unread = $action['message_action']['non_read_notify'] ?? false; |
||
| 713 | $result = $GLOBALS["operations"]->deleteMessages($store, $parententryid, $entryid, $soft, $unread); |
||
| 714 | if ($result) { |
||
| 715 | $GLOBALS["bus"]->notify(bin2hex($parententryid), TABLE_DELETE, $props); |
||
| 716 | $this->sendFeedback(true); |
||
| 717 | } |
||
| 718 | } |
||
| 719 | |||
| 720 | /** |
||
| 721 | * Function which returns the entryid of a default folder. |
||
| 722 | * |
||
| 723 | * @param object $store MAPI Message Store Object |
||
| 724 | * @param string $messageClass the class of the folder |
||
| 725 | * |
||
| 726 | * @return string entryid of a default folder, false if not found |
||
| 727 | */ |
||
| 728 | public function getDefaultFolderEntryID($store, $messageClass) { |
||
| 729 | $entryid = false; |
||
| 730 | |||
| 731 | if ($store) { |
||
| 732 | $rootcontainer = mapi_msgstore_openentry($store); |
||
| 733 | $rootcontainerprops = mapi_getprops($rootcontainer, [PR_IPM_DRAFTS_ENTRYID, PR_IPM_APPOINTMENT_ENTRYID, PR_IPM_CONTACT_ENTRYID, PR_IPM_JOURNAL_ENTRYID, PR_IPM_NOTE_ENTRYID, PR_IPM_TASK_ENTRYID]); |
||
| 734 | |||
| 735 | switch ($messageClass) { |
||
| 736 | case "IPM.Appointment": |
||
| 737 | if (isset($rootcontainerprops[PR_IPM_APPOINTMENT_ENTRYID])) { |
||
| 738 | $entryid = $rootcontainerprops[PR_IPM_APPOINTMENT_ENTRYID]; |
||
| 739 | } |
||
| 740 | break; |
||
| 741 | |||
| 742 | case "IPM.Contact": |
||
| 743 | case "IPM.DistList": |
||
| 744 | if (isset($rootcontainerprops[PR_IPM_CONTACT_ENTRYID])) { |
||
| 745 | $entryid = $rootcontainerprops[PR_IPM_CONTACT_ENTRYID]; |
||
| 746 | } |
||
| 747 | break; |
||
| 748 | |||
| 749 | case "IPM.StickyNote": |
||
| 750 | if (isset($rootcontainerprops[PR_IPM_NOTE_ENTRYID])) { |
||
| 751 | $entryid = $rootcontainerprops[PR_IPM_NOTE_ENTRYID]; |
||
| 752 | } |
||
| 753 | break; |
||
| 754 | |||
| 755 | case "IPM.Task": |
||
| 756 | if (isset($rootcontainerprops[PR_IPM_TASK_ENTRYID])) { |
||
| 757 | $entryid = $rootcontainerprops[PR_IPM_TASK_ENTRYID]; |
||
| 758 | } |
||
| 759 | break; |
||
| 760 | |||
| 761 | default: |
||
| 762 | if (isset($rootcontainerprops[PR_IPM_DRAFTS_ENTRYID])) { |
||
| 763 | $entryid = $rootcontainerprops[PR_IPM_DRAFTS_ENTRYID]; |
||
| 764 | } |
||
| 765 | break; |
||
| 766 | } |
||
| 767 | } |
||
| 768 | |||
| 769 | return $entryid; |
||
| 770 | } |
||
| 771 | |||
| 772 | /** |
||
| 773 | * Function which copies or moves one or more items. |
||
| 774 | * |
||
| 775 | * @param resource $store MAPI Message Store Object |
||
| 776 | * @param string $parententryid entryid of the folder |
||
| 777 | * @param mixed $entryids list of entryids which will be copied or moved (in binary format) |
||
| 778 | * @param array $action the action data, sent by the client |
||
| 779 | */ |
||
| 780 | public function copy($store, $parententryid, $entryids, $action) { |
||
| 781 | $result = false; |
||
| 782 | |||
| 783 | if ($store && $parententryid && $entryids) { |
||
| 784 | $dest_store = $store; |
||
| 785 | if (isset($action["message_action"]["destination_store_entryid"])) { |
||
| 786 | $dest_storeentryid = hex2bin($action["message_action"]["destination_store_entryid"]); |
||
| 787 | $dest_store = $GLOBALS["mapisession"]->openMessageStore($dest_storeentryid); |
||
| 788 | } |
||
| 789 | |||
| 790 | $dest_folderentryid = false; |
||
| 791 | if (isset($action["message_action"]["destination_parent_entryid"])) { |
||
| 792 | $dest_folderentryid = hex2bin($action["message_action"]["destination_parent_entryid"]); |
||
| 793 | } |
||
| 794 | |||
| 795 | $moveMessages = false; |
||
| 796 | if (isset($action["message_action"]["action_type"]) && $action["message_action"]["action_type"] == "move") { |
||
| 797 | $moveMessages = true; |
||
| 798 | } |
||
| 799 | |||
| 800 | // if item has some set of props that need to be saved into the newly copied/moved item |
||
| 801 | $copyProps = []; |
||
| 802 | if (isset($action["message_action"]["dropmodifications"])) { |
||
| 803 | $copyProps = Conversion::mapXML2MAPI($this->properties, $action["message_action"]["dropmodifications"]); |
||
| 804 | } |
||
| 805 | |||
| 806 | // if item has some changes made before choosing different calendar from create-in dropdown |
||
| 807 | if (isset($action["props"]) && !empty($action["props"])) { |
||
| 808 | $copyProps = Conversion::mapXML2MAPI($this->properties, $action["props"]); |
||
| 809 | } |
||
| 810 | |||
| 811 | $props = []; |
||
| 812 | $props[PR_PARENT_ENTRYID] = $parententryid; |
||
| 813 | $props[PR_ENTRYID] = $entryids; |
||
| 814 | |||
| 815 | $storeprops = mapi_getprops($store, [PR_ENTRYID]); |
||
| 816 | $props[PR_STORE_ENTRYID] = $storeprops[PR_ENTRYID]; |
||
| 817 | |||
| 818 | $skipCopyProperties = []; |
||
| 819 | if (isset($action["message_action"]["unset_Private"])) { |
||
| 820 | if ($moveMessages) { |
||
| 821 | array_push($skipCopyProperties, $this->properties["private"], $this->properties["sensitivity"]); |
||
| 822 | } |
||
| 823 | else { |
||
| 824 | array_push($this->skipCopyProperties, $this->properties["private"], $this->properties["sensitivity"]); |
||
| 825 | } |
||
| 826 | } |
||
| 827 | |||
| 828 | $result = $GLOBALS["operations"]->copyMessages($store, $parententryid, $dest_store, $dest_folderentryid, $entryids, $moveMessages ? $skipCopyProperties : $this->skipCopyProperties, $moveMessages, $copyProps); |
||
| 829 | |||
| 830 | if ($result) { |
||
| 831 | if ($moveMessages) { |
||
| 832 | $GLOBALS["bus"]->notify(bin2hex($parententryid), TABLE_DELETE, $props); |
||
| 833 | } |
||
| 834 | |||
| 835 | // Delete the PR_ENTRYID, the copied or moved message has a new entryid, |
||
| 836 | // and at this time we have no idea what that might be. So make sure |
||
| 837 | // we unset it, otherwise the notification handlers get weird ideas |
||
| 838 | // and could reset the PR_PARENT_ENTRYID to the old folder again. |
||
| 839 | unset($props[PR_ENTRYID]); |
||
| 840 | $props[PR_PARENT_ENTRYID] = $dest_folderentryid; |
||
| 841 | $props[PR_STORE_ENTRYID] = $dest_storeentryid; |
||
| 842 | $GLOBALS["bus"]->notify(bin2hex($dest_folderentryid), TABLE_SAVE, $props); |
||
| 843 | } |
||
| 844 | |||
| 845 | $this->sendFeedback($result, []); |
||
| 846 | } |
||
| 847 | } |
||
| 848 | |||
| 849 | /** |
||
| 850 | * Function returns correspondent calendar item's properties attached |
||
| 851 | * with the meeting request/response/cancellation. |
||
| 852 | * |
||
| 853 | * @param Meetingrequest $meetingRequestObject the meeting request object |
||
| 854 | * using which function will fetch meeting request properties and return them |
||
| 855 | */ |
||
| 856 | public function getCalendarItemProps($meetingRequestObject) { |
||
| 857 | $calendarItem = $meetingRequestObject->getCorrespondentCalendarItem(); |
||
| 858 | $props = []; |
||
| 859 | if ($calendarItem !== false) { |
||
| 860 | $calendarItemProps = mapi_getprops($calendarItem, [PR_STORE_ENTRYID, PR_PARENT_ENTRYID, PR_ENTRYID, $meetingRequestObject->proptags['updatecounter'], $meetingRequestObject->proptags['goid']]); |
||
| 861 | |||
| 862 | // Store calendar item's necessary properties in props array. |
||
| 863 | $props['appointment_store_entryid'] = bin2hex((string) $calendarItemProps[PR_STORE_ENTRYID]); |
||
| 864 | $props['appointment_parent_entryid'] = bin2hex((string) $calendarItemProps[PR_PARENT_ENTRYID]); |
||
| 865 | $props['appointment_entryid'] = bin2hex((string) $calendarItemProps[PR_ENTRYID]); |
||
| 866 | |||
| 867 | $props['appointment_updatecounter'] = $calendarItemProps[$meetingRequestObject->proptags['updatecounter']] ?? 0; |
||
| 868 | |||
| 869 | $messageProps = mapi_getprops($meetingRequestObject->message, [$meetingRequestObject->proptags['goid']]); |
||
| 870 | |||
| 871 | $basedate = $meetingRequestObject->getBasedateFromGlobalID($messageProps[$meetingRequestObject->proptags['goid']]); |
||
| 872 | |||
| 873 | if ($basedate !== false) { |
||
| 874 | $props['appointment_basedate'] = $basedate; |
||
| 875 | |||
| 876 | // if basedate is provided then it is exception, so get update counter of the exception |
||
| 877 | $exception = $meetingRequestObject->getExceptionItem($calendarItem, $basedate); |
||
| 878 | |||
| 879 | if ($exception !== false) { |
||
| 880 | // we are able to find the exception then get updatecounter |
||
| 881 | $exceptionProps = mapi_getprops($exception, [$meetingRequestObject->proptags['updatecounter']]); |
||
| 882 | $props['appointment_updatecounter'] = $exceptionProps[$meetingRequestObject->proptags['updatecounter']] ?? 0; |
||
| 883 | } |
||
| 884 | } |
||
| 885 | |||
| 886 | if ($meetingRequestObject->isMeetingRequestResponse()) { |
||
| 887 | $props['meeting_updated'] = $meetingRequestObject->isMeetingUpdated($basedate); |
||
| 888 | } |
||
| 889 | |||
| 890 | return $props; |
||
| 891 | } |
||
| 892 | |||
| 893 | return false; |
||
| 894 | } |
||
| 895 | |||
| 896 | /** |
||
| 897 | * Get a text body for a Non-Delivery report. |
||
| 898 | * |
||
| 899 | * This function reads the necessary properties from the passed message and constructs |
||
| 900 | * a user-readable NDR message from those properties |
||
| 901 | * |
||
| 902 | * @param mapimessage $message The NDR message to read the information from |
||
| 903 | * |
||
| 904 | * @return string NDR body message as plaintext message |
||
| 905 | */ |
||
| 906 | public function getNDRbody($message) { |
||
| 930 | } |
||
| 931 | |||
| 932 | /** |
||
| 933 | * Send a meeting cancellation. |
||
| 934 | * |
||
| 935 | * This function sends a meeting cancellation for the meeting references by the passed entryid. It |
||
| 936 | * will send the meeting cancellation and move the item itself to the waste basket. |
||
| 937 | * |
||
| 938 | * @param mapistore $store The store in which the meeting request resides |
||
| 939 | * @param string $entryid entryid of the appointment for which the cancellation should be sent |
||
| 940 | * @param object $action data sent by client |
||
| 941 | * @param bool $directBookingMeetingRequest Indicates if a Meeting Request should use direct booking or not |
||
| 942 | */ |
||
| 943 | public function cancelInvitation($store, $entryid, $action, $directBookingMeetingRequest) { |
||
| 971 | } |
||
| 972 | } |
||
| 973 | |||
| 974 | /** |
||
| 975 | * Remove all appointments for a certain meeting request. |
||
| 976 | * |
||
| 977 | * This function searches the default calendar for all meeting requests for the specified |
||
| 978 | * meeting. All those appointments are then removed. |
||
| 979 | * |
||
| 980 | * @param mapistore $store Mapi store in which the meeting request and the calendar reside |
||
| 981 | * @param string $entryid Entryid of the meeting request or appointment for which all items should be deleted |
||
| 982 | * @param string $basedate if specified contains starttime of day of an occurrence |
||
| 983 | * @param bool $directBookingMeetingRequest Indicates if a Meeting Request should use direct booking or not |
||
| 984 | */ |
||
| 985 | public function removeFromCalendar($store, $entryid, $basedate, $directBookingMeetingRequest) { |
||
| 995 | } |
||
| 996 | } |
||
| 997 |