Commit a21f59c9 authored by mku's avatar mku

ZP-549 #comment Autodiscover - use primary email address from the backend in the response

git-svn-id: https://z-push.org/svn/z-push/trunk@1907 b7dd7b3b-3a3c-0410-9da9-bee62a6cc5b5
parent 197896f6
......@@ -105,9 +105,11 @@ class ZPushAutodiscover {
$incomingXml = $this->getIncomingXml();
$backend = ZPush::GetBackend();
$username = $this->login($backend, $incomingXml);
$userFullname = $backend->GetUserFullname($username);
$userDetails = $backend->GetUserDetails($username);
$email = ($this->getAttribFromUserDetails($userDetails, 'emailaddress')) ? $this->getAttribFromUserDetails($userDetails, 'emailaddress') : $incomingXml->Request->EMailAddress;
$userFullname = ($this->getAttribFromUserDetails($userDetails, 'fullname')) ? $this->getAttribFromUserDetails($userDetails, 'fullname') : $email;
ZLog::Write(LOGLEVEL_WBXML, sprintf("Resolved user's '%s' fullname to '%s'", $username, $userFullname));
$response = $this->createResponse($incomingXml->Request->EMailAddress, $userFullname);
$response = $this->createResponse($email, $userFullname);
setcookie("membername", $username);
}
......@@ -237,6 +239,22 @@ class ZPushAutodiscover {
fclose($output);
ZLog::Write(LOGLEVEL_DEBUG, "ZPushAutodiscover->sendResponse() response sent.");
}
/**
* Gets an attribute from user details.
* @param Array $userDetails
* @param String $attrib
* @access private
*
* @return String or false on error.
*/
private function getAttribFromUserDetails($userDetails, $attrib) {
if (isset($userDetails[$attrib]) && $userDetails[$attrib]) {
return $userDetails[$attrib];
}
ZLog::Write(LOGLEVEL_WARN, sprintf("The backend was not able to find attribute '%s' of the user. Fall back to the default value."));
return false;
}
}
ZPushAutodiscover::DoZPushAutodiscover();
......
......@@ -1181,17 +1181,19 @@ class BackendZarafa implements IBackend, ISearchProvider {
}
/**
* Returns the display name of the user. Used by autodiscover.
* Returns the email address and the display name of the user. Used by autodiscover.
*
* @param string $username The username
*
* @access public
* @return string
* @return Array
*/
public function GetUserFullname($username) {
ZLog::Write(LOGLEVEL_WBXML, sprintf("ZarafaBackend->GetUserFullname for '%s'.", $username));
public function GetUserDetails($username) {
ZLog::Write(LOGLEVEL_WBXML, sprintf("ZarafaBackend->GetUserDetails for '%s'.", $username));
$zarafauserinfo = @mapi_zarafa_getuser_by_name($this->defaultstore, $username);
return (isset($zarafauserinfo['fullname']) && $zarafauserinfo['fullname']) ? $zarafauserinfo['fullname'] : $username;
$userDetails['emailaddress'] = (isset($zarafauserinfo['emailaddress']) && $zarafauserinfo['emailaddress']) ? $zarafauserinfo['emailaddress'] : false;
$userDetails['fullname'] = (isset($zarafauserinfo['fullname']) && $zarafauserinfo['fullname']) ? $zarafauserinfo['fullname'] : false;
return $userDetails;
}
......
......@@ -204,15 +204,15 @@ abstract class Backend implements IBackend {
}
/**
* Returns the display name of the user. Used by autodiscover.
* Returns the email address and the display name of the user. Used by autodiscover.
*
* @param string $username The username
*
* @access public
* @return string
* @return Array
*/
public function GetUserFullname($username) {
return $username;
public function GetUserDetails($username) {
return array('emailaddress' => $username, 'fullname' => $username);
}
/**----------------------------------------------------------------------------------------------------------
......
......@@ -291,14 +291,14 @@ interface IBackend {
public function ResolveRecipients($resolveRecipients);
/**
* Returns the display name of the user. Used by autodiscover.
* Returns the email address and the display name of the user. Used by autodiscover.
*
* @param string $username The username
*
* @access public
* @return string
* @return Array
*/
public function GetUserFullname($username);
public function GetUserDetails($username);
}
?>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment