Skip to content

Commit 6252d43

Browse files
committed
Merge branch '135-sync-issues-when-using-altnames-to-login' into 'master'
Get users email address from the store to be used with nsp_getuserinfo(). Closes #135 See merge request grommunio/grommunio-sync!105
2 parents 22f2119 + de0cd1c commit 6252d43

File tree

4 files changed

+48
-16
lines changed

4 files changed

+48
-16
lines changed

lib/core/sharedfolders.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php
2+
23
/*
34
* SPDX-License-Identifier: AGPL-3.0-only
4-
* SPDX-FileCopyrightText: Copyright 2022 grommunio GmbH
5+
* SPDX-FileCopyrightText: Copyright 2022-2025 grommunio GmbH
56
*
67
* Cache shared public folder hierarchy information.
78
*/
@@ -29,7 +30,7 @@ public function __construct() {
2930
$this->allocate = 0;
3031
$this->localpart = "undefined";
3132
$this->mainDomain = "undefined";
32-
if (preg_match('/^([*+!.&#$|\'\\%\/0-9a-z^_`{}=?~:-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})$/i', nsp_getuserinfo(Request::GetUser())['primary_email'], $matches)) {
33+
if (preg_match('/^([*+!.&#$|\'\%\/0-9a-z^_`{}=?~:-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})$/i', nsp_getuserinfo(Request::GetUserIdentifier())['primary_email'], $matches)) {
3334
$this->localpart = $matches[1];
3435
$this->mainDomain = $matches[2];
3536
}

lib/grommunio/grommunio.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php
2+
23
/*
34
* SPDX-License-Identifier: AGPL-3.0-only
45
* SPDX-FileCopyrightText: Copyright 2007-2016 Zarafa Deutschland GmbH
5-
* SPDX-FileCopyrightText: Copyright 2020-2024 grommunio GmbH
6+
* SPDX-FileCopyrightText: Copyright 2020-2025 grommunio GmbH
67
*
78
* This is a backend for grommunio. It is an implementation of IBackend and also
89
* implements ISearchProvider to search in the grommunio system. The backend
@@ -2207,6 +2208,17 @@ private function openMessageStore($user) {
22072208
$this->storeCache[$user] = $store;
22082209
}
22092210

2211+
// g-sync135: always use SMTP address (issue with altnames)
2212+
if (!$return_public) {
2213+
$addressbook = $this->getAddressbook();
2214+
$storeProps = mapi_getprops($store, [PR_MAILBOX_OWNER_ENTRYID]);
2215+
$mailuser = mapi_ab_openentry($addressbook, $storeProps[PR_MAILBOX_OWNER_ENTRYID]);
2216+
$smtpProps = mapi_getprops($mailuser, [PR_SMTP_ADDRESS]);
2217+
if (isset($smtpProps[PR_SMTP_ADDRESS])) {
2218+
Request::SetUserIdentifier($smtpProps[PR_SMTP_ADDRESS]);
2219+
}
2220+
}
2221+
22102222
SLog::Write(LOGLEVEL_DEBUG, sprintf("Grommunio->openMessageStore('%s'): Found '%s' store: '%s'", $user, ($return_public) ? 'PUBLIC' : 'DEFAULT', $store));
22112223

22122224
return $store;
@@ -2396,7 +2408,7 @@ private function settingsUserInformation(&$userinformation) {
23962408

23972409
return false;
23982410
}
2399-
$user = nsp_getuserinfo($this->mainUser);
2411+
$user = nsp_getuserinfo(Request::GetUserIdentifier());
24002412
if ($user != false) {
24012413
$userinformation->Status = SYNC_SETTINGSSTATUS_USERINFO_SUCCESS;
24022414
if (Request::GetProtocolVersion() >= 14.1) {
@@ -3015,19 +3027,16 @@ private function getAddressbook() {
30153027
}
30163028

30173029
/**
3018-
* Returns the adressbook dir entry
3019-
*
3020-
* @access private
3030+
* Returns the adressbook dir entry.
30213031
*
30223032
* @return mixed addressbook dir entry or false on error
30233033
*/
30243034
private function getAddressbookDir() {
30253035
try {
30263036
$addrbook = $this->getAddressbook();
30273037
$ab_entryid = mapi_ab_getdefaultdir($addrbook);
3028-
$ab_dir = mapi_ab_openentry($addrbook, $ab_entryid);
30293038

3030-
return $ab_dir;
3039+
return mapi_ab_openentry($addrbook, $ab_entryid);
30313040
}
30323041
catch (MAPIException $e) {
30333042
SLog::Write(LOGLEVEL_ERROR, sprintf("Grommunio->getAddressbookDir(): Unable to open addressbook: %s", $e));

lib/grommunio/mapiprovider.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php
2+
23
/*
34
* SPDX-License-Identifier: AGPL-3.0-only
45
* SPDX-FileCopyrightText: Copyright 2007-2016 Zarafa Deutschland GmbH
5-
* SPDX-FileCopyrightText: Copyright 2020-2024 grommunio GmbH
6+
* SPDX-FileCopyrightText: Copyright 2020-2025 grommunio GmbH
67
*/
78

89
class MAPIProvider {
@@ -306,7 +307,7 @@ private function getAppointment($mapimessage, $contentparameters) {
306307
SLog::Write(LOGLEVEL_DEBUG, sprintf("MAPIProvider->getAppointment: adding ourself as an attendee for iOS6 workaround"));
307308
$attendee = new SyncAttendee();
308309

309-
$meinfo = nsp_getuserinfo(Request::GetUser());
310+
$meinfo = nsp_getuserinfo(Request::GetUserIdentifier());
310311

311312
if (is_array($meinfo)) {
312313
$attendee->email = $meinfo["primary_email"];
@@ -322,7 +323,7 @@ private function getAppointment($mapimessage, $contentparameters) {
322323
// If it's an appointment which doesn't have any attendees, we have to make sure that
323324
// the user is the owner or it will not work properly with android devices
324325
if (isset($messageprops[$appointmentprops["meetingstatus"]]) && $messageprops[$appointmentprops["meetingstatus"]] == olNonMeeting && empty($message->attendees)) {
325-
$meinfo = nsp_getuserinfo(Request::GetUser());
326+
$meinfo = nsp_getuserinfo(Request::GetUserIdentifier());
326327

327328
if (is_array($meinfo)) {
328329
$message->organizeremail = $meinfo["primary_email"];
@@ -805,7 +806,7 @@ private function getEmail($mapimessage, $contentparameters) {
805806
// do it so that the attendee status is updated on the mobile
806807
if (!isset($messageprops[$emailproperties["processed"]])) {
807808
// check if we are not sending the MR so we can process it
808-
$cuser = GSync::GetBackend()->GetUserDetails(GSync::GetBackend()->GetCurrentUsername());
809+
$cuser = GSync::GetBackend()->GetUserDetails(Request::GetUserIdentifier());
809810
if (isset($cuser["emailaddress"]) && $cuser["emailaddress"] != $fromaddr) {
810811
if (!isset($req)) {
811812
$req = new Meetingrequest($this->store, $mapimessage, $this->session);
@@ -1025,7 +1026,8 @@ public function GetFolder($folderprops) {
10251026

10261027
// ignore certain undesired folders, like "RSS Feeds", "Suggested contacts" and Journal
10271028
if ((isset($folderprops[PR_CONTAINER_CLASS]) && (
1028-
$folderprops[PR_CONTAINER_CLASS] == "IPF.Note.OutlookHomepage" || $folderprops[PR_CONTAINER_CLASS] == "IPF.Journal")) ||
1029+
$folderprops[PR_CONTAINER_CLASS] == "IPF.Note.OutlookHomepage" || $folderprops[PR_CONTAINER_CLASS] == "IPF.Journal"
1030+
)) ||
10291031
in_array($folderprops[PR_ENTRYID], $this->getSpecialFoldersData())
10301032
) {
10311033
SLog::Write(LOGLEVEL_DEBUG, sprintf("MAPIProvider->GetFolder(): folder '%s' should not be synchronized", $folderprops[PR_DISPLAY_NAME]));
@@ -2142,7 +2144,7 @@ private function setTask($mapimessage, $task) {
21422144
$p = [$taskprops["owner"]];
21432145
$owner = $this->getProps($mapimessage, $p);
21442146
if (!isset($owner[$taskprops["owner"]])) {
2145-
$userinfo = nsp_getuserinfo(Request::GetUser());
2147+
$userinfo = nsp_getuserinfo(Request::GetUserIdentifier());
21462148
if (mapi_last_hresult() == NOERROR && isset($userinfo["fullname"])) {
21472149
$props[$taskprops["owner"]] = $userinfo["fullname"];
21482150
}

lib/request/request.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php
2+
23
/*
34
* SPDX-License-Identifier: AGPL-3.0-only
45
* SPDX-FileCopyrightText: Copyright 2007-2016 Zarafa Deutschland GmbH
5-
* SPDX-FileCopyrightText: Copyright 2020-2024 grommunio GmbH
6+
* SPDX-FileCopyrightText: Copyright 2020-2025 grommunio GmbH
67
*
78
* This class checks and processes all incoming data of the request.
89
*/
@@ -54,6 +55,7 @@ class Request {
5455
private static $authDomain;
5556
private static $authPassword;
5657
private static $impersonatedUser;
58+
private static $userIdentifier;
5759
private static $asProtocolVersion;
5860
private static $policykey;
5961
private static $useragent;
@@ -692,6 +694,24 @@ public static function IsRequestMemoryLimitReached() {
692694
return memory_get_peak_usage(true) >= self::$memoryLimit;
693695
}
694696

697+
/**
698+
* Returns a user identifier coming from the logged user store, mostly an email address.
699+
*
700+
* @return string
701+
*/
702+
public static function GetUserIdentifier() {
703+
return self::$userIdentifier;
704+
}
705+
706+
/**
707+
* Sets a user identifier coming from the logged user store.
708+
*
709+
* @param string $userIdentifier
710+
*/
711+
public static function SetUserIdentifier($userIdentifier) {
712+
self::$userIdentifier = $userIdentifier;
713+
}
714+
695715
/*----------------------------------------------------------------------------------------------------------
696716
* Private stuff
697717
*/

0 commit comments

Comments
 (0)