Skip to content

Commit cfa1441

Browse files
committed
Merge branch 'issue134' into 'master'
Fix: editing appointment in android adds an attendee See merge request grommunio/grommunio-sync!98
2 parents 396ad6a + 23dd44a commit cfa1441

File tree

1 file changed

+45
-35
lines changed

1 file changed

+45
-35
lines changed

lib/grommunio/mapiprovider.php

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,6 +1414,7 @@ private function setAppointment($mapimessage, $appointment) {
14141414
$response = new SyncAppointmentResponse();
14151415

14161416
$isAllday = isset($appointment->alldayevent) && $appointment->alldayevent;
1417+
$isMeeting = isset($appointment->meetingstatus) && $appointment->meetingstatus > 0;
14171418
$isAs16 = Request::GetProtocolVersion() >= 16.0;
14181419

14191420
// Get timezone info
@@ -1728,15 +1729,20 @@ private function setAppointment($mapimessage, $appointment) {
17281729
$appointmentprops["sentrepresentingemail"], $appointmentprops["sentrepresentinsrchk"], $appointmentprops["responsestatus"], ];
17291730
$representingprops = $this->getProps($mapimessage, $p);
17301731

1732+
$storeProps = $this->GetStoreProps();
1733+
$abEntryProps = $this->getAbPropsFromEntryID($storeProps[PR_MAILBOX_OWNER_ENTRYID]);
17311734
if (!isset($representingprops[$appointmentprops["representingentryid"]])) {
1732-
// TODO use GetStoreProps
1733-
$storeProps = mapi_getprops($this->store, [PR_MAILBOX_OWNER_ENTRYID]);
1735+
$displayname = $sentrepresentingemail = Request::GetUser();
1736+
$sentrepresentingaddt = 'SMPT';
1737+
if ($abEntryProps !== false) {
1738+
$displayname = $abEntryProps[PR_DISPLAY_NAME] ?? $displayname;
1739+
$sentrepresentingemail = $abEntryProps[PR_EMAIL_ADDRESS] ?? $abEntryProps[PR_SMTP_ADDRESS] ?? $sentrepresentingemail;
1740+
$sentrepresentingaddt = $abEntryProps[PR_ADDRTYPE] ?? $sentrepresentingaddt;
1741+
}
17341742
$props[$appointmentprops["representingentryid"]] = $storeProps[PR_MAILBOX_OWNER_ENTRYID];
1735-
$displayname = $this->getFullnameFromEntryID($storeProps[PR_MAILBOX_OWNER_ENTRYID]);
1736-
1737-
$props[$appointmentprops["representingname"]] = ($displayname !== false) ? $displayname : Request::GetUser();
1738-
$props[$appointmentprops["sentrepresentingemail"]] = Request::GetUser();
1739-
$props[$appointmentprops["sentrepresentingaddt"]] = "ZARAFA";
1743+
$props[$appointmentprops["representingname"]] = $displayname;
1744+
$props[$appointmentprops["sentrepresentingemail"]] = $sentrepresentingemail;
1745+
$props[$appointmentprops["sentrepresentingaddt"]] = $sentrepresentingaddt;
17401746
$props[$appointmentprops["sentrepresentinsrchk"]] = $props[$appointmentprops["sentrepresentingaddt"]] . ":" . $props[$appointmentprops["sentrepresentingemail"]];
17411747

17421748
if (isset($appointment->attendees) && is_array($appointment->attendees) && !empty($appointment->attendees)) {
@@ -1763,7 +1769,7 @@ private function setAppointment($mapimessage, $appointment) {
17631769

17641770
// Do attendees
17651771
// For AS-16 get a list of the current attendees (pre update)
1766-
if ($isAs16 && isset($appointment->meetingstatus) && $appointment->meetingstatus > 0) {
1772+
if ($isAs16 && $isMeeting) {
17671773
$old_recipienttable = mapi_message_getrecipienttable($mapimessage);
17681774
$old_receipstable = mapi_table_queryallrows(
17691775
$old_recipienttable,
@@ -1799,20 +1805,26 @@ private function setAppointment($mapimessage, $appointment) {
17991805
$recips = [];
18001806

18011807
// Outlook XP requires organizer in the attendee list as well
1802-
$org = [];
1803-
$org[PR_ENTRYID] = isset($representingprops[$appointmentprops["representingentryid"]]) ? $representingprops[$appointmentprops["representingentryid"]] : $props[$appointmentprops["representingentryid"]];
1804-
$org[PR_DISPLAY_NAME] = isset($representingprops[$appointmentprops["representingname"]]) ? $representingprops[$appointmentprops["representingname"]] : $props[$appointmentprops["representingname"]];
1805-
$org[PR_ADDRTYPE] = isset($representingprops[$appointmentprops["sentrepresentingaddt"]]) ? $representingprops[$appointmentprops["sentrepresentingaddt"]] : $props[$appointmentprops["sentrepresentingaddt"]];
1806-
$org[PR_SMTP_ADDRESS] = $org[PR_EMAIL_ADDRESS] = isset($representingprops[$appointmentprops["sentrepresentingemail"]]) ? $representingprops[$appointmentprops["sentrepresentingemail"]] : $props[$appointmentprops["sentrepresentingemail"]];
1807-
$org[PR_SEARCH_KEY] = isset($representingprops[$appointmentprops["sentrepresentinsrchk"]]) ? $representingprops[$appointmentprops["sentrepresentinsrchk"]] : $props[$appointmentprops["sentrepresentinsrchk"]];
1808-
$org[PR_RECIPIENT_FLAGS] = recipOrganizer | recipSendable;
1809-
$org[PR_RECIPIENT_TYPE] = MAPI_ORIG;
1810-
1811-
array_push($recips, $org);
1808+
// Only add organizer if it's a meeting
1809+
if ($isMeeting) {
1810+
$org = [];
1811+
$org[PR_ENTRYID] = isset($representingprops[$appointmentprops["representingentryid"]]) ? $representingprops[$appointmentprops["representingentryid"]] : $props[$appointmentprops["representingentryid"]];
1812+
$org[PR_DISPLAY_NAME] = isset($representingprops[$appointmentprops["representingname"]]) ? $representingprops[$appointmentprops["representingname"]] : $props[$appointmentprops["representingname"]];
1813+
$org[PR_ADDRTYPE] = isset($representingprops[$appointmentprops["sentrepresentingaddt"]]) ? $representingprops[$appointmentprops["sentrepresentingaddt"]] : $props[$appointmentprops["sentrepresentingaddt"]];
1814+
$org[PR_SMTP_ADDRESS] = $org[PR_EMAIL_ADDRESS] = isset($representingprops[$appointmentprops["sentrepresentingemail"]]) ? $representingprops[$appointmentprops["sentrepresentingemail"]] : $props[$appointmentprops["sentrepresentingemail"]];
1815+
$org[PR_SEARCH_KEY] = isset($representingprops[$appointmentprops["sentrepresentinsrchk"]]) ? $representingprops[$appointmentprops["sentrepresentinsrchk"]] : $props[$appointmentprops["sentrepresentinsrchk"]];
1816+
$org[PR_RECIPIENT_FLAGS] = recipOrganizer | recipSendable;
1817+
$org[PR_RECIPIENT_TYPE] = MAPI_ORIG;
1818+
$org[PR_RECIPIENT_TRACKSTATUS] = olResponseOrganized;
1819+
if ($abEntryProps !== false && isset($abEntryProps[PR_SMTP_ADDRESS])) {
1820+
$org[PR_SMTP_ADDRESS] = $abEntryProps[PR_SMTP_ADDRESS];
1821+
}
18121822

1813-
// remove organizer from old_receips
1814-
if (isset($old_receips[$org[PR_EMAIL_ADDRESS]])) {
1815-
unset($old_receips[$org[PR_EMAIL_ADDRESS]]);
1823+
array_push($recips, $org);
1824+
// remove organizer from old_receips
1825+
if (isset($old_receips[$org[PR_EMAIL_ADDRESS]])) {
1826+
unset($old_receips[$org[PR_EMAIL_ADDRESS]]);
1827+
}
18161828
}
18171829

18181830
// Open address book for user resolve
@@ -1850,6 +1862,10 @@ private function setAppointment($mapimessage, $appointment) {
18501862
else {
18511863
$forceMRUpdateSend = true;
18521864
}
1865+
// the organizer is already in the recipient list, no need to add him again
1866+
if (isset($org[PR_EMAIL_ADDRESS]) && strcasecmp($org[PR_EMAIL_ADDRESS], $recip[PR_EMAIL_ADDRESS]) == 0) {
1867+
continue;
1868+
}
18531869
array_push($recips, $recip);
18541870
}
18551871

@@ -1858,7 +1874,7 @@ private function setAppointment($mapimessage, $appointment) {
18581874
mapi_setprops($mapimessage, $props);
18591875

18601876
// Since AS 16 we have to take care of MeetingRequest updates
1861-
if ($isAs16 && isset($appointment->meetingstatus) && $appointment->meetingstatus > 0) {
1877+
if ($isAs16 && $isMeeting) {
18621878
$mr = new Meetingrequest($this->store, $mapimessage, $this->session);
18631879
// Only send updates if this is a new MR or we are the organizer
18641880
if ($appointment->clientuid || $mr->isLocalOrganiser() || $forceMRUpdateSend) {
@@ -2588,26 +2604,20 @@ private function getSMTPAddressFromEntryID($entryid) {
25882604
}
25892605

25902606
/**
2591-
* Returns fullname from an entryid.
2607+
* Returns AB data from an entryid.
25922608
*
2593-
* @param binary $entryid
2609+
* @param string $entryid
25942610
*
2595-
* @return string fullname or false on error
2611+
* @return mixed
25962612
*/
2597-
private function getFullnameFromEntryID($entryid) {
2613+
private function getAbPropsFromEntryID($entryid) {
25982614
$addrbook = $this->getAddressbook();
25992615
$mailuser = mapi_ab_openentry($addrbook, $entryid);
2600-
if (!$mailuser) {
2601-
SLog::Write(LOGLEVEL_ERROR, sprintf("Unable to get mailuser for getFullnameFromEntryID (0x%X)", mapi_last_hresult()));
2602-
2603-
return false;
2616+
if ($mailuser) {
2617+
return mapi_getprops($mailuser, [PR_DISPLAY_NAME, PR_ADDRTYPE, PR_SMTP_ADDRESS, PR_EMAIL_ADDRESS]);
26042618
}
26052619

2606-
$props = mapi_getprops($mailuser, [PR_DISPLAY_NAME]);
2607-
if (isset($props[PR_DISPLAY_NAME])) {
2608-
return $props[PR_DISPLAY_NAME];
2609-
}
2610-
SLog::Write(LOGLEVEL_ERROR, sprintf("Unable to get fullname for getFullnameFromEntryID (0x%X)", mapi_last_hresult()));
2620+
SLog::Write(LOGLEVEL_ERROR, sprintf("MAPIProvider->getAbPropsFromEntryID(): Unable to get mailuser (0x%X)", mapi_last_hresult()));
26112621

26122622
return false;
26132623
}

0 commit comments

Comments
 (0)