From edf137a7d0a15f5b63f50392aad9927f043bf53c Mon Sep 17 00:00:00 2001 From: Adam Spragg Date: Mon, 4 Oct 2021 09:40:04 +0100 Subject: First working version of emailautoconf --- php/thunderbird.php | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 php/thunderbird.php (limited to 'php/thunderbird.php') diff --git a/php/thunderbird.php b/php/thunderbird.php new file mode 100644 index 0000000..cc35f09 --- /dev/null +++ b/php/thunderbird.php @@ -0,0 +1,91 @@ +. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +// Thunderbird autoconfiguration described at: +// https://wiki.mozilla.org/Thunderbird:Autoconfiguration +// https://wiki.mozilla.org/Thunderbird:Autoconfiguration:ConfigFileFormat +// +// Should be installed at: +// http://autoconfig.[domain]/mail/config-v1.1.xml +// http://[domain]/.well-known/autoconfig/mail/config-v1.1.xml + +if ($_SERVER['REQUEST_URI'] == "/mail/config-v1.1.xml" + && preg_match('/^autoconfig\.(.*)$/', $_SERVER['HTTP_HOST'], $matches)) +{ + $domain = $matches[1]; +} +else if ($_SERVER['REQUEST_URI'] == "/.well-known/autoconfig/mail/config-v1.1.xml") { + $domain = $_SERVER['HTTP_HOST']; +} +else { + http_response_code(500); + header('Content-Type: text/plain'); + echo "Unable to determine email domain from //".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; + exit(1); +} + +$IMAP = dns_get_record("_imaps._tcp.".$domain, DNS_SRV) + ?: dns_get_record("_imap._tcp.".$domain, DNS_SRV); +$SMTP = dns_get_record("_submission._tcp.".$domain, DNS_SRV); + +if (!$IMAP || !$SMTP) { + http_response_code(500); + header('Content-Type: text/plain'); + if (!$IMAP) { + echo "Missing/unavailable IMAP(S) SRV record for ".$domain; + } + if (!$SMTP) { + echo "Missing/unavailable Submission SRV record for ".$domain; + } + exit(1); +} + +$sitename = getenv("EMAIL_SITENAME") ?: $domain; +$shortname = getenv("EMAIL_SHORTNAME") ?: $sitename; + +header('Content-Type: application/xml'); +?> + + + + + + + + + + + SSL + %EMAILLOCALPART% + password-cleartext + + + + + + + STARTTLS + %EMAILLOCALPART% + password-cleartext + + + + -- cgit v1.2.1