diff --git a/inc/autodiscover-handler.php b/inc/autodiscover-handler.php index 9eda2e6c..abf4fcac 100644 --- a/inc/autodiscover-handler.php +++ b/inc/autodiscover-handler.php @@ -1,2 +1,90 @@ enable_autodiscover) || ! $c->enable_autodiscover ) { + $request->DoResponse( 404 ); + exit(0); +} + +$ns_outlook_req_2006 = "http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006"; +$ns_exchange_resp_2006 = "http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006"; +$ns_outlook_resp_2006a = "http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a"; + +function errorResponse( $code, $message, $debugdata = '' ) { + global $request, $ns_exchange_resp_2006; + + $error_time_id = time(); + $error_time = gmdate('h:i:s', $error_time_id); + $response = << + + + + $code + $message + $debugdata + + + +ERROR; + + $request->DoResponse( $code, $response, 'text/xml; charset="utf-8"' ); + exit(0); +} + + +if ( !isset($request->xml_tags) ) + errorResponse( 406, translate("Body contains no XML data!") ); + +$position = 0; +$xmltree = BuildXMLTree( $request->xml_tags, $position); +if ( !is_object($xmltree) ) + errorResponse( 406, translate("REPORT body is not valid XML data!") ); + +$user_email = $xmltree->GetPath( +'/'.$ns_outlook_req_2006.':Autodiscover'. +'/'.$ns_outlook_req_2006.':Request'. +'/'.$ns_outlook_req_2006.':EMailAddress'); +if ( count($user_email) < 1 ) errorResponse(500,"User not found."); +$user_email = $user_email[0]->GetContent(); + +$principal = new Principal(); + +$reply = new XMLDocument( array( $ns_outlook_resp_2006a => "" ) ); +$response = array( + new XMLElement( 'User', + array( + new XMLElement( 'DisplayName', $principal->$fullname ), + new XMLElement('AutoDiscoverSMTPAddress',$user_email), + ) + ) +); + +$response[] = new XMLElement('Account', + array( + new XMLElement( 'AccountType', 'email' ), // The only allowed accounttype + new XMLElement('Action','settings'), + new XMLElement('Protocol', + array( + new XMLElement('Type', 'DAV'), + new XMLElement('Server', $c->domain_name ), + new XMLElement('LoginName', $principal->username()) + ) + ) + ) +); + +$autodiscover = new XMLElement( "Autodiscover", $responses, $reply->GetXmlNsArray(), $ns_exchange_resp_2006 ); + +$request->XMLResponse( 207, $autodiscover );