<?php
// Outlook wysyła POST z <EMailAddress>; odpowiadamy ustawieniami IMAP/SMTP dla tego adresu.
$body = file_get_contents('php://input');
preg_match('/<EMailAddress>([^<]+)<\/EMailAddress>/i', $body, $m);
$email = htmlspecialchars(trim($m[1] ?? ''), ENT_XML1);
header('Content-Type: application/xml; charset=utf-8');
echo <<<XML
<?xml version="1.0" encoding="utf-8"?>
<Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006">
  <Response xmlns="http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a">
    <Account>
      <AccountType>email</AccountType>
      <Action>settings</Action>
      <Protocol>
        <Type>IMAP</Type><Server>ssl0.ovh.net</Server><Port>993</Port><SSL>on</SSL>
        <SPA>off</SPA><AuthRequired>on</AuthRequired><DomainRequired>off</DomainRequired>
        <LoginName>$email</LoginName>
      </Protocol>
      <Protocol>
        <Type>SMTP</Type><Server>ssl0.ovh.net</Server><Port>587</Port><Encryption>TLS</Encryption>
        <SPA>off</SPA><AuthRequired>on</AuthRequired><UsePOPAuth>on</UsePOPAuth><SMTPLast>off</SMTPLast>
        <DomainRequired>off</DomainRequired><LoginName>$email</LoginName>
      </Protocol>
    </Account>
  </Response>
</Autodiscover>
XML;
