Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- Support dynamic hostname (%d/%n) variables in configuration options…

… (#1485438)
  • Loading branch information...
commit bb8721aaeb4961f0dee8ca250749906e01a8f6a8 1 parent 05a631a
@alecpl alecpl authored
View
1  CHANGELOG
@@ -1,6 +1,7 @@
CHANGELOG RoundCube Webmail
===========================
+- Support dynamic hostname (%d/%n) variables in configuration options (#1485438)
- Add 'messages_list' hook (#1486266)
- Add request* event triggers in http_post/http_request (#1486054)
- Fix use RFC-compliant line-delimiter when saving messages on IMAP (#1486712)
View
20 config/main.inc.php.dist
@@ -61,6 +61,10 @@ $rcmail_config['smtp_debug'] = false;
// leave blank to show a textbox at login, give a list of hosts
// to display a pulldown menu or set one host as string.
// To use SSL/TLS connection, enter hostname with prefix ssl:// or tls://
+// Supported replacement variables:
+// %n - http hostname ($_SERVER['SERVER_NAME'])
+// %d - domain (http hostname without the first part)
+// For example %n = mail.domain.tld, %d = domain.tld
$rcmail_config['default_host'] = '';
// TCP port used for IMAP connections
@@ -90,7 +94,11 @@ $rcmail_config['imap_timeout'] = 0;
// SMTP server host (for sending mails).
// To use SSL/TLS connection, enter hostname with prefix ssl:// or tls://
// If left blank, the PHP mail() function is used
-// Use %h variable as replacement for user's IMAP hostname
+// Supported replacement variables:
+// %h - user's IMAP hostname
+// %n - http hostname ($_SERVER['SERVER_NAME'])
+// %d - domain (http hostname without the first part)
+// For example %n = mail.domain.tld, %d = domain.tld
$rcmail_config['smtp_server'] = '';
// SMTP port (default is 25; 465 for SSL)
@@ -176,6 +184,11 @@ $rcmail_config['username_domain'] = '';
// This domain will be used to form e-mail addresses of new users
// Specify an array with 'host' => 'domain' values to support multiple hosts
+// Supported replacement variables:
+// %h - user's IMAP hostname
+// %n - http hostname ($_SERVER['SERVER_NAME'])
+// %d - domain (http hostname without the first part)
+// For example %n = mail.domain.tld, %d = domain.tld
$rcmail_config['mail_domain'] = '';
// Password charset.
@@ -374,6 +387,11 @@ $rcmail_config['ldap_public'] = array();
*
$rcmail_config['ldap_public']['Verisign'] = array(
'name' => 'Verisign.com',
+ // Replacement variables supported in host names:
+ // %h - user's IMAP hostname
+ // %n - http hostname ($_SERVER['SERVER_NAME'])
+ // %d - domain (http hostname without the first part)
+ // For example %n = mail.domain.tld, %d = domain.tld
'hosts' => array('directory.verisign.com'),
'port' => 389,
'use_tls' => false,
View
16 program/include/main.inc
@@ -1532,6 +1532,7 @@ function rcube_https_check($port=null, $use_https=true)
return false;
}
+
// for backward compatibility
function rcube_sess_unset($var_name=null)
{
@@ -1541,6 +1542,21 @@ function rcube_sess_unset($var_name=null)
}
+// Replaces hostname variables
+function rcube_parse_host($name)
+{
+ // %n - host
+ $n = preg_replace('/:\d+$/', '', $_SERVER['SERVER_NAME']);
+ // %d - domain name without first part, e.g. %d=mail.domain.tld, %m=domain.tld
+ $d = preg_replace('/^[^\.]+\./', '', $n);
+ // %h - IMAP host
+ $h = $_SESSION['imap_host'];
+
+ $name = str_replace(array('%n', '%d', '%h'), array($n, $d, $h), $name);
+ return $name;
+}
+
+
/**
* E-mail address validation
*/
View
4 program/include/rcmail.php
@@ -575,7 +575,7 @@ function login($username, $pass, $host=NULL)
if (!$allowed)
return false;
}
- else if (!empty($config['default_host']) && $host != $config['default_host'])
+ else if (!empty($config['default_host']) && $host != rcube_parse_host($config['default_host']))
return false;
// parse $host URL
@@ -743,7 +743,7 @@ public function autoselect_host()
$host = get_input_value('_host', RCUBE_INPUT_POST);
}
else
- $host = $default_host;
+ $host = rcube_parse_host($default_host);
return $host;
}
View
8 program/include/rcube_config.php
@@ -277,12 +277,12 @@ public function mail_domain($host)
$domain = $this->prop['mail_domain'][$host];
}
else if (!empty($this->prop['mail_domain']))
- $domain = $this->prop['mail_domain'];
-
+ $domain = rcube_parse_host($this->prop['mail_domain']);
+
return $domain;
}
-
-
+
+
/**
* Getter for error state
*
View
1  program/include/rcube_ldap.php
@@ -99,6 +99,7 @@ function connect()
foreach ($this->prop['hosts'] as $host)
{
+ $host = rcube_parse_host($host);
$this->_debug("C: Connect [$host".($this->prop['port'] ? ':'.$this->prop['port'] : '')."]");
if ($lc = @ldap_connect($host, $this->prop['port']))
View
2  program/include/rcube_smtp.php
@@ -73,7 +73,7 @@ public function connect()
'smtp_timeout' => $RCMAIL->config->get('smtp_timeout'),
));
- $smtp_host = str_replace('%h', $_SESSION['imap_host'], $CONFIG['smtp_server']);
+ $smtp_host = rcube_parse_host($CONFIG['smtp_server']);
// when called from Installer it's possible to have empty $smtp_host here
if (!$smtp_host) $smtp_host = 'localhost';
$smtp_port = is_numeric($CONFIG['smtp_port']) ? $CONFIG['smtp_port'] : 25;
Please sign in to comment.
Something went wrong with that request. Please try again.