Files
2026-11-30 16:32:37 +00:00

1411 lines
54 KiB
PHP

<?php
/*
* SPDX-FileCopyrightText: Copyright 2020 - 2026 grommunio GmbH
* SPDX-FileCopyrightText: Copyright 2016 Kopano and its licensors
* SPDX-FileCopyrightText: Copyright 2005 - 2016 Zarafa B.V. and its licensors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
require_once __DIR__ . '/../core/class.meetingrequestforwarder.php';
require_once __DIR__ . '/../hexutil.php';
/**
* ItemModule
* Module which opens, creates, saves and deletes an item. It
* extends the Module class.
*/
class ItemModule extends Module {
/**
* The setting whether Meeting Requests should be booked directly or not.
*/
public $directBookingMeetingRequest;
/**
* The opt-in setting whether responding to a meeting outside the request mail
* also removes that mail.
*/
public $removeRequestOnResponse;
/**
* The array of properties which should not be copied during the copy() action.
*/
public $skipCopyProperties;
/**
* Indicates that we are supporting only plain text body in the message props.
*/
public $plaintext;
/**
* Constructor.
*
* @param int $id unique id
* @param array $data list of all actions
*/
public function __construct($id, $data) {
$this->directBookingMeetingRequest = ENABLE_DIRECT_BOOKING;
$this->removeRequestOnResponse = $GLOBALS['settings']->get(
'grommunio/v1/contexts/calendar/remove_meetingrequest_on_calendar_response',
false
);
$this->skipCopyProperties = [];
$this->plaintext = false;
parent::__construct($id, $data);
}
/**
* Create a meeting-request helper against either the four- or five-argument
* mapi-header-php constructor.
*
* The remove-on-response option was added as a fifth constructor argument.
* Older supported mapi-header-php releases do not expose it, so they retain
* their original behavior while newer releases receive the configured value.
*
* @param resource $store
* @param resource $message
*
* @return Meetingrequest
*/
protected function createMeetingRequest($store, $message) {
$reflection = new ReflectionClass(Meetingrequest::class);
$arguments = [
$store,
$message,
$GLOBALS['mapisession']->getSession(),
$this->directBookingMeetingRequest,
];
$constructor = $reflection->getConstructor();
if ($constructor !== null && $constructor->getNumberOfParameters() >= 5) {
$arguments[] = $this->removeRequestOnResponse;
}
return $reflection->newInstanceArgs($arguments);
}
/**
* Executes all the actions in the $data variable.
*/
#[Override]
public function execute() {
foreach ($this->data as $actionType => $action) {
if (!isset($actionType)) {
continue;
}
$parententryid = null;
$entryid = null;
$singleEntryid = null;
try {
$store = $this->getActionStore($action);
if (is_array($store)) {
$this->sendFeedback(false);
continue;
}
$parententryid = $this->getActionParentEntryID($action);
$entryid = $this->getActionEntryID($action);
$singleEntryid = is_string($entryid) ? $entryid : false;
switch ($actionType) {
case "open":
$this->open($store, $singleEntryid, $action);
break;
case "save":
if (!$store || !$parententryid) {
/*
* if parententryid or storeentryid is not passed then we can take a guess that
* it would be a save operation but instead of depending on server to get default
* parent and store client should always send parententryid and storeentryid
*
* we can also assume that user has permission to right in his own store
*/
$this->save($store, $parententryid, $singleEntryid, $action);
break;
}
/*
* The "message_action" object has been set, check the action_type field for
* the exact action which must be taken.
* Supported actions:
* - acceptmeetingrequest: attendee has accepted mr
* - declineMeetingRequest: attendee has declined mr
*/
if (!isset($action["message_action"], $action["message_action"]["action_type"])) {
$this->save($store, $parententryid, $singleEntryid, $action);
break;
}
$subActionType = $action["message_action"]["action_type"];
if ($singleEntryid === false && in_array($subActionType, ["declineMeetingRequest", "acceptMeetingRequest", "acceptTaskRequest", "declineTaskRequest", "forwardMeetingRequest", "removeAttachments"])) {
$this->sendFeedback(false);
break;
}
switch ($subActionType) {
case "declineMeetingRequest":
case "acceptMeetingRequest":
$this->respondToMeetingRequest($store, $singleEntryid, $action);
break;
case "acceptTaskRequest":
case "declineTaskRequest":
$this->respondToTaskRequest($store, $singleEntryid, $action);
break;
case "copy":
case "move":
case "copyToNote":
$this->copy($store, $parententryid, $entryid, $action);
break;
case "forwardMeetingRequest":
$this->forwardMeetingRequest($store, $singleEntryid, $action, $this->directBookingMeetingRequest);
break;
case "removeAttachments":
$this->removeAttachments($store, $singleEntryid, $action);
break;
case "reply":
case "replyall":
case "forward":
default:
$this->save($store, $parententryid, $singleEntryid, $action);
}
break;
case "delete":
$subActionType = false;
if (isset($action["message_action"], $action["message_action"]["action_type"])) {
$subActionType = $action["message_action"]["action_type"];
}
if (($store === false || $singleEntryid === false) && in_array($subActionType, ["removeFromCalendar", "cancelInvitation", "declineMeeting"])) {
$this->sendFeedback(false);
break;
}
/*
* The "message_action" object has been set, check the action_type field for
* the exact action which must be taken.
* Supported actions:
* - cancelInvitation: organizer cancels already scheduled meeting
* - removeFromCalendar: attendee receives meeting cancellation and wants to remove item from calendar
*/
switch ($subActionType) {
case "removeFromCalendar":
$basedate = !empty($action['basedate']) ? $action['basedate'] : false;
$this->removeFromCalendar($store, $singleEntryid, $basedate, $this->directBookingMeetingRequest);
$this->sendFeedback(true);
break;
case "cancelInvitation":
$this->cancelInvitation($store, $singleEntryid, $action, $this->directBookingMeetingRequest);
$this->sendFeedback(true);
break;
case "declineMeeting":
$this->declineMeeting($store, $singleEntryid, $action);
break;
case "snooze":
case "dismiss":
$this->delete($store, $parententryid, $singleEntryid, $action);
break;
default:
// Deleting an occurrence means that we have to save the message to
// generate an exception. So when the basedate is provided, we actually
// perform a save rather then delete.
if (!empty($action['basedate'])) {
$this->save($store, $parententryid, $singleEntryid, $action, "delete");
}
else {
$this->delete($store, $parententryid, $entryid, $action);
}
break;
}
break;
default:
$this->handleUnknownActionType($actionType);
}
}
catch (MAPIException $e) {
$this->processException($e, $actionType, $store, $parententryid, $singleEntryid, $action);
}
}
}
/**
* Accepts or declines a meeting request as the attendee.
*
* @param resource $store MAPI store of the message
* @param string $entryid entryid of the meeting request or appointment
* @param array $action the action data, sent by the client
*/
private function respondToMeetingRequest($store, $entryid, $action) {
$message = $GLOBALS["operations"]->openMessage($store, $entryid);
$basedate = ($action['basedate'] ?? false);
$delete = false;
if ($basedate) {
$recurrence = new Recurrence($store, $message);
$exceptionatt = $recurrence->getExceptionAttachment($basedate);
if ($exceptionatt) {
// get properties of existing exception.
$exceptionattProps = mapi_getprops($exceptionatt, [PR_ATTACH_NUM]);
$attach_num = $exceptionattProps[PR_ATTACH_NUM];
}
}
/**
* Get message class from original message. This can be changed to
* IPM.Appointment if the item is a Meeting Request in the maillist.
* After Accepting/Declining the message is moved and changed.
*/
$originalMessageProps = mapi_getprops($message, [PR_MESSAGE_CLASS]);
// Clear PR_PROCESSED so that doAccept fully copies
// all properties from the meeting request to the
// calendar item. Without this, an update that changes
// a single meeting into a recurring series is not
// applied because the flag was already set during
// auto-processing in open().
mapi_deleteprops($message, [PR_PROCESSED]);
$req = $this->createMeetingRequest($store, $message);
// Update extra body information
if (!empty($action["message_action"]['meetingTimeInfo'])) {
$req->setMeetingTimeInfo($action["message_action"]['meetingTimeInfo'],
$action["message_action"]['mti_html'] ?? false);
unset($action["message_action"]['meetingTimeInfo']);
}
// sendResponse flag if it is set then send the mail response to the organzer.
$sendResponse = ($action["message_action"]["sendResponse"] ?? true) != false;
$body = $this->getResponseBody($action);
if ($action["message_action"]["action_type"] == "acceptMeetingRequest") {
$tentative = $action["message_action"]["responseType"] === olResponseTentative;
$newProposedStartTime = $action["message_action"]["proposed_starttime"] ?? false;
$newProposedEndTime = $action["message_action"]["proposed_endtime"] ?? false;
// We are accepting MR from preview-read-mail so set delete the actual mail flag.
$delete = $req->isMeetingRequest($originalMessageProps[PR_MESSAGE_CLASS]);
$req->doAccept($tentative, $sendResponse, $delete, $newProposedStartTime, $newProposedEndTime, $body, true, $store, $basedate);
}
else {
$delete = $req->doDecline($sendResponse, $basedate, $body);
}
/**
* Now if the item is the Meeting Request that was sent to the attendee
* it is removed when the user has clicked on Accept/Decline. If the
* item is the appointment in the calendar it will not be moved. To only
* notify the bus when the item is a Meeting Request we are going to
* check the PR_MESSAGE_CLASS and see if it is "IPM.Meeting*".
*/
$messageProps = mapi_getprops($message, [PR_ENTRYID, PR_STORE_ENTRYID, PR_PARENT_ENTRYID]);
// if opened appointment is exception then it will add
// the attach_num and basedate in messageProps.
if (isset($attach_num)) {
$messageProps[PR_ATTACH_NUM] = [$attach_num];
$messageProps[$this->properties["basedate"]] = $basedate;
}
if ($delete) {
// send TABLE_DELETE event because the message has moved
$this->sendFeedback(true);
$GLOBALS["bus"]->notify(bin2hex((string) $messageProps[PR_PARENT_ENTRYID]), TABLE_DELETE, $messageProps);
}
else {
$this->addActionData("update", ["item" => Conversion::mapMAPI2XML($this->properties, $messageProps)]);
$GLOBALS["bus"]->addData($this->getResponseData());
// send TABLE_SAVE event because an occurrence is deleted
$GLOBALS["bus"]->notify(bin2hex((string) $messageProps[PR_PARENT_ENTRYID]), TABLE_SAVE, $messageProps);
}
}
/**
* Accepts or declines a task request.
*
* @param resource $store MAPI store of the message
* @param string $entryid entryid of the task request
* @param array $action the action data, sent by the client
*/
private function respondToTaskRequest($store, $entryid, $action) {
$message = $GLOBALS["operations"]->openMessage($store, $entryid);
if (!empty($action["props"])) {
$properties = $GLOBALS["properties"]->getTaskProperties();
mapi_setprops($message, Conversion::mapXML2MAPI($properties, $action["props"]));
mapi_savechanges($message);
}
// The task may be a delegated task, do an update if needed (will fail for non-delegated tasks)
$tr = new TaskRequest($store, $message, $GLOBALS["mapisession"]->getSession());
$isAccept = $action["message_action"]["action_type"] == "acceptTaskRequest";
if (!empty($action["message_action"]["task_comments_info"])) {
$tr->setTaskCommentsInfo($action["message_action"]["task_comments_info"]);
}
if ($isAccept) {
$result = $tr->doAccept();
}
else {
$result = $tr->doDecline();
}
$this->sendFeedback(true);
if ($result !== false) {
$GLOBALS["bus"]->notify(bin2hex((string) $result[PR_PARENT_ENTRYID]), TABLE_DELETE, $result);
}
$props = mapi_getprops($message, [PR_ENTRYID, PR_STORE_ENTRYID, PR_PARENT_ENTRYID]);
if (!$tr->isTaskRequest()) {
unset($props[PR_MESSAGE_CLASS]);
$GLOBALS["bus"]->notify(bin2hex((string) $props[PR_PARENT_ENTRYID]), $isAccept ? TABLE_SAVE : TABLE_DELETE, $props);
}
}
/**
* Declines a meeting from the calendar as the attendee.
*
* @param resource $store MAPI store of the appointment
* @param string $entryid entryid of the appointment
* @param array $action the action data, sent by the client
*/
private function declineMeeting($store, $entryid, $action) {
// @FIXME can we somehow merge declineMeeting and declineMeetingRequest sub actions?
$message = $GLOBALS["operations"]->openMessage($store, $entryid);
$basedate = !empty($action['basedate']) ? $action['basedate'] : false;
$req = $this->createMeetingRequest($store, $message);
$body = $this->getResponseBody($action);
$req->doDecline(true, $basedate, $body);
$messageProps = mapi_getprops($message, [PR_ENTRYID, PR_STORE_ENTRYID, PR_PARENT_ENTRYID]);
$GLOBALS["bus"]->notify(bin2hex((string) $messageProps[PR_PARENT_ENTRYID]), $basedate ? TABLE_SAVE : TABLE_DELETE, $messageProps);
}
/**
* @param array $action the action data, sent by the client
*
* @return false|string the response body in the format the client edited it in
*/
private function getResponseBody($action) {
return ($action["props"]["isHTML"] ?? null) === true ? ($action["props"]["html_body"] ?? false) : ($action["props"]["body"] ?? false);
}
/**
* Function does customization of exception based on module data.
* like, here it will generate display message based on actionType
* for particular exception.
*
* @param object $e Exception object
* @param string $actionType the action type, sent by the client
* @param resource $store MAPI store containing the message
* @param string $parententryid parent entryid of the message
* @param string $entryid entryid of the message
* @param array $action the action data, sent by the client
*/
#[Override]
public function handleException(&$e, $actionType = null, $store = null, $parententryid = null, $entryid = null, $action = null) {
if (is_null($e->displayMessage)) {
switch ($actionType) {
case "open":
if ($e->getCode() == MAPI_E_NO_ACCESS) {
$e->setDisplayMessage(_("You have insufficient privileges to open this message."));
}
elseif ($e->getCode() == MAPI_E_NOT_FOUND) {
$e->setDisplayMessage(_("Could not find message, either it has been moved or deleted or you don't have access to open this message."));
// Show error in console instead of a pop-up
if (isset($action["message_action"]['suppress_exception']) && $action["message_action"]['suppress_exception'] === true) {
$e->setNotificationType('console');
}
}
else {
$e->setDisplayMessage(_("Could not open message."));
$e->allowToShowDetailsMessage = true;
}
break;
case "save":
if ($e->getCode() == MAPI_E_NO_ACCESS) {
if (!empty($action["message_action"]["action_type"])) {
switch ($action["message_action"]["action_type"]) {
case "declineMeetingRequest":
$e->setDisplayMessage(_("You have insufficient privileges to decline this Meeting Request."));
break;
case "acceptMeetingRequest":
$e->setDisplayMessage(_("You have insufficient privileges to accept this Meeting Request."));
break;
case "copy":
case "copyToNote":
$e->setDisplayMessage(_("Could not copy message."));
break;
case "move":
$e->setDisplayMessage(_("Could not move message."));
break;
case "forwardMeetingRequest":
$e->setDisplayMessage(_("Could not forward meeting request."));
break;
}
}
if (empty($e->displayMessage)) {
$e->setDisplayMessage(_("You have insufficient privileges to save items in this folder."));
}
}
elseif ($e->getCode() == MAPI_E_STORE_FULL) {
$e->setDisplayMessage($this->getOverQuotaMessage($store));
}
else {
$e->setDisplayMessage(_("Could not save message."));
$e->allowToShowDetailsMessage = true;
}
break;
case 'delete':
switch ($e->getCode()) {
case MAPI_E_NO_ACCESS:
if (!empty($action['message_action']['action_type'])) {
switch ($action['message_action']['action_type']) {
case 'removeFromCalendar':
$e->setDisplayMessage(_('You have insufficient privileges to remove item from the calendar.'));
break;
}
}
break;
case MAPI_E_NOT_IN_QUEUE:
$e->setDisplayMessage(_('Message is no longer in the outgoing queue, typically because it has already been sent.'));
break;
case MAPI_E_UNABLE_TO_ABORT:
$e->setDisplayMessage(_('Message cannot be aborted'));
break;
}
if (empty($e->displayMessage)) {
$e->setDisplayMessage(_("You have insufficient privileges to delete items in this folder."));
}
break;
case "attach_items":
if ($e->getCode() == MAPI_E_NO_ACCESS) {
$e->setDisplayMessage(_("You have insufficient privileges to attach item as an attachment."));
}
else {
$e->setDisplayMessage(_("Could not attach item as an attachment."));
}
break;
case "reclaimownership":
if ($e->getCode() == MAPI_E_NO_ACCESS) {
$e->setDisplayMessage(_("You have insufficient privileges to reclaim the ownership for the Task Request."));
}
else {
$e->setDisplayMessage(_("Could not reclaim the ownership for the Task Request."));
}
break;
case "acceptTaskRequest":
if ($e->getCode() == MAPI_E_NO_ACCESS) {
$e->setDisplayMessage(_("You have insufficient privileges to accept this Task Request."));
}
else {
$e->setDisplayMessage(_("Could not accept Task Request."));
}
break;
case "declineTaskRequest":
if ($e->getCode() == MAPI_E_NO_ACCESS) {
$e->setDisplayMessage(_("You have insufficient privileges to decline this Task Request."));
}
else {
$e->setDisplayMessage(_("Could not decline Task Request."));
}
break;
}
Log::Write(
LOGLEVEL_ERROR,
"itemmodule::handleException():" . $actionType . ": " . $e->displayMessage
);
}
parent::handleException($e, $actionType, $store, $parententryid, $entryid, $action);
}
/**
* Function which opens an item.
*
* @param false|resource $store MAPI message store, or false if it was not supplied
* @param false|string $entryid entry ID of the message, or false if it was not supplied
* @param array $action action data sent by the client
*/
public function open($store, $entryid, $action) {
$data = [];
$message = false;
if ($entryid) {
if ($store !== false) {
$message = $GLOBALS['operations']->openMessage($store, $entryid);
}
else {
// store is not passed so we need to open the message first to get the store resource
$message = $GLOBALS['mapisession']->openMessage($entryid);
$messageStoreInfo = mapi_getprops($message, [PR_STORE_ENTRYID]);
$store = $GLOBALS['mapisession']->openMessageStore($messageStoreInfo[PR_STORE_ENTRYID]);
}
}
if (empty($message) || $store === false) {
return;
}
// Detect whether S/MIME decoding or meeting request processing is required
$props = mapi_getprops($message, [PR_MESSAGE_CLASS]);
$messageClass = $props[PR_MESSAGE_CLASS] ?? '';
$requiresSmime = stripos((string) $messageClass, 'SMIME') !== false; /* infix match(!), cannot use class_match_prefix */
$requiresMeeting = class_match_prefix($messageClass, "IPM.Schedule.Meeting");
// Decode S/MIME signed messages only when needed
if ($requiresSmime || (defined('PLUGIN_PGP_ENABLE') && PLUGIN_PGP_ENABLE)) {
parse_smime($store, $message);
}
// Open embedded message if requested
$attachNum = !empty($action['attach_num']) ? $action['attach_num'] : false;
if ($attachNum) {
// get message props of sub message
$parentMessage = $message;
$message = $GLOBALS['operations']->openMessage($store, $entryid, $attachNum, true);
if (empty($message)) {
// Without this the client is left with an empty item and no reason.
throw new GrommunioException('attachment ' . implode('.', (array) $attachNum) . ' holds no message', 0, null, _("Could not open the attachment."));
}
$data['item'] = $GLOBALS['operations']->getEmbeddedMessageProps($store, $message, $this->properties, $parentMessage, $attachNum);
}
else {
// Mark as read if requested by the client. This combines the
// open + mark-as-read into a single HTTP round-trip by setting
// the read flag BEFORE getMessageProps(), so the returned
// message_flags already includes MSGFLAG_READ.
if (isset($action['message_action']['mark_read'])) {
$flag = MAPI_DEFERRED_ERRORS;
if (isset($action['message_action']['send_read_receipt']) &&
$action['message_action']['send_read_receipt'] == false) {
$flag |= SUPPRESS_RECEIPT;
}
mapi_message_setreadflag($message, $flag);
// Notify the mail list so it updates the unread state / counter.
$notifyProps = mapi_getprops($message, [PR_ENTRYID, PR_STORE_ENTRYID, PR_PARENT_ENTRYID]);
$GLOBALS['bus']->notify(bin2hex((string) $notifyProps[PR_PARENT_ENTRYID]), TABLE_SAVE, $notifyProps);
}
// get message props of the message
$data['item'] = $GLOBALS['operations']->getMessageProps($store, $message, $this->properties, $this->plaintext, true);
$messageClass = $data['item']['props']['message_class'] ?? $messageClass;
// Determine again if meeting processing is required after parsing
if (!$requiresMeeting) {
$requiresMeeting = class_match_prefix($messageClass, "IPM.Schedule.Meeting");
}
// Skip meeting request processing for items in the Sent
// Items folder — those are outgoing copies that should not
// be processed as incoming requests.
$isSentItem = false;
if ($requiresMeeting) {
$sentStoreProps = mapi_getprops($store, [PR_IPM_SENTMAIL_ENTRYID]);
$msgFolderProps = mapi_getprops($message, [PR_PARENT_ENTRYID]);
if (isset($sentStoreProps[PR_IPM_SENTMAIL_ENTRYID], $msgFolderProps[PR_PARENT_ENTRYID]) &&
$GLOBALS['entryid']->compareEntryIds(
bin2hex((string) $sentStoreProps[PR_IPM_SENTMAIL_ENTRYID]),
bin2hex((string) $msgFolderProps[PR_PARENT_ENTRYID]))) {
$isSentItem = true;
}
}
// A forward notification adds the forwarded attendees to the
// organizer's meeting, other notifications are informational only.
$isForwardNotification = class_match_prefix($messageClass, "IPM.Schedule.Meeting.Notification.Forward");
$isMeetingNotification = !$isForwardNotification && class_match_prefix($messageClass, "IPM.Schedule.Meeting.Notification");
// Check for meeting request, do processing if necessary
if ($requiresMeeting && !$isSentItem && !$isMeetingNotification) {
$req = new Meetingrequest($store, $message, $GLOBALS['mapisession']->getSession(), $this->directBookingMeetingRequest);
try {
if ($isForwardNotification) {
if ($req->processMeetingForwardNotification()) {
$this->notifyForwardedMeeting($store, $req);
}
}
elseif ($req->isMeetingRequestResponse($messageClass)) {
if ($req->isLocalOrganiser()) {
// We received a meeting request response, and we're the delegate/organiser
$req->processMeetingRequestResponse();
}
}
elseif ($req->isMeetingRequest($messageClass)) {
if (!$req->isLocalOrganiser()) {
if ($req->isMeetingOutOfDate()) {
// we know that meeting is out of date so directly set this properties
$data['item']['props']['meetingtype'] = mtgOutOfDate;
$data['item']['props']['icon_index'] = 1033;
// send update to maillistmodule that meeting request is updated with out of date flag
$messageProps = mapi_getprops($message, [PR_ENTRYID, PR_PARENT_ENTRYID, PR_STORE_ENTRYID]);
$GLOBALS['bus']->notify(bin2hex((string) $messageProps[PR_PARENT_ENTRYID]), TABLE_SAVE, $messageProps);
}
else {
/*
* if meeting request is not out of date then process it for the first time
* which will create corresponding appointment in the user's calendar
*/
$calItemEntryid = $req->doAccept(true, false, false);
// we need to set timezone information for all-day events
if (isset($data['item']['props']['alldayevent']) &&
$data['item']['props']['alldayevent'] == true &&
!empty($action["timezone_iana"]) &&
is_string($calItemEntryid)) {
try {
$tzdef = mapi_ianatz_to_tzdef($action['timezone_iana']);
$localStart = getLocalStart($data['item']['props']['appointment_startdate'], $action['timezone_iana']);
$duration = $data['item']['props']['appointment_duedate'] - $data['item']['props']['appointment_startdate'];
$calItem = $GLOBALS['mapisession']->openMessage($calItemEntryid);
mapi_setprops($calItem, [
$this->properties['appointment_startdate'] => $localStart,
$this->properties['appointment_duedate'] => $localStart + $duration,
$this->properties['tzdefstart'] => $tzdef,
$this->properties['tzdefend'] => $tzdef,
]);
mapi_savechanges($calItem);
}
catch (Exception $e) {
error_log(sprintf("Error setting timezone to an all-day event: %s", $e));
}
}
}
// Show user whether meeting request conflict with other appointment or not.
$meetingConflicts = $req->isMeetingConflicting();
/**
* if $meetingConflicts is boolean and true then its a normal meeting.
* if $meetingConflicts is integer then it indicates no of instances of a recurring meeting which conflicts with Calendar.
*/
if ($meetingConflicts !== false) {
if ($meetingConflicts === true) {
$data['item']['props']['conflictinfo'] = _('Conflicts with another appointment.');
}
else {
$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);
}
}
}
}
elseif ($req->isMeetingCancellation()) {
$req->processMeetingCancellation();
}
if ($req->isInCalendar()) {
$calendarItemProps = $this->getCalendarItemProps($req);
if (!empty($calendarItemProps)) {
$data['item']['props'] = array_merge($data['item']['props'], $calendarItemProps);
}
}
elseif (!$isForwardNotification) {
$data['item']['props']['appointment_not_found'] = true;
}
}
catch (MAPIException $e) {
// If the quota is exceeded or we cannot write to the calendar folder, ignore the exception.
// gromox reports a calendar without read rights (e.g. a former delegator's) as not found.
if ($e->getCode() !== MAPI_E_STORE_FULL && $e->getCode() !== MAPI_E_NO_ACCESS && $e->getCode() !== MAPI_E_NOT_FOUND) {
// re-throw the exception if it is not one of quota/calendar permission.
throw $e;
}
}
if (!empty($data['item']['props']['appointment_recurring']) &&
empty($data['item']['props']['appointment_recurring_pattern'])) {
$recurr = new Recurrence($store, $message);
$data['item']['props']['appointment_recurring_pattern'] = $recurr->saveRecurrencePattern();
}
}
elseif (class_match_prefix($messageClass, "REPORT.IPM.NOTE.NDR")) {
// check if this message is a NDR (mail)message, if so, generate a new body message
$data['item']['props']['isHTML'] = false;
$data['item']['props']['body'] = $this->getNDRbody($message);
}
}
$userEntryId = '';
if (isset($data['item']['props']['sent_representing_entryid'])) {
$userEntryId = hex2bin($data['item']['props']['sent_representing_entryid']);
}
elseif (isset($data['item']['props']['sender_entryid'])) {
$userEntryId = hex2bin($data['item']['props']['sender_entryid']);
}
// get user image saved in LDAP.
if (!empty($userEntryId)) {
$data['item']['props']['user_image'] = $GLOBALS['operations']->getCompressedUserImage($userEntryId);
}
// Allowing to hook in just before the data sent away to be sent to the client
$GLOBALS['PluginManager']->triggerHook('server.module.itemmodule.open.after', [
'moduleObject' => &$this,
'store' => $store,
'entryid' => $entryid,
'action' => $action,
'message' => &$message,
'data' => &$data,
]);
// ugly workaround to show clip icon for the signed/encrypted emails
if (isset($data['item']['props']['smime'])) {
$data['item']['props']['hasattach'] = true;
unset($data['item']['props']['hide_attachments']);
}
$this->addActionData('item', $data);
$GLOBALS['bus']->addData($this->getResponseData());
}
/**
* Function which saves an item.
*
* @param false|resource $store MAPI message store, or false to use the default
* @param false|string $parententryid parent entry ID, or false to infer it
* @param false|string $entryid entry ID of the message, or false for a new item
* @param array $action the action data, sent by the client
* @param string $actionType The action type which triggered this action
*/
public function save($store, $parententryid, $entryid, $action, $actionType = 'save') {
$result = false;
if (isset($action["props"])) {
if ($store === false) {
$store = $GLOBALS['mapisession']->getDefaultMessageStore();
}
if (!$parententryid) {
if (isset($action['props']['message_class'])) {
$parententryid = $this->getDefaultFolderEntryID($store, $action['props']['message_class']);
}
else {
$parententryid = $this->getDefaultFolderEntryID($store, '');
}
}
if ($store !== false && $parententryid) {
$props = Conversion::mapXML2MAPI($this->properties, $action["props"]);
$messageProps = []; // props returned from saveMessage
// Save message
if (!empty($props)) {
$result = $GLOBALS["operations"]->saveMessage($store, $entryid, $parententryid, $props, $messageProps, [], !empty($action['attachments']) ? $action['attachments'] : []);
}
if ($result) {
$GLOBALS["bus"]->notify(bin2hex($parententryid), TABLE_SAVE, $messageProps);
$this->addActionData("update", ["item" => Conversion::mapMAPI2XML($this->properties, $messageProps)]);
$GLOBALS["bus"]->addData($this->getResponseData());
}
else {
$this->sendFeedback(false);
}
}
}
}
/**
* Function which deletes an item.
*
* @param false|resource $store MAPI message store, or false when unavailable
* @param false|string $parententryid parent entry ID, or false when unavailable
* @param array|false|string $entryid entry ID or IDs, or false when unavailable
* @param array $action action data sent by the client
*/
public function delete($store, $parententryid, $entryid, $action) {
if ($store === false || !$parententryid || !$entryid) {
return;
}
$props = [];
$props[PR_PARENT_ENTRYID] = $parententryid;
$props[PR_ENTRYID] = $entryid;
$storeprops = mapi_getprops($store, [PR_ENTRYID]);
$props[PR_STORE_ENTRYID] = $storeprops[PR_ENTRYID];
$soft = $action['message_action']['soft_delete'] ?? false;
$unread = $action['message_action']['non_read_notify'] ?? false;
// When the client asked to track the new entryids (undo support),
// snapshot the target wastebasket and the items' move-stable search
// keys before the delete, so they can be relocated afterwards.
$undoInfo = $this->prepareDeleteUndo($store, $parententryid, $entryid, $action, $soft);
$result = $GLOBALS["operations"]->deleteMessages($store, $parententryid, $entryid, $soft, $unread);
if ($result) {
$GLOBALS["bus"]->notify(bin2hex($parententryid), TABLE_DELETE, $props);
$this->sendFeedback(true, $this->buildDeleteUndoFeedback($undoInfo));
}
else {
$this->sendFeedback(false);
}
}
/**
* Snapshot the information needed to make a delete undoable (see the
* 'track_new_entryids' message action). Determines where deleteMessages()
* will move the items and remembers their move-stable PR_SEARCH_KEYs, as
* well as the items already present in the target wastebasket which share
* one of those keys. Only deletes that end up in a wastebasket (not
* hard/soft deletes) can be tracked; otherwise null is returned.
*
* Must be called before the delete, while the items still exist.
*
* @param resource $store MAPI message store
* @param string $parententryid parent entryid of the message(s)
* @param array|string $entryid one entryid or a list of entryids
* @param array $action the action data, sent by the client
* @param bool $soft whether this is a soft delete
*
* @return null|array the undo snapshot, or null when not trackable
*/
protected function prepareDeleteUndo($store, $parententryid, $entryid, $action, $soft) {
if (empty($action['message_action']['track_new_entryids']) || $soft) {
return null;
}
$msgprops = mapi_getprops($store, [PR_IPM_WASTEBASKET_ENTRYID, PR_MDB_PROVIDER, PR_IPM_OUTBOX_ENTRYID]);
// Deleting from the Outbox aborts submission of deferred-send mail;
// an undo would restore it looking scheduled while it never sends.
if (isset($msgprops[PR_IPM_OUTBOX_ENTRYID]) && $msgprops[PR_IPM_OUTBOX_ENTRYID] == $parententryid) {
return null;
}
$wastebasketStore = null;
$wastebasketEntryid = false;
switch ($msgprops[PR_MDB_PROVIDER] ?? '') {
case ZARAFA_SERVICE_GUID:
// Own store: items move to the own wastebasket, unless
// they are already in it (then they are hard deleted).
if (isset($msgprops[PR_IPM_WASTEBASKET_ENTRYID]) && $msgprops[PR_IPM_WASTEBASKET_ENTRYID] != $parententryid) {
$wastebasketStore = $store;
$wastebasketEntryid = $msgprops[PR_IPM_WASTEBASKET_ENTRYID];
}
break;
case ZARAFA_STORE_DELEGATE_GUID:
// Mirror Operations::deleteMessages: hard delete in the
// wastebasket or with default soft delete, otherwise the
// style setting selects the wastebasket.
$softDefault = defined('ENABLE_DEFAULT_SOFT_DELETE') ? ENABLE_DEFAULT_SOFT_DELETE : false;
if ($softDefault || (isset($msgprops[PR_IPM_WASTEBASKET_ENTRYID]) && $msgprops[PR_IPM_WASTEBASKET_ENTRYID] == $parententryid)) {
break;
}
$delegateWastebasketStyle = $GLOBALS['settings']->get('grommunio/v1/contexts/mail/delegate_wastebasket_style', DELEGATE_WASTEBASKET_MAINUSER);
$targetStore = $store;
$targetProps = $msgprops;
if ($delegateWastebasketStyle === DELEGATE_WASTEBASKET_MAINUSER) {
$targetStore = $GLOBALS["mapisession"]->getDefaultMessageStore();
$targetProps = mapi_getprops($targetStore, [PR_IPM_WASTEBASKET_ENTRYID]);
}
if (isset($targetProps[PR_IPM_WASTEBASKET_ENTRYID]) && $targetProps[PR_IPM_WASTEBASKET_ENTRYID] != $parententryid) {
$wastebasketStore = $targetStore;
$wastebasketEntryid = $targetProps[PR_IPM_WASTEBASKET_ENTRYID];
}
break;
}
if ($wastebasketEntryid === false) {
return null;
}
$searchKeys = $GLOBALS["operations"]->getMessageSearchKeys($store, $entryid);
if (empty($searchKeys)) {
return null;
}
return [
'store' => $wastebasketStore,
'entryid' => $wastebasketEntryid,
'searchKeys' => $searchKeys,
'existing' => $GLOBALS["operations"]->getFolderEntryidsBySearchKey($wastebasketStore, $wastebasketEntryid, $searchKeys),
];
}
/**
* Build the 'undo' feedback object for a completed delete from the snapshot
* taken by prepareDeleteUndo(). Any failure while resolving the new
* location is swallowed so the (already completed) delete is still reported
* as successful.
*
* @param null|array $undoInfo the snapshot returned by prepareDeleteUndo(),
* or null when the delete was not trackable
*
* @return array the feedback array, possibly containing an 'undo' key
*/
protected function buildDeleteUndoFeedback($undoInfo) {
$feedback = [];
if (empty($undoInfo)) {
return $feedback;
}
try {
$newEntryids = $GLOBALS["operations"]->resolveNewEntryids($undoInfo['store'], $undoInfo['entryid'], $undoInfo['searchKeys'], $undoInfo['existing']);
if (!empty($newEntryids)) {
$wastebasketStoreProps = mapi_getprops($undoInfo['store'], [PR_ENTRYID]);
$feedback['undo'] = [
'new_entryids' => $newEntryids,
'destination_parent_entryid' => bin2hex((string) $undoInfo['entryid']),
'destination_store_entryid' => bin2hex((string) $wastebasketStoreProps[PR_ENTRYID]),
];
}
}
catch (MAPIException $e) {
$e->setHandled();
}
return $feedback;
}
/**
* Function which returns the entryid of a default folder.
*
* @param false|resource $store MAPI message store, or false when unavailable
* @param string $messageClass the class of the folder
*
* @return false|string entry ID of a default folder, or false if not found
*/
public function getDefaultFolderEntryID($store, $messageClass) {
$entryid = false;
if ($store !== false) {
$rootcontainer = mapi_msgstore_openentry($store);
$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]);
switch ($messageClass) {
case "IPM.Appointment":
if (isset($rootcontainerprops[PR_IPM_APPOINTMENT_ENTRYID])) {
$entryid = $rootcontainerprops[PR_IPM_APPOINTMENT_ENTRYID];
}
break;
case "IPM.Contact":
case "IPM.DistList":
if (isset($rootcontainerprops[PR_IPM_CONTACT_ENTRYID])) {
$entryid = $rootcontainerprops[PR_IPM_CONTACT_ENTRYID];
}
break;
case "IPM.StickyNote":
if (isset($rootcontainerprops[PR_IPM_NOTE_ENTRYID])) {
$entryid = $rootcontainerprops[PR_IPM_NOTE_ENTRYID];
}
break;
case "IPM.Task":
if (isset($rootcontainerprops[PR_IPM_TASK_ENTRYID])) {
$entryid = $rootcontainerprops[PR_IPM_TASK_ENTRYID];
}
break;
default:
if (isset($rootcontainerprops[PR_IPM_DRAFTS_ENTRYID])) {
$entryid = $rootcontainerprops[PR_IPM_DRAFTS_ENTRYID];
}
break;
}
}
return $entryid;
}
/**
* Function which copies or moves one or more items.
*
* @param false|resource $store MAPI message store, or false when it was not resolved
* @param string $parententryid entryid of the folder
* @param mixed $entryids list of entryids which will be copied or moved (in binary format)
* @param array $action the action data, sent by the client
*/
public function copy($store, $parententryid, $entryids, $action) {
if ($store !== false && $parententryid && $entryids) {
$destinationParentEntryid = $action["message_action"]["destination_parent_entryid"] ?? null;
if (!is_hex_entryid($destinationParentEntryid)) {
$this->sendFeedback(false);
return;
}
$dest_folderentryid = hex2bin($destinationParentEntryid);
$dest_store = $store;
if (isset($action["message_action"]["destination_store_entryid"])) {
$destinationStoreEntryid = $action["message_action"]["destination_store_entryid"];
if (!is_hex_entryid($destinationStoreEntryid)) {
$this->sendFeedback(false);
return;
}
$dest_storeentryid = hex2bin($destinationStoreEntryid);
$dest_store = $GLOBALS["mapisession"]->openMessageStore($dest_storeentryid);
}
if (!$dest_store) {
$this->sendFeedback(false);
return;
}
$destStoreProps = mapi_getprops($dest_store, [PR_ENTRYID]);
if (!isset($destStoreProps[PR_ENTRYID])) {
$this->sendFeedback(false);
return;
}
$dest_storeentryid = $destStoreProps[PR_ENTRYID];
$moveMessages = false;
$actionType = $action["message_action"]["action_type"] ?? null;
if ($actionType == "move") {
$moveMessages = true;
}
// if item has some set of props that need to be saved into the newly copied/moved item
$copyProps = [];
if (isset($action["message_action"]["dropmodifications"])) {
$copyProps = Conversion::mapXML2MAPI($this->properties, $action["message_action"]["dropmodifications"]);
}
// if item has some changes made before choosing different calendar from create-in dropdown
if (!empty($action["props"])) {
$copyProps = Conversion::mapXML2MAPI($this->properties, $action["props"]);
}
$props = [];
$props[PR_PARENT_ENTRYID] = $parententryid;
$props[PR_ENTRYID] = $entryids;
$storeprops = mapi_getprops($store, [PR_ENTRYID]);
$props[PR_STORE_ENTRYID] = $storeprops[PR_ENTRYID];
$skipCopyProperties = [];
if (isset($action["message_action"]["unset_Private"])) {
if ($moveMessages) {
array_push($skipCopyProperties, $this->properties["private"], $this->properties["sensitivity"]);
}
else {
array_push($this->skipCopyProperties, $this->properties["private"], $this->properties["sensitivity"]);
}
}
// When the client asked to track the new entryids (undo support),
// remember the move-stable search keys before the operation so the
// items can be relocated in the destination folder afterwards, plus
// the items already present in the destination sharing those keys so
// they are not mistaken for the freshly copied/moved items.
$searchKeys = [];
$existingEntryids = [];
if ($actionType !== "copyToNote" && !empty($action["message_action"]["track_new_entryids"])) {
$searchKeys = $GLOBALS["operations"]->getMessageSearchKeys($store, $entryids);
$existingEntryids = $GLOBALS["operations"]->getFolderEntryidsBySearchKey($dest_store, $dest_folderentryid, $searchKeys);
}
if ($actionType === "copyToNote") {
$result = $GLOBALS["operations"]->copyMessagesToNotes($store, $dest_store, $dest_folderentryid, $entryids);
}
else {
$result = $GLOBALS["operations"]->copyMessages($store, $parententryid, $dest_store, $dest_folderentryid, $entryids, $moveMessages ? $skipCopyProperties : $this->skipCopyProperties, $moveMessages, $copyProps);
}
if ($result) {
if ($moveMessages) {
$GLOBALS["bus"]->notify(bin2hex($parententryid), TABLE_DELETE, $props);
}
// Delete the PR_ENTRYID, the copied or moved message has a new entryid,
// and at this time we have no idea what that might be. So make sure
// we unset it, otherwise the notification handlers get weird ideas
// and could reset the PR_PARENT_ENTRYID to the old folder again.
unset($props[PR_ENTRYID]);
$props[PR_PARENT_ENTRYID] = $dest_folderentryid;
$props[PR_STORE_ENTRYID] = $dest_storeentryid;
$GLOBALS["bus"]->notify(bin2hex($dest_folderentryid), TABLE_SAVE, $props);
}
$feedback = [];
if ($result && !empty($searchKeys)) {
// Best-effort: a failure resolving the new location must not
// turn the already completed copy/move into an error.
try {
$newEntryids = $GLOBALS["operations"]->resolveNewEntryids($dest_store, $dest_folderentryid, $searchKeys, $existingEntryids);
if (!empty($newEntryids)) {
$feedback['undo'] = [
'new_entryids' => $newEntryids,
'destination_parent_entryid' => bin2hex($dest_folderentryid),
'destination_store_entryid' => bin2hex($dest_storeentryid),
];
}
}
catch (MAPIException $e) {
$e->setHandled();
}
}
$this->sendFeedback($result, $feedback);
}
}
/**
* Function returns correspondent calendar item's properties attached
* with the meeting request/response/cancellation.
*
* @param Meetingrequest $meetingRequestObject the meeting request object
* using which function will fetch meeting request properties and return them
*/
public function getCalendarItemProps($meetingRequestObject) {
$calendarItem = $meetingRequestObject->getCorrespondentCalendarItem();
$props = [];
if ($calendarItem !== false) {
$calendarItemProps = mapi_getprops($calendarItem, [PR_STORE_ENTRYID, PR_PARENT_ENTRYID, PR_ENTRYID, $meetingRequestObject->proptags['updatecounter'], $meetingRequestObject->proptags['goid']]);
// Store calendar item's necessary properties in props array.
$props['appointment_store_entryid'] = bin2hex((string) $calendarItemProps[PR_STORE_ENTRYID]);
$props['appointment_parent_entryid'] = bin2hex((string) $calendarItemProps[PR_PARENT_ENTRYID]);
$props['appointment_entryid'] = bin2hex((string) $calendarItemProps[PR_ENTRYID]);
$props['appointment_updatecounter'] = $calendarItemProps[$meetingRequestObject->proptags['updatecounter']] ?? 0;
$messageProps = mapi_getprops($meetingRequestObject->message, [$meetingRequestObject->proptags['goid']]);
$basedate = $meetingRequestObject->getBasedateFromGlobalID($messageProps[$meetingRequestObject->proptags['goid']]);
if ($basedate !== false) {
$props['appointment_basedate'] = $basedate;
// if basedate is provided then it is exception, so get update counter of the exception
$exception = $meetingRequestObject->getExceptionItem($calendarItem, $basedate);
if ($exception !== false) {
// we are able to find the exception then get updatecounter
$exceptionProps = mapi_getprops($exception, [$meetingRequestObject->proptags['updatecounter']]);
$props['appointment_updatecounter'] = $exceptionProps[$meetingRequestObject->proptags['updatecounter']] ?? 0;
}
}
if ($meetingRequestObject->isMeetingRequestResponse()) {
$props['meeting_updated'] = $meetingRequestObject->isMeetingUpdated($basedate);
}
return $props;
}
return false;
}
/**
* Tells the calendar that a forward notification added attendees
* to the organizer's meeting.
*
* @param resource $store MAPI store of the forward notification
* @param Meetingrequest $req the forward notification
*/
private function notifyForwardedMeeting($store, $req) {
$goidProps = mapi_getprops($req->message, [$req->proptags['goid2']]);
if (empty($goidProps[$req->proptags['goid2']])) {
return;
}
foreach ($req->findCalendarItems($goidProps[$req->proptags['goid2']], false, true) ?? [] as $calItemEntryid) {
$calItem = mapi_msgstore_openentry($store, $calItemEntryid);
$calItemProps = mapi_getprops($calItem, [PR_ENTRYID, PR_PARENT_ENTRYID, PR_STORE_ENTRYID]);
$GLOBALS['bus']->notify(bin2hex((string) $calItemProps[PR_PARENT_ENTRYID]), TABLE_SAVE, $calItemProps);
}
}
/**
* Get a text body for a Non-Delivery report.
*
* This function reads the necessary properties from the passed message and constructs
* a user-readable NDR message from those properties
*
* @param resource $message NDR message to read
*
* @return string NDR body message as plaintext message
*/
public function getNDRbody($message) {
$message_props = mapi_getprops($message, [PR_ORIGINAL_SUBJECT, PR_ORIGINAL_SUBMIT_TIME, PR_BODY]);
// use PR_BODY if it's there, otherwise create a recipient failed message
$body = readMapiProp($message, PR_BODY, $message_props) ?? '';
if (empty($body)) {
$body = _("Your message did not reach some or all of the intended recipients") . "\n\n";
$body .= "\t" . _("Subject") . ": " . $message_props[PR_ORIGINAL_SUBJECT] . "\n";
$body .= "\t" . _("Sent") . ": " . date(DATE_RFC2822, $message_props[PR_ORIGINAL_SUBMIT_TIME]) . "\n\n";
$body .= _("The following recipient(s) could not be reached") . ":\n";
$recipienttable = mapi_message_getrecipienttable($message);
$recipientrows = mapi_table_queryallrows($recipienttable, [PR_DISPLAY_NAME, PR_REPORT_TIME, PR_REPORT_TEXT]);
foreach ($recipientrows as $recipient) {
$body .= "\n\t" . $recipient[PR_DISPLAY_NAME] . " on " . date(DATE_RFC2822, $recipient[PR_REPORT_TIME]) . "\n";
$body .= "\t\t" . $recipient[PR_REPORT_TEXT] . "\n";
}
}
return $body;
}
/**
* Send a meeting cancellation.
*
* This function sends a meeting cancellation for the meeting references by the passed entryid. It
* will send the meeting cancellation and move the item itself to the waste basket.
*
* @param resource $store store containing the meeting request
* @param string $entryid entryid of the appointment for which the cancellation should be sent
* @param object $action data sent by client
* @param bool $directBookingMeetingRequest Indicates if a Meeting Request should use direct booking or not
*/
public function cancelInvitation($store, $entryid, $action, $directBookingMeetingRequest) {
$message = $GLOBALS['operations']->openMessage($store, $entryid);
// @TODO move this to meeting request class ?
$req = new Meetingrequest($store, $message, $GLOBALS['mapisession']->getSession(), $directBookingMeetingRequest);
// Update extra body information
if (isset($action['message_action']['meetingTimeInfo']) && !empty($action['message_action']['meetingTimeInfo'])) {
$req->setMeetingTimeInfo($action["message_action"]['meetingTimeInfo'],
$action["message_action"]['mti_html'] ?? false);
unset($action["message_action"]['meetingTimeInfo']);
}
// get basedate from action data and pass to meeting request class
$basedate = !empty($action['basedate']) ? $action['basedate'] : false;
$req->doCancelInvitation($basedate);
if ($basedate !== false) {
// if basedate is specified then we have created exception in recurring meeting request
// so send notification of creation of exception
$messageProps = mapi_getprops($message, [PR_ENTRYID, PR_STORE_ENTRYID, PR_PARENT_ENTRYID]);
$GLOBALS["bus"]->notify(bin2hex((string) $messageProps[PR_PARENT_ENTRYID]), TABLE_SAVE, $messageProps);
}
else {
// for normal/recurring meetings send delete notification
$messageProps = mapi_getprops($message, [PR_ENTRYID, PR_STORE_ENTRYID, PR_PARENT_ENTRYID]);
$GLOBALS["bus"]->notify(bin2hex((string) $messageProps[PR_PARENT_ENTRYID]), TABLE_DELETE, $messageProps);
}
}
/**
* Remove all appointments for a certain meeting request.
*
* This function searches the default calendar for all meeting requests for the specified
* meeting. All those appointments are then removed.
*
* @param resource $store MAPI store containing the meeting request and calendar
* @param string $entryid Entryid of the meeting request or appointment for which all items should be deleted
* @param false|string $basedate if specified contains starttime of day of an occurrence
* @param bool $directBookingMeetingRequest Indicates if a Meeting Request should use direct booking or not
*/
public function removeFromCalendar($store, $entryid, $basedate, $directBookingMeetingRequest) {
$message = $GLOBALS["operations"]->openMessage($store, $entryid);
$req = new Meetingrequest($store, $message, $GLOBALS["mapisession"]->getSession(), $directBookingMeetingRequest);
$req->doRemoveFromCalendar($basedate);
// Notify the bus that the message has been deleted
$messageProps = mapi_getprops($message, [PR_ENTRYID, PR_STORE_ENTRYID, PR_PARENT_ENTRYID]);
$GLOBALS["bus"]->notify(bin2hex((string) $messageProps[PR_PARENT_ENTRYID]), $basedate ? TABLE_SAVE : TABLE_DELETE, $messageProps);
}
/**
* Remove attachments from a message which is already stored.
*
* The numbers are deleted from the highest down, because deleting an attachment
* renumbers the ones behind it.
*
* @param resource $store MAPI store of the message
* @param string $entryid entryid of the message
* @param array $action action data from the client
*/
public function removeAttachments($store, $entryid, $action) {
if (!ENABLE_ATTACHMENT_REMOVAL) {
$this->sendFeedback(false, [
'type' => ERROR_GENERAL,
'info' => [
'display_message' => _('Removing attachments has been disabled by the administrator.'),
],
]);
return;
}
$numbers = $action['message_action']['attach_num'] ?? [];
$numbers = array_filter(array_map('intval', (array) $numbers), fn ($number) => $number >= 0);
$message = $GLOBALS['operations']->openMessage($store, $entryid);
if (empty($message) || empty($numbers)) {
$this->sendFeedback(false);
return;
}
rsort($numbers);
foreach ($numbers as $number) {
mapi_message_deleteattach($message, $number);
}
mapi_savechanges($message);
$messageProps = mapi_getprops($message, [PR_ENTRYID, PR_STORE_ENTRYID, PR_PARENT_ENTRYID]);
$GLOBALS['bus']->notify(bin2hex((string) $messageProps[PR_PARENT_ENTRYID]), TABLE_SAVE, $messageProps);
$data = $GLOBALS['operations']->getMessageProps($store, $message, $this->properties, $this->plaintext, true);
$data['attachments'] = ['item' => $GLOBALS['operations']->getAttachmentsInfo($message)];
$this->addActionData('update', ['item' => $data]);
$GLOBALS['bus']->addData($this->getResponseData());
}
/**
* Forward a meeting request to additional recipients.
*
* Creates a new IPM.Schedule.Meeting.Request message addressed to the
* specified recipients and sends a forward notification to the organizer.
*
* @param resource $store MAPI store of the appointment
* @param string $entryid entryid of the appointment to forward
* @param array $action action data from the client
* @param bool $directBookingMeetingRequest direct-booking flag
*/
public function forwardMeetingRequest($store, $entryid, $action, $directBookingMeetingRequest) {
if ((new MeetingRequestForwarder())->forward($store, $entryid, $action)) {
$this->sendFeedback(true);
}
}
}