From b9e5bc9e1fbcb4ec8be3b361894ab8715e42d630 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 29 Nov 2014 13:46:50 +0100 Subject: bug 1318: Properly order MX records by order given in RFC 5321 --- includes/general.php | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/includes/general.php b/includes/general.php index 596cc49..d9c74b9 100644 --- a/includes/general.php +++ b/includes/general.php @@ -538,20 +538,34 @@ if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\+\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/" , $email)) { list($username,$domain)=explode('@',$email,2); - $dom = escapeshellarg($domain); - $line = trim(shell_exec("dig +short MX $dom 2>&1")); -#echo $email."-$dom-$line-\n"; -#echo shell_exec("dig +short mx heise.de 2>&1")."-
\n"; - - $list = explode("\n", $line); - foreach($list as $row) { - if(!strstr($row, " ")) { - continue; + $mxhosts = array(); + $mxweight = array(); + if( !getmxrr($domain, $mxhosts) ) { + $mxhostrr = array($domain); + $mxweight = array(0); + } else if ( !empty($mxhosts) ) { + $mxhostrr = array($domain); + $mxweight = array(0); + } + + $mxhostprio = array(); + for($i = 0; $i < count($mxhostrr); $i++) { + $mx_host = trim($mxhostrr[$i], '.'); + $mx_prio = $mxweight[$i]; + if(empty($mxhostprio[$mx_prio])) { + $mxhostprio[$mx_prio] = arraY(); } - list($pri, $mxhosts[]) = explode(" ", trim($row), 2); + $mxhostprio[$mx_prio][] = $mx_host; + } + + array_walk($mxhostprio, function(&$mx) { shuffle($mx); } ); + + $mxhosts = array(); + foreach($mxhostprio as $mx_prio => $mxhostnames) { + foreach($mxhostnames as $mx_host) { + $mxhosts[] = $mx_host; + ] } - $mxhosts[] = $domain; - array_walk($mxhosts, function(&$mx) { $mx = trim($mx, '.'); } ); foreach($mxhosts as $key => $domain) { -- cgit v1.2.1 From 285cd754385216cec4292ce74f75f945d267c78d Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 29 Nov 2014 14:26:16 +0100 Subject: bug 1318: Typo in control structure --- includes/general.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/general.php b/includes/general.php index d9c74b9..4e57d3c 100644 --- a/includes/general.php +++ b/includes/general.php @@ -564,7 +564,7 @@ foreach($mxhostprio as $mx_prio => $mxhostnames) { foreach($mxhostnames as $mx_host) { $mxhosts[] = $mx_host; - ] + } } foreach($mxhosts as $key => $domain) -- cgit v1.2.1 From 2ccdbb3af3cbac35195edd4fe65e946a0c27f70b Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 29 Nov 2014 14:50:31 +0100 Subject: bug 1318: Request the array containing the priorities to sort entries propoerly --- includes/general.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/general.php b/includes/general.php index 4e57d3c..64322aa 100644 --- a/includes/general.php +++ b/includes/general.php @@ -540,7 +540,7 @@ list($username,$domain)=explode('@',$email,2); $mxhosts = array(); $mxweight = array(); - if( !getmxrr($domain, $mxhosts) ) { + if( !getmxrr($domain, $mxhosts, $mxweight) ) { $mxhostrr = array($domain); $mxweight = array(0); } else if ( !empty($mxhosts) ) { -- cgit v1.2.1 From 6288c98be0af18ece8d1ae674f65954452005b97 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 29 Nov 2014 14:58:20 +0100 Subject: bug 1318: Fix a check for if there were any servers --- includes/general.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/general.php b/includes/general.php index 64322aa..065daaa 100644 --- a/includes/general.php +++ b/includes/general.php @@ -543,7 +543,7 @@ if( !getmxrr($domain, $mxhosts, $mxweight) ) { $mxhostrr = array($domain); $mxweight = array(0); - } else if ( !empty($mxhosts) ) { + } else if ( empty($mxhosts) ) { $mxhostrr = array($domain); $mxweight = array(0); } -- cgit v1.2.1 From 292ac178bf2ac32834fafc3313fa294dbeae8ecb Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 29 Nov 2014 15:08:09 +0100 Subject: bug 1318: Actually sort by priority --- includes/general.php | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/general.php b/includes/general.php index 065daaa..1031247 100644 --- a/includes/general.php +++ b/includes/general.php @@ -559,6 +559,7 @@ } array_walk($mxhostprio, function(&$mx) { shuffle($mx); } ); + ksort($mxhostprio); $mxhosts = array(); foreach($mxhostprio as $mx_prio => $mxhostnames) { -- cgit v1.2.1 From 5ea53c50ad1679e808bd0ddd4da92ed88b499a7d Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 29 Nov 2014 15:11:15 +0100 Subject: bug 1318: typo in variable names --- includes/general.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/general.php b/includes/general.php index 1031247..4ed4ea5 100644 --- a/includes/general.php +++ b/includes/general.php @@ -540,10 +540,10 @@ list($username,$domain)=explode('@',$email,2); $mxhosts = array(); $mxweight = array(); - if( !getmxrr($domain, $mxhosts, $mxweight) ) { + if( !getmxrr($domain, $mxhostrr, $mxweight) ) { $mxhostrr = array($domain); $mxweight = array(0); - } else if ( empty($mxhosts) ) { + } else if ( empty($mxhostrr) ) { $mxhostrr = array($domain); $mxweight = array(0); } -- cgit v1.2.1 From 18e87bafbf9f28af77280e29bca27e642890a0bd Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sun, 30 Nov 2014 18:57:09 +0100 Subject: bug 1318: Variable name typo --- includes/general.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/general.php b/includes/general.php index 4ed4ea5..b2e3258 100644 --- a/includes/general.php +++ b/includes/general.php @@ -538,7 +538,7 @@ if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\+\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/" , $email)) { list($username,$domain)=explode('@',$email,2); - $mxhosts = array(); + $mxhostrr = array(); $mxweight = array(); if( !getmxrr($domain, $mxhostrr, $mxweight) ) { $mxhostrr = array($domain); -- cgit v1.2.1 From b388a866c926be68aeb5a9e5bb28b364fa39ad86 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sun, 30 Nov 2014 19:03:44 +0100 Subject: bug 1318: Minor typo --- includes/general.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/general.php b/includes/general.php index b2e3258..a03a45f 100644 --- a/includes/general.php +++ b/includes/general.php @@ -553,7 +553,7 @@ $mx_host = trim($mxhostrr[$i], '.'); $mx_prio = $mxweight[$i]; if(empty($mxhostprio[$mx_prio])) { - $mxhostprio[$mx_prio] = arraY(); + $mxhostprio[$mx_prio] = array(); } $mxhostprio[$mx_prio][] = $mx_host; } -- cgit v1.2.1