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/6841/head
Amir Caspi 6 years ago committed by Aleksander Machniak
parent 55ebae3c1e
commit 06c5a20331

@ -567,13 +567,15 @@ class rcube_utils
// %n - host // %n - host
$n = preg_replace('/:\d+$/', '', $_SERVER['SERVER_NAME']); $n = preg_replace('/:\d+$/', '', $_SERVER['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('/^[^\.]+\./', '', $_SERVER['HTTP_HOST']); // %d - domain name without first part (up to domain.tld)
$d = preg_replace('/^[^.]+\.(?![^.]+$)/', '', $_SERVER['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