diff --git a/data/web/inc/ajax/dns_diagnostics.php b/data/web/inc/ajax/dns_diagnostics.php
index 1b4c6ea7..4ee6f92e 100644
--- a/data/web/inc/ajax/dns_diagnostics.php
+++ b/data/web/inc/ajax/dns_diagnostics.php
@@ -94,7 +94,7 @@ if ($_SESSION['mailcow_cc_role'] == "admin") {
     $records[] = array(
       $mailcow_hostname,
       'AAAA',
-      $ip6
+      expand_ipv6($ip6)
     );
     $records[] = array(
       $ptr6,
@@ -335,6 +335,11 @@ foreach ($records as $record) {
       }
       unset($current);
     }
+    elseif ($record[1] == 'AAAA') {
+      foreach ($currents as &$current) {
+        $current['ipv6'] = expand_ipv6($current['ipv6']);
+      }
+    }
   }
 
   if ($record[1] == 'CNAME' && count($currents) == 0) {
@@ -346,8 +351,8 @@ foreach ($records as $record) {
         $currents = array(array('host' => $record[0], 'class' => 'IN', 'type' => 'CNAME', 'target' => $record[2]));
         $aaaa = dns_get_record($record[0], DNS_AAAA);
         $cname = dns_get_record($record[2], DNS_AAAA);
-        if (count($aaaa) == 0 || count($cname) == 0 || $aaaa[0]['ipv6'] != $cname[0]['ipv6']) {
-          $currents[0]['target'] = $aaaa[0]['ipv6'] . ' <sup>1</sup>';
+        if (count($aaaa) == 0 || count($cname) == 0 || expand_ipv6($aaaa[0]['ipv6']) != expand_ipv6($cname[0]['ipv6'])) {
+          $currents[0]['target'] = expand_ipv6($aaaa[0]['ipv6']) . ' <sup>1</sup>';
         }
       }
       else {
diff --git a/data/web/inc/functions.inc.php b/data/web/inc/functions.inc.php
index 43639d04..6848a0dd 100644
--- a/data/web/inc/functions.inc.php
+++ b/data/web/inc/functions.inc.php
@@ -355,6 +355,11 @@ function pem_to_der($pem_key) {
   unset($lines[0]);
   return base64_decode(implode('', $lines));
 }
+function expand_ipv6($ip) {
+	$hex = unpack("H*hex", inet_pton($ip));
+	$ip = substr(preg_replace("/([A-f0-9]{4})/", "$1:", $hex['hex']), 0, -1);
+	return $ip;
+}
 function generate_tlsa_digest($hostname, $port, $starttls = null) {
   if (!is_valid_domain_name($hostname)) {
     return "Not a valid hostname";
diff --git a/data/web/inc/spf.inc.php b/data/web/inc/spf.inc.php
index 5e63b38b..bccbbeae 100644
--- a/data/web/inc/spf.inc.php
+++ b/data/web/inc/spf.inc.php
@@ -1,12 +1,6 @@
 <?php
 error_reporting(0);
 
-function expand_ipv6($ip) {
-	$hex = unpack("H*hex", inet_pton($ip));
-	$ip = substr(preg_replace("/([A-f0-9]{4})/", "$1:", $hex['hex']), 0, -1);
-	return $ip;
-}
-
 function get_spf_allowed_hosts($check_domain)
 {
 	$hosts = array();