From 6b5fa52ec130d9f4d055c49104b9dc03317ea371 Mon Sep 17 00:00:00 2001 From: Amir Caspi Date: Sat, 11 May 2019 00:03:37 -0600 Subject: [PATCH] Update rcube_utils::parse_host, fixes #6746 Updated regexps used in parse_host to ensure that %t, %d, %z do not cut off domain and return only tld when underlying host has no subdomain (i.e., is just domain.tld rather than mail.domain.tld). Update fixes #6746, now returns nothing shorter than domain.tld. Also removed backslash from character class, period does not need to be escaped within character class. --- program/lib/Roundcube/rcube_utils.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/program/lib/Roundcube/rcube_utils.php b/program/lib/Roundcube/rcube_utils.php index e86f3c780..747371913 100644 --- a/program/lib/Roundcube/rcube_utils.php +++ b/program/lib/Roundcube/rcube_utils.php @@ -574,13 +574,15 @@ class rcube_utils // %n - host $n = self::server_name(); // %t - host name without first part, e.g. %n=mail.domain.tld, %t=domain.tld - $t = preg_replace('/^[^\.]+\./', '', $n); - // %d - domain name without first part - $d = preg_replace('/^[^\.]+\./', '', self::server_name('HTTP_HOST')); + // If %n=domain.tld then %t=domain.tld as well (remains valid) + $t = preg_replace('/^[^.]+\.(?![^.]+$)/', '', $n); + // %d - domain name without first part (up to domain.tld) + $d = preg_replace('/^[^.]+\.(?![^.]+$)/', '', self::server_name('HTTP_HOST')); // %h - IMAP host $h = $_SESSION['storage_host'] ?: $host; // %z - IMAP domain without first part, e.g. %h=imap.domain.tld, %z=domain.tld - $z = preg_replace('/^[^\.]+\./', '', $h); + // If %h=domain.tld then %z=domain.tld as well (remains valid) + $z = preg_replace('/^[^.]+\.(?![^.]+$)/', '', $h); // %s - domain name after the '@' from e-mail address provided at login screen. // Returns FALSE if an invalid email is provided if (strpos($name, '%s') !== false) {