/** * Processes a response to a meeting request. * CalendarID is a reference and has to be set if a new calendar item is created * * @param string $requestid id of the object containing the request * @param string $folderid id of the parent folder of $requestid * @param string $response * * @access public * @return string id of the created/updated calendar obj * @throws StatusException */ public function MeetingResponse($requestid, $folderid, $response) { // Use standard meeting response code to process meeting request $reqentryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($folderid), hex2bin($requestid)); if (!$reqentryid) { throw new StatusException(sprintf("BackendZarafa->MeetingResponse('%s', '%s', '%s'): Error, unable to entryid of the message 0x%X", $requestid, $folderid, $response, mapi_last_hresult()), SYNC_MEETRESPSTATUS_INVALIDMEETREQ); } $mapimessage = mapi_msgstore_openentry($this->store, $reqentryid); if (!$mapimessage) { throw new StatusException(sprintf("BackendZarafa->MeetingResponse('%s','%s', '%s'): Error, unable to open request message for response 0x%X", $requestid, $folderid, $response, mapi_last_hresult()), SYNC_MEETRESPSTATUS_INVALIDMEETREQ); } $meetingrequest = new Meetingrequest($this->store, $mapimessage); if (!$meetingrequest->isMeetingRequest()) { throw new StatusException(sprintf("BackendZarafa->MeetingResponse('%s','%s', '%s'): Error, attempt to respond to non-meeting request", $requestid, $folderid, $response), SYNC_MEETRESPSTATUS_INVALIDMEETREQ); } if ($meetingrequest->isLocalOrganiser()) { throw new StatusException(sprintf("BackendZarafa->MeetingResponse('%s','%s', '%s'): Error, attempt to response to meeting request that we organized", $requestid, $folderid, $response), SYNC_MEETRESPSTATUS_INVALIDMEETREQ); } // Process the meeting response. We don't have to send the actual meeting response // e-mail, because the device will send it itself. switch ($response) { case 1: // accept // accept default: $entryid = $meetingrequest->doAccept(false, false, false, false, false, false, true); // last true is the $userAction break; case 2: // tentative $entryid = $meetingrequest->doAccept(true, false, false, false, false, false, true); // last true is the $userAction break; case 3: // decline $meetingrequest->doDecline(false); break; } // F/B will be updated on logoff // We have to return the ID of the new calendar item, so do that here $calendarid = ""; if (isset($entryid)) { $newitem = mapi_msgstore_openentry($this->store, $entryid); $newprops = mapi_getprops($newitem, array(PR_SOURCE_KEY)); $calendarid = bin2hex($newprops[PR_SOURCE_KEY]); } // on recurring items, the MeetingRequest class responds with a wrong entryid if ($requestid == $calendarid) { ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendZarafa->MeetingResponse('%s','%s', '%s'): returned calender id is the same as the requestid - re-searching", $requestid, $folderid, $response)); $props = MAPIMapping::GetMeetingRequestProperties(); $props = getPropIdsFromStrings($this->store, $props); $messageprops = mapi_getprops($mapimessage, array($props["goidtag"])); $goid = $messageprops[$props["goidtag"]]; $items = $meetingrequest->findCalendarItems($goid); if (is_array($items)) { $newitem = mapi_msgstore_openentry($this->store, $items[0]); $newprops = mapi_getprops($newitem, array(PR_SOURCE_KEY)); $calendarid = bin2hex($newprops[PR_SOURCE_KEY]); ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendZarafa->MeetingResponse('%s','%s', '%s'): found other calendar entryid", $requestid, $folderid, $response)); } if ($requestid == $calendarid) { throw new StatusException(sprintf("BackendZarafa->MeetingResponse('%s','%s', '%s'): Error finding the accepted meeting response in the calendar", $requestid, $folderid, $response), SYNC_MEETRESPSTATUS_INVALIDMEETREQ); } } // delete meeting request from Inbox $folderentryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($folderid)); $folder = mapi_msgstore_openentry($this->store, $folderentryid); mapi_folder_deletemessages($folder, array($reqentryid), 0); return $calendarid; }
function MeetingResponse($requestid, $folderid, $response, &$calendarid) { // Use standard meeting response code to process meeting request $reqentryid = mapi_msgstore_entryidfromsourcekey($this->_defaultstore, hex2bin($folderid), hex2bin($requestid)); $mapimessage = mapi_msgstore_openentry($this->_defaultstore, $reqentryid); if (!$mapimessage) { debugLog("Unable to open request message for response"); return false; } $meetingrequest = new Meetingrequest($this->_defaultstore, $mapimessage); if (!$meetingrequest->isMeetingRequest()) { debugLog("Attempt to respond to non-meeting request"); return false; } if ($meetingrequest->isLocalOrganiser()) { debugLog("Attempt to response to meeting request that we organized"); return false; } // Process the meeting response. We don't have to send the actual meeting response // e-mail, because the device will send it itself. switch ($response) { case 1: // accept // accept default: $entryid = $meetingrequest->doAccept(false, false, false, false, false, false, true); // last true is the $userAction break; case 2: // tentative $entryid = $meetingrequest->doAccept(true, false, false, false, false, false, true); // last true is the $userAction break; case 3: // decline $meetingrequest->doDecline(false); break; } // F/B will be updated on logoff // We have to return the ID of the new calendar item, so do that here if (isset($entryid)) { $newitem = mapi_msgstore_openentry($this->_defaultstore, $entryid); $newprops = mapi_getprops($newitem, array(PR_SOURCE_KEY)); $calendarid = bin2hex($newprops[PR_SOURCE_KEY]); } // on recurring items, the MeetingRequest class responds with a wrong entryid if ($requestid == $calendarid) { debugLog("returned calender id is the same as the requestid - re-searching"); $goidprop = GetPropIDFromString($this->_defaultstore, "PT_BINARY:{6ED8DA90-450B-101B-98DA-00AA003F1305}:0x3"); $messageprops = mapi_getprops($mapimessage, array($goidprop, PR_OWNER_APPT_ID)); $goid = $messageprops[$goidprop]; if (isset($messageprops[PR_OWNER_APPT_ID])) { $apptid = $messageprops[PR_OWNER_APPT_ID]; } else { $apptid = false; } //findCalendarItems signature was changed in 6.40.8, Mantis #485 $items = checkMapiExtVersion("6.40.8") ? $meetingrequest->findCalendarItems($goid) : $meetingrequest->findCalendarItems($goid, $apptid); if (is_array($items)) { $newitem = mapi_msgstore_openentry($this->_defaultstore, $items[0]); $newprops = mapi_getprops($newitem, array(PR_SOURCE_KEY)); $calendarid = bin2hex($newprops[PR_SOURCE_KEY]); debugLog("found other calendar entryid"); } } // delete meeting request from Inbox $folderentryid = mapi_msgstore_entryidfromsourcekey($this->_defaultstore, hex2bin($folderid)); $folder = mapi_msgstore_openentry($this->_defaultstore, $folderentryid); mapi_folder_deletemessages($folder, array($reqentryid), 0); return true; }
function MeetingResponse($requestid, $folderid, $response, &$calendarid) { // Use standard meeting response code to process meeting request $entryid = mapi_msgstore_entryidfromsourcekey($this->_defaultstore, hex2bin($folderid), hex2bin($requestid)); $mapimessage = mapi_msgstore_openentry($this->_defaultstore, $entryid); if (!$mapimessage) { debugLog("Unable to open request message for response"); return false; } $meetingrequest = new Meetingrequest($this->_defaultstore, $mapimessage); if (!$meetingrequest->isMeetingRequest()) { debugLog("Attempt to respond to non-meeting request"); return false; } if ($meetingrequest->isLocalOrganiser()) { debugLog("Attempt to response to meeting request that we organized"); return false; } // Process the meeting response. We don't have to send the actual meeting response // e-mail, because the device will send it itself. switch ($response) { case 1: // accept // accept default: $entryid = $meetingrequest->doAccept(false, false, $meetingrequest->isInCalendar()); break; case 2: // tentative $meetingrequest->doAccept(true, false, $meetingrequest->isInCalendar()); break; case 3: // decline $meetingrequest->doDecline(false); break; } // Update F/B $root = mapi_msgstore_openentry($this->_defaultstore); $rootprops = mapi_getprops($root, array(PR_IPM_APPOINTMENT_ENTRYID)); $calendar = mapi_msgstore_openentry($this->_defaultstore, $rootprops[PR_IPM_APPOINTMENT_ENTRYID]); $storeprops = mapi_getprops($this->_defaultstore, array(PR_USER_ENTRYID)); $pub = new FreeBusyPublish($this->_session, $this->_defaultstore, $calendar, $storeprops[PR_USER_ENTRYID]); $pub->publishFB(time() - 7 * 24 * 60 * 60, 6 * 30 * 24 * 60 * 60); // publish from one week ago, 6 months ahead // We have to return the ID of the new calendar item, so do that here $newitem = mapi_msgstore_openentry($this->_defaultstore, $entryid); $newprops = mapi_getprops($newitem, array(PR_SOURCE_KEY)); $calendarid = bin2hex($newprops[PR_SOURCE_KEY]); return true; }
// Find the item by restricting all items to the correct ID $restrict = array(RES_AND, array(array(RES_PROPERTY, array(RELOP => RELOP_NE, ULPROPTAG => PR_PROCESSED, VALUE => array(PR_PROCESSED => true))), array(RES_CONTENT, array(FUZZYLEVEL => FL_PREFIX, ULPROPTAG => PR_MESSAGE_CLASS, VALUE => array(PR_SUBJECT => 'IPM.Schedule.Meeting'))), array(RES_BITMASK, array(ULTYPE => BMR_EQZ, ULMASK => MSGFLAG_READ, ULPROPTAG => PR_MESSAGE_FLAGS)))); // Just get all items from table $l_aRows = mapi_table_queryallrows($l_rInboxTable, array(PR_ENTRYID, PR_MESSAGE_CLASS, PR_SUBJECT, PR_PROCESSED), $restrict); echo 'Querying contents table result (0=success): ' . mapi_last_hresult() . "\n"; //print_r(count($l_aRows)); //exit; echo 'Processing messages' . "\n"; $l_iCounter = 0; for ($i = 0; $i < count($l_aRows); $i++) { $l_sMsgClassSearch = 'IPM.Schedule.Meeting'; $l_rMessage = mapi_msgstore_openentry($l_rDefaultStore, $l_aRows[$i][PR_ENTRYID]); $req = new Meetingrequest($l_rDefaultStore, $l_rMessage, $l_rSession); if ($req->isMeetingRequest() && !$req->isLocalOrganiser()) { // Put the item in the calendar 'tentatively' $req->doAccept(true, false, false); $l_iCounter++; } elseif ($req->isMeetingCancellation()) { // Let's do some processing of this Meeting Cancellation Object we received $req->processMeetingCancellation(); $l_iCounter++; } } echo 'Processed ' . $l_iCounter . ' ' . ($l_iCounter == 1 ? 'message' : 'messages') . "\n"; if ($l_iCounter > 0) { // Publish updated free/busy information publishFreeBusy($l_rDefaultStore, $l_rSession); echo 'Published FreeBusy information!' . "\n"; } } else { echo 'Inbox could not be opened!' . "\n";
function MeetingResponse($requestid, $folderid, $response, &$calendarid) { // Use standard meeting response code to process meeting request $reqentryid = mapi_msgstore_entryidfromsourcekey($this->_defaultstore, hex2bin($folderid), hex2bin($requestid)); $mapimessage = mapi_msgstore_openentry($this->_defaultstore, $reqentryid); if (!$mapimessage) { debugLog("Unable to open request message for response"); return false; } $meetingrequest = new Meetingrequest($this->_defaultstore, $mapimessage); if (!$meetingrequest->isMeetingRequest()) { debugLog("Attempt to respond to non-meeting request"); return false; } if ($meetingrequest->isLocalOrganiser()) { debugLog("Attempt to response to meeting request that we organized"); return false; } // Process the meeting response. We don't have to send the actual meeting response // e-mail, because the device will send it itself. switch ($response) { case 1: // accept // accept default: $entryid = $meetingrequest->doAccept(false, false, false, false, false, false, true); // last true is the $userAction break; case 2: // tentative $entryid = $meetingrequest->doAccept(true, false, false, false, false, false, true); // last true is the $userAction break; case 3: // decline $meetingrequest->doDecline(false); break; } // F/B will be updated on logoff // We have to return the ID of the new calendar item, so do that here $newitem = mapi_msgstore_openentry($this->_defaultstore, $entryid); $newprops = mapi_getprops($newitem, array(PR_SOURCE_KEY)); $calendarid = bin2hex($newprops[PR_SOURCE_KEY]); // delete meeting request from Inbox $folderentryid = mapi_msgstore_entryidfromsourcekey($this->_defaultstore, hex2bin($folderid)); $folder = mapi_msgstore_openentry($this->_defaultstore, $folderentryid); mapi_folder_deletemessages($folder, array($reqentryid), 0); return true; }
/** * Processes a response to a meeting request. * CalendarID is a reference and has to be set if a new calendar item is created * * @param string $requestid id of the object containing the request * @param string $folderid id of the parent folder of $requestid * @param string $response * * @access public * @return string id of the created/updated calendar obj * @throws StatusException */ public function MeetingResponse($requestid, $folderid, $response) { // Use standard meeting response code to process meeting request list($fid, $requestid) = Utils::SplitMessageId($requestid); $reqentryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($folderid), hex2bin($requestid)); if (!$reqentryid) { throw new StatusException(sprintf("BackendKopano->MeetingResponse('%s', '%s', '%s'): Error, unable to entryid of the message 0x%X", $requestid, $folderid, $response, mapi_last_hresult()), SYNC_MEETRESPSTATUS_INVALIDMEETREQ); } $mapimessage = mapi_msgstore_openentry($this->store, $reqentryid); if (!$mapimessage) { throw new StatusException(sprintf("BackendKopano->MeetingResponse('%s','%s', '%s'): Error, unable to open request message for response 0x%X", $requestid, $folderid, $response, mapi_last_hresult()), SYNC_MEETRESPSTATUS_INVALIDMEETREQ); } $meetingrequest = new Meetingrequest($this->store, $mapimessage, $this->session); if (!$meetingrequest->isMeetingRequest()) { throw new StatusException(sprintf("BackendKopano->MeetingResponse('%s','%s', '%s'): Error, attempt to respond to non-meeting request", $requestid, $folderid, $response), SYNC_MEETRESPSTATUS_INVALIDMEETREQ); } if ($meetingrequest->isLocalOrganiser()) { throw new StatusException(sprintf("BackendKopano->MeetingResponse('%s','%s', '%s'): Error, attempt to response to meeting request that we organized", $requestid, $folderid, $response), SYNC_MEETRESPSTATUS_INVALIDMEETREQ); } // Process the meeting response. We don't have to send the actual meeting response // e-mail, because the device will send it itself. switch ($response) { case 1: // accept // accept default: $entryid = $meetingrequest->doAccept(false, false, false, false, false, false, true); // last true is the $userAction break; case 2: // tentative $entryid = $meetingrequest->doAccept(true, false, false, false, false, false, true); // last true is the $userAction break; case 3: // decline $meetingrequest->doDecline(false); break; } // F/B will be updated on logoff // We have to return the ID of the new calendar item, so do that here $calendarid = ""; $calFolderId = ""; if (isset($entryid)) { $newitem = mapi_msgstore_openentry($this->store, $entryid); // new item might be in a delegator's store. ActiveSync does not support accepting them. if (!$newitem) { throw new StatusException(sprintf("BackendKopano->MeetingResponse('%s','%s', '%s'): Object with entryid '%s' was not found in user's store (0x%X). It might be in a delegator's store.", $requestid, $folderid, $response, bin2hex($entryid), mapi_last_hresult()), SYNC_MEETRESPSTATUS_SERVERERROR, null, LOGLEVEL_WARN); } $newprops = mapi_getprops($newitem, array(PR_SOURCE_KEY, PR_PARENT_SOURCE_KEY)); $calendarid = bin2hex($newprops[PR_SOURCE_KEY]); $calFolderId = bin2hex($newprops[PR_PARENT_SOURCE_KEY]); } // on recurring items, the MeetingRequest class responds with a wrong entryid if ($requestid == $calendarid) { ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendKopano->MeetingResponse('%s','%s', '%s'): returned calender id is the same as the requestid - re-searching", $requestid, $folderid, $response)); $props = MAPIMapping::GetMeetingRequestProperties(); $props = getPropIdsFromStrings($this->store, $props); $messageprops = mapi_getprops($mapimessage, array($props["goidtag"])); $goid = $messageprops[$props["goidtag"]]; $items = $meetingrequest->findCalendarItems($goid); if (is_array($items)) { $newitem = mapi_msgstore_openentry($this->store, $items[0]); $newprops = mapi_getprops($newitem, array(PR_SOURCE_KEY, PR_PARENT_SOURCE_KEY)); $calendarid = bin2hex($newprops[PR_SOURCE_KEY]); $calFolderId = bin2hex($newprops[PR_PARENT_SOURCE_KEY]); ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendKopano->MeetingResponse('%s','%s', '%s'): found other calendar entryid", $requestid, $folderid, $response)); } if ($requestid == $calendarid) { throw new StatusException(sprintf("BackendKopano->MeetingResponse('%s','%s', '%s'): Error finding the accepted meeting response in the calendar", $requestid, $folderid, $response), SYNC_MEETRESPSTATUS_INVALIDMEETREQ); } } // delete meeting request from Inbox $folderentryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($folderid)); $folder = mapi_msgstore_openentry($this->store, $folderentryid); mapi_folder_deletemessages($folder, array($reqentryid), 0); $prefix = ''; // prepend the short folderid of the target calendar: if available and short ids are used if ($calFolderId) { $shortFolderId = ZPush::GetDeviceManager()->GetFolderIdForBackendId($calFolderId); if ($calFolderId != $shortFolderId) { $prefix = $shortFolderId . ':'; } } return $prefix . $calendarid; }