Skip to content

Commit 208551b

Browse files
committed
Get users email address from the store to be used with nsp_getuserinfo().
References: Issue #135
1 parent e959394 commit 208551b

File tree

4 files changed

+42
-17
lines changed

4 files changed

+42
-17
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: 10 additions & 8 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
@@ -2399,7 +2400,7 @@ private function settingsUserInformation(&$userinformation) {
23992400

24002401
return false;
24012402
}
2402-
$user = nsp_getuserinfo($this->mainUser);
2403+
$user = nsp_getuserinfo(Request::GetUserIdentifier());
24032404
if ($user != false) {
24042405
$userinformation->Status = SYNC_SETTINGSSTATUS_USERINFO_SUCCESS;
24052406
if (Request::GetProtocolVersion() >= 14.1) {
@@ -3018,19 +3019,16 @@ private function getAddressbook() {
30183019
}
30193020

30203021
/**
3021-
* Returns the adressbook dir entry
3022-
*
3023-
* @access private
3022+
* Returns the adressbook dir entry.
30243023
*
30253024
* @return mixed addressbook dir entry or false on error
30263025
*/
30273026
private function getAddressbookDir() {
30283027
try {
30293028
$addrbook = $this->getAddressbook();
30303029
$ab_entryid = mapi_ab_getdefaultdir($addrbook);
3031-
$ab_dir = mapi_ab_openentry($addrbook, $ab_entryid);
30323030

3033-
return $ab_dir;
3031+
return mapi_ab_openentry($addrbook, $ab_entryid);
30343032
}
30353033
catch (MAPIException $e) {
30363034
SLog::Write(LOGLEVEL_ERROR, sprintf("Grommunio->getAddressbookDir(): Unable to open addressbook: %s", $e));
@@ -3053,7 +3051,11 @@ private function isGSyncEnabled() {
30533051
$mobileDisabled = !($storeProps[PR_EC_ENABLED_FEATURES_L] & UP_EAS);
30543052
if (!$mobileDisabled) {
30553053
$mailuser = mapi_ab_openentry($addressbook, $storeProps[PR_MAILBOX_OWNER_ENTRYID]);
3056-
$enabledFeatures = mapi_getprops($mailuser, [PR_EC_DISABLED_FEATURES]);
3054+
$enabledFeatures = mapi_getprops($mailuser, [PR_EC_DISABLED_FEATURES, PR_SMTP_ADDRESS]);
3055+
// g-sync135: always use SMTP address (issue with altnames)
3056+
if (isset($enabledFeatures[PR_SMTP_ADDRESS])) {
3057+
Request::SetUserIdentifier($enabledFeatures[PR_SMTP_ADDRESS]);
3058+
}
30573059
if (isset($enabledFeatures[PR_EC_DISABLED_FEATURES]) && is_array($enabledFeatures[PR_EC_DISABLED_FEATURES])) {
30583060
$mobileDisabled = in_array(self::MOBILE_ENABLED, $enabledFeatures[PR_EC_DISABLED_FEATURES]);
30593061
$deviceId = Request::GetDeviceID();

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)