From b34d650f9795d98cc9a753cb0c03697ab552b495 Mon Sep 17 00:00:00 2001 From: Michael Kuron Date: Sun, 18 Jun 2017 13:09:28 +0200 Subject: [PATCH] Autodiscovery for arbitrary clients. EAS only for Outlook 2013+ Mobile and Desktop clients can be differentiated based on the response scheme they request. Mobile clients and Outlook 2013+ get EAS, others get IMAP --- data/web/autodiscover.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/data/web/autodiscover.php b/data/web/autodiscover.php index c0a06e87..fdef02a5 100644 --- a/data/web/autodiscover.php +++ b/data/web/autodiscover.php @@ -27,14 +27,18 @@ if(file_exists('inc/vars.local.inc.php')) { error_reporting(0); -if ($config['useEASforOutlook'] == 'no') { - if (strpos($_SERVER['HTTP_USER_AGENT'], 'Outlook')) { - $config['autodiscoverType'] = 'imap'; - } -} +$data = trim(file_get_contents("php://input")); -if (!isset($_SERVER['HTTP_USER_AGENT']) || empty($_SERVER['HTTP_USER_AGENT'])) { // eM Client sends no user agent +// Desktop clients need IMAP, unless it's Outlook 2013 or higher on Windows +if (strpos($data, 'autodiscover/outlook/responseschema')) { // desktop client $config['autodiscoverType'] = 'imap'; + if ($config['useEASforOutlook'] == 'yes' && + strpos($_SERVER['HTTP_USER_AGENT'], 'Outlook') !== FALSE && // Outlook + strpos($_SERVER['HTTP_USER_AGENT'], 'Windows NT') !== FALSE && // Windows + preg_match('/Outlook (1[5-9]\.|[2-9]|1[0-9][0-9])/', $_SERVER['HTTP_USER_AGENT']) // Outlook 2013 (version 15) or higher + ) { + $config['autodiscoverType'] = 'activesync'; + } } $dsn = "$database_type:host=$database_host;dbname=$database_name"; @@ -57,7 +61,6 @@ if (!isset($_SERVER['PHP_AUTH_USER']) OR $as !== "user") { header("Content-Type: application/xml"); echo ''; - $data = trim(file_get_contents("php://input")); if(!$data) { list($usec, $sec) = explode(' ', microtime()); echo '';