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.
pull/6763/head
Amir Caspi 5 years ago committed by Aleksander Machniak
parent 7c8ce07e8c
commit 6b5fa52ec1

@ -574,13 +574,15 @@ class rcube_utils
// %n - host // %n - host
$n = self::server_name(); $n = self::server_name();
// %t - host name without first part, e.g. %n=mail.domain.tld, %t=domain.tld // %t - host name without first part, e.g. %n=mail.domain.tld, %t=domain.tld
$t = preg_replace('/^[^\.]+\./', '', $n); // If %n=domain.tld then %t=domain.tld as well (remains valid)
// %d - domain name without first part $t = preg_replace('/^[^.]+\.(?![^.]+$)/', '', $n);
$d = preg_replace('/^[^\.]+\./', '', self::server_name('HTTP_HOST')); // %d - domain name without first part (up to domain.tld)
$d = preg_replace('/^[^.]+\.(?![^.]+$)/', '', self::server_name('HTTP_HOST'));
// %h - IMAP host // %h - IMAP host
$h = $_SESSION['storage_host'] ?: $host; $h = $_SESSION['storage_host'] ?: $host;
// %z - IMAP domain without first part, e.g. %h=imap.domain.tld, %z=domain.tld // %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. // %s - domain name after the '@' from e-mail address provided at login screen.
// Returns FALSE if an invalid email is provided // Returns FALSE if an invalid email is provided
if (strpos($name, '%s') !== false) { if (strpos($name, '%s') !== false) {

Loading…
Cancel
Save