function _getAppointment($mapimessage, $truncsize, $mimesupport = 0) { $message = new SyncAppointment(); // Standard one-to-one mappings first $this->_getPropsFromMAPI($message, $mapimessage, $this->_appointmentmapping); // Disable reminder if it is off $reminderset = $this->_getPropIDFromString("PT_BOOLEAN:{00062008-0000-0000-C000-000000000046}:0x8503"); $remindertime = $this->_getPropIDFromString("PT_LONG:{00062008-0000-0000-C000-000000000046}:0x8501"); $messageprops = mapi_getprops($mapimessage, array($reminderset, $remindertime)); if (!isset($messageprops[$reminderset]) || $messageprops[$reminderset] == false) { $message->reminder = ""; } else { if ($messageprops[$remindertime] == 0x5ae980e1) { $message->reminder = 15; } else { $message->reminder = $messageprops[$remindertime]; } } $messageprops = mapi_getprops($mapimessage, array(PR_SOURCE_KEY)); if (!isset($message->uid)) { $message->uid = bin2hex($messageprops[PR_SOURCE_KEY]); } else { $message->uid = getICalUidFromOLUid($message->uid); } // Get organizer information if it is a meetingrequest $meetingstatustag = $this->_getPropIDFromString("PT_LONG:{00062002-0000-0000-C000-000000000046}:0x8217"); $messageprops = mapi_getprops($mapimessage, array($meetingstatustag, PR_SENT_REPRESENTING_ENTRYID, PR_SENT_REPRESENTING_NAME)); if (isset($messageprops[$meetingstatustag]) && $messageprops[$meetingstatustag] > 0 && isset($messageprops[PR_SENT_REPRESENTING_ENTRYID]) && isset($messageprops[PR_SENT_REPRESENTING_NAME])) { $message->organizeremail = w2u($this->_getSMTPAddressFromEntryID($messageprops[PR_SENT_REPRESENTING_ENTRYID])); $message->organizername = w2u($messageprops[PR_SENT_REPRESENTING_NAME]); } $isrecurringtag = $this->_getPropIDFromString("PT_BOOLEAN:{00062002-0000-0000-C000-000000000046}:0x8223"); $recurringstate = $this->_getPropIDFromString("PT_BINARY:{00062002-0000-0000-C000-000000000046}:0x8216"); $timezonetag = $this->_getPropIDFromString("PT_BINARY:{00062002-0000-0000-C000-000000000046}:0x8233"); $recurrenceend = $this->_getPropIDFromString("PT_SYSTIME:{00062002-0000-0000-C000-000000000046}:0x8236"); // Now, get and convert the recurrence and timezone information $recurprops = mapi_getprops($mapimessage, array($isrecurringtag, $recurringstate, $timezonetag, $recurrenceend)); if (isset($recurprops[$timezonetag])) { $tz = $this->_getTZFromMAPIBlob($recurprops[$timezonetag]); } else { $tz = $this->_getGMTTZ(); } $message->timezone = base64_encode($this->_getSyncBlobFromTZ($tz)); if (isset($recurprops[$isrecurringtag]) && $recurprops[$isrecurringtag]) { // Process recurrence $message->recurrence = new SyncRecurrence(); $this->_getRecurrence($mapimessage, $recurprops, $message, $message->recurrence, $tz); } // Do attendees $reciptable = mapi_message_getrecipienttable($mapimessage); $rows = mapi_table_queryallrows($reciptable, array(PR_DISPLAY_NAME, PR_EMAIL_ADDRESS, PR_SMTP_ADDRESS, PR_ADDRTYPE)); if (count($rows) > 0) { $message->attendees = array(); } foreach ($rows as $row) { $attendee = new SyncAttendee(); $attendee->name = w2u($row[PR_DISPLAY_NAME]); //smtp address is always a proper email address if (isset($row[PR_SMTP_ADDRESS])) { $attendee->email = w2u($row[PR_SMTP_ADDRESS]); } elseif (isset($row[PR_ADDRTYPE]) && isset($row[PR_EMAIL_ADDRESS])) { //if address type is SMTP, it's also a proper email address if ($row[PR_ADDRTYPE] == "SMTP") { $attendee->email = w2u($row[PR_EMAIL_ADDRESS]); } elseif ($row[PR_ADDRTYPE] == "ZARAFA") { $userinfo = mapi_zarafa_getuser_by_name($this->_store, $row[PR_EMAIL_ADDRESS]); if (is_array($userinfo) && isset($userinfo["emailaddress"])) { $attendee->email = w2u($userinfo["emailaddress"]); } } } // Some attendees have no email or name (eg resources), and if you // don't send one of those fields, the phone will give an error ... so // we don't send it in that case. // also ignore the "attendee" if the email is equal to the organizers' email if (isset($attendee->name) && isset($attendee->email) && $attendee->email != "" && (!isset($message->organizeremail) || isset($message->organizeremail) && $attendee->email != $message->organizeremail)) { array_push($message->attendees, $attendee); } } // Force the 'alldayevent' in the object at all times. (non-existent == 0) if (!isset($message->alldayevent) || $message->alldayevent == "") { $message->alldayevent = 0; } return $message; }
function _getAppointment($mapimessage, $truncsize, $mimesupport = 0) { $message = new SyncAppointment(); // Standard one-to-one mappings first $this->_getPropsFromMAPI($message, $mapimessage, $this->_appointmentmapping); // Disable reminder if it is off $reminderset = $this->_getPropIDFromString("PT_BOOLEAN:{00062008-0000-0000-C000-000000000046}:0x8503"); $remindertime = $this->_getPropIDFromString("PT_LONG:{00062008-0000-0000-C000-000000000046}:0x8501"); $messageprops = mapi_getprops($mapimessage, array($reminderset, $remindertime)); if (!isset($messageprops[$reminderset]) || $messageprops[$reminderset] == false) { $message->reminder = ""; } else { if ($messageprops[$remindertime] == 0x5ae980e1) { $message->reminder = 15; } else { $message->reminder = $messageprops[$remindertime]; } } $messageprops = mapi_getprops($mapimessage, array(PR_SOURCE_KEY)); if (!isset($message->uid)) { $message->uid = bin2hex($messageprops[PR_SOURCE_KEY]); } else { $message->uid = getICalUidFromOLUid($message->uid); } $isrecurringtag = $this->_getPropIDFromString("PT_BOOLEAN:{00062002-0000-0000-C000-000000000046}:0x8223"); $recurringstate = $this->_getPropIDFromString("PT_BINARY:{00062002-0000-0000-C000-000000000046}:0x8216"); $timezonetag = $this->_getPropIDFromString("PT_BINARY:{00062002-0000-0000-C000-000000000046}:0x8233"); // Now, get and convert the recurrence and timezone information $recurprops = mapi_getprops($mapimessage, array($isrecurringtag, $recurringstate, $timezonetag)); if (isset($recurprops[$timezonetag])) { $tz = $this->_getTZFromMAPIBlob($recurprops[$timezonetag]); } else { $tz = $this->_getGMTTZ(); } if (isset($recurprops[$isrecurringtag]) && $recurprops[$isrecurringtag]) { // Process recurrence $recurrence = new Recurrence($this->_store, $recurprops); $message->recurrence = new SyncRecurrence(); switch ($recurrence->recur["type"]) { case 10: // daily switch ($recurrence->recur["subtype"]) { default: $message->recurrence->type = 0; break; case 1: $message->recurrence->type = 0; $message->recurrence->dayofweek = 62; // mon-fri break; } break; case 11: // weekly $message->recurrence->type = 1; break; case 12: // monthly switch ($recurrence->recur["subtype"]) { default: $message->recurrence->type = 2; break; case 3: $message->recurrence->type = 3; break; } break; case 13: // yearly switch ($recurrence->recur["subtype"]) { default: $message->recurrence->type = 4; break; case 2: $message->recurrence->type = 5; break; case 3: $message->recurrence->type = 6; } } // Termination switch ($recurrence->recur["term"]) { case 0x21: $message->recurrence->until = $recurrence->recur["end"]; break; case 0x22: $message->recurrence->occurrences = $recurrence->recur["numoccur"]; break; case 0x23: // never ends break; } // Correct 'alldayevent' because outlook fails to set it on recurring items of 24 hours or longer if ($recurrence->recur["endocc"] - $recurrence->recur["startocc"] >= 1440) { $message->alldayevent = true; } // Interval is different according to the type/subtype switch ($recurrence->recur["type"]) { case 10: if ($recurrence->recur["subtype"] == 0) { $message->recurrence->interval = (int) ($recurrence->recur["everyn"] / 1440); } // minutes break; case 11: case 12: $message->recurrence->interval = $recurrence->recur["everyn"]; break; // months / weeks // months / weeks case 13: $message->recurrence->interval = (int) ($recurrence->recur["everyn"] / 12); break; // months } if (isset($recurrence->recur["weekdays"])) { $message->recurrence->dayofweek = $recurrence->recur["weekdays"]; } // bitmask of days (1 == sunday, 128 == saturday if (isset($recurrence->recur["nday"])) { $message->recurrence->weekofmonth = $recurrence->recur["nday"]; } // N'th {DAY} of {X} (0-5) if (isset($recurrence->recur["month"])) { $message->recurrence->monthofyear = (int) ($recurrence->recur["month"] / (60 * 24 * 29)) + 1; } // works ok due to rounding. see also $monthminutes below (1-12) if (isset($recurrence->recur["monthday"])) { $message->recurrence->dayofmonth = $recurrence->recur["monthday"]; } // day of month (1-31) // All changed exceptions are appointments within the 'exceptions' array. They contain the same items as a normal appointment foreach ($recurrence->recur["changed_occurences"] as $change) { $exception = new SyncAppointment(); // start, end, basedate, subject, remind_before, reminderset, location, busystatus, alldayevent, label if (isset($change["start"])) { $exception->starttime = $this->_getGMTTimeByTZ($change["start"], $tz); } if (isset($change["end"])) { $exception->endtime = $this->_getGMTTimeByTZ($change["end"], $tz); } if (isset($change["basedate"])) { $exception->exceptionstarttime = $this->_getGMTTimeByTZ($this->_getDayStartOfTimestamp($change["basedate"]) + $recurrence->recur["startocc"] * 60, $tz); } if (isset($change["subject"])) { $exception->subject = w2u($change["subject"]); } if (isset($change["reminder_before"]) && $change["reminder_before"]) { $exception->reminder = $change["remind_before"]; } if (isset($change["location"])) { $exception->location = w2u($change["location"]); } if (isset($change["busystatus"])) { $exception->busystatus = $change["busystatus"]; } if (isset($change["alldayevent"])) { $exception->alldayevent = $change["alldayevent"]; } if (!isset($message->exceptions)) { $message->exceptions = array(); } array_push($message->exceptions, $exception); } // Deleted appointments contain only the original date (basedate) and a 'deleted' tag foreach ($recurrence->recur["deleted_occurences"] as $deleted) { $exception = new SyncAppointment(); $exception->exceptionstarttime = $this->_getGMTTimeByTZ($this->_getDayStartOfTimestamp($deleted) + $recurrence->recur["startocc"] * 60, $tz); $exception->deleted = "1"; if (!isset($message->exceptions)) { $message->exceptions = array(); } array_push($message->exceptions, $exception); } } if ($tz) { $message->timezone = base64_encode($this->_getSyncBlobFromTZ($tz)); } // Get organizer information if it is a meetingrequest $meetingstatustag = $this->_getPropIDFromString("PT_LONG:{00062002-0000-0000-C000-000000000046}:0x8217"); $messageprops = mapi_getprops($mapimessage, array($meetingstatustag, PR_SENT_REPRESENTING_ENTRYID, PR_SENT_REPRESENTING_NAME)); if (isset($messageprops[$meetingstatustag]) && $messageprops[$meetingstatustag] > 0 && isset($messageprops[PR_SENT_REPRESENTING_ENTRYID]) && isset($messageprops[PR_SENT_REPRESENTING_NAME])) { $message->organizeremail = w2u($this->_getSMTPAddressFromEntryID($messageprops[PR_SENT_REPRESENTING_ENTRYID])); $message->organizername = w2u($messageprops[PR_SENT_REPRESENTING_NAME]); } // Do attendees $reciptable = mapi_message_getrecipienttable($mapimessage); $rows = mapi_table_queryallrows($reciptable, array(PR_DISPLAY_NAME, PR_EMAIL_ADDRESS, PR_SMTP_ADDRESS, PR_ADDRTYPE)); if (count($rows) > 0) { $message->attendees = array(); } foreach ($rows as $row) { $attendee = new SyncAttendee(); $attendee->name = w2u($row[PR_DISPLAY_NAME]); //smtp address is always a proper email address if (isset($row[PR_SMTP_ADDRESS])) { $attendee->email = w2u($row[PR_SMTP_ADDRESS]); } elseif (isset($row[PR_ADDRTYPE]) && isset($row[PR_EMAIL_ADDRESS])) { //if address type is SMTP, it's also a proper email address if ($row[PR_ADDRTYPE] == "SMTP") { $attendee->email = w2u($row[PR_EMAIL_ADDRESS]); } elseif ($row[PR_ADDRTYPE] == "ZARAFA") { $userinfo = mapi_zarafa_getuser_by_name($this->_store, $row[PR_EMAIL_ADDRESS]); if (is_array($userinfo) && isset($userinfo["emailaddress"])) { $attendee->email = w2u($userinfo["emailaddress"]); } } } // Some attendees have no email or name (eg resources), and if you // don't send one of those fields, the phone will give an error ... so // we don't send it in that case. // also ignore the "attendee" if the email is equal to the organizers' email if (isset($attendee->name) && isset($attendee->email) && (!isset($message->organizeremail) || isset($message->organizeremail) && $attendee->email != $message->organizeremail)) { array_push($message->attendees, $attendee); } } // Force the 'alldayevent' in the object at all times. (non-existent == 0) if (!isset($message->alldayevent) || $message->alldayevent == "") { $message->alldayevent = 0; } return $message; }