From 603ffde020045b81ad0a82d74a04c40d694731c5 Mon Sep 17 00:00:00 2001
From: jvolkenant <root@pdxutil.localdomain>
Date: Fri, 2 Nov 2018 11:39:45 -0700
Subject: [PATCH] Add autoconfig/autodiscover cnames for hosted email domains

---
 management/dns_update.py | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/management/dns_update.py b/management/dns_update.py
index b6e1022d..87046932 100755
--- a/management/dns_update.py
+++ b/management/dns_update.py
@@ -288,6 +288,14 @@ def build_zone(domain, all_domains, additional_records, www_redirect_domains, en
 			if not has_rec(qname, "SRV"):
 				records.append((qname, "SRV", "0 0 443 " + env["PRIMARY_HOSTNAME"] + ".", "Recommended. Specifies the hostname of the server that handles CardDAV/CalDAV services for email addresses on this domain."))
 
+        # Adds CNAME records for hosted email address domains (Email addresses that are added apart from the PRIMARY_HOSTNAME)
+        # autodiscover.* - Z-Push ActiveSync Autodiscover
+        # autoconfig.* - Thunderbird Autoconfig
+	if domain != env["PRIMARY_HOSTNAME"]:
+		for qname in ("autodiscover", "autoconfig"):
+			if not has_rec(qname, "CNAME"):
+				records.append((qname, "CNAME", env["PRIMARY_HOSTNAME"] + ".", "Provides autodiscovery support for hosted email address domains."))
+
 	# Sort the records. The None records *must* go first in the nsd zone file. Otherwise it doesn't matter.
 	records.sort(key = lambda rec : list(reversed(rec[0].split(".")) if rec[0] is not None else ""))