summaryrefslogtreecommitdiff
path: root/program/include
diff options
context:
space:
mode:
Diffstat (limited to 'program/include')
-rw-r--r--program/include/main.inc1
-rw-r--r--program/include/rcmail.php8
-rw-r--r--program/include/rcube_config.php8
-rw-r--r--program/include/rcube_imap.php11
-rw-r--r--program/include/rcube_ldap.php2
-rw-r--r--program/include/rcube_shared.inc48
-rw-r--r--program/include/rcube_smtp.php9
-rwxr-xr-xprogram/include/rcube_template.php8
-rw-r--r--program/include/rcube_user.php58
9 files changed, 111 insertions, 42 deletions
diff --git a/program/include/main.inc b/program/include/main.inc
index efcb60e78..f3f1a970d 100644
--- a/program/include/main.inc
+++ b/program/include/main.inc
@@ -1764,4 +1764,3 @@ function log_bug($arg_arr)
flush();
}
}
-
diff --git a/program/include/rcmail.php b/program/include/rcmail.php
index 9fe9430bd..9b5a498b6 100644
--- a/program/include/rcmail.php
+++ b/program/include/rcmail.php
@@ -587,7 +587,7 @@ class rcmail
if ($a_host['host']) {
$host = $a_host['host'];
$imap_ssl = (isset($a_host['scheme']) && in_array($a_host['scheme'], array('ssl','imaps','tls'))) ? $a_host['scheme'] : null;
- if(!empty($a_host['port']))
+ if (!empty($a_host['port']))
$imap_port = $a_host['port'];
else if ($imap_ssl && $imap_ssl != 'tls' && (!$config['default_port'] || $config['default_port'] == 143))
$imap_port = 993;
@@ -618,6 +618,12 @@ class rcmail
if (!$this->imap)
$this->imap_init();
+ // Here we need IDNA ASCII
+ // Only rcube_contacts class is using domain names in Unicode
+ $host = idn_to_ascii($host);
+ if (strpos($username, '@'))
+ $username = idn_to_ascii($username);
+
// try IMAP login
if (!($imap_login = $this->imap->connect($host, $username, $pass, $imap_port, $imap_ssl))) {
// lowercase username if it's an e-mail address (#1484473)
diff --git a/program/include/rcube_config.php b/program/include/rcube_config.php
index 36892c0e1..8020c3912 100644
--- a/program/include/rcube_config.php
+++ b/program/include/rcube_config.php
@@ -274,10 +274,11 @@ class rcube_config
/**
* Return the mail domain configured for the given host
*
- * @param string IMAP host
+ * @param string IMAP host
+ * @param boolean If true, domain name will be converted to IDN ASCII
* @return string Resolved SMTP host
*/
- public function mail_domain($host)
+ public function mail_domain($host, $encode=true)
{
$domain = $host;
@@ -288,6 +289,9 @@ class rcube_config
else if (!empty($this->prop['mail_domain']))
$domain = rcube_parse_host($this->prop['mail_domain']);
+ if ($encode)
+ $domain = idn_to_ascii($domain);
+
return $domain;
}
diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php
index 6f1294385..62996e2cd 100644
--- a/program/include/rcube_imap.php
+++ b/program/include/rcube_imap.php
@@ -3505,7 +3505,7 @@ class rcube_imap
$address = trim($val['address']);
$name = trim($val['name']);
- if (preg_match('/^[\'"]/', $name) && preg_match('/[\'"]$/', $name))
+ if ($name && preg_match('/^[\'"]/', $name) && preg_match('/[\'"]$/', $name))
$name = trim($name, '\'"');
if ($name && $address && $name != $address)
@@ -3515,7 +3515,8 @@ class rcube_imap
else if ($name)
$string = $name;
- $out[$j] = array('name' => $name,
+ $out[$j] = array(
+ 'name' => $name,
'mailto' => $address,
'string' => $string
);
@@ -3912,9 +3913,9 @@ class rcube_imap
$result[$key]['name'] .= (empty($result[$key]['name'])?'':' ').str_replace("\"",'',stripslashes($v));
}
- if (empty($result[$key]['name']))
- $result[$key]['name'] = $result[$key]['address'];
- elseif (empty($result[$key]['address']))
+// if (empty($result[$key]['name']))
+// $result[$key]['name'] = $result[$key]['address'];
+ if (empty($result[$key]['address']))
$result[$key]['address'] = $result[$key]['name'];
}
diff --git a/program/include/rcube_ldap.php b/program/include/rcube_ldap.php
index fb1396c2a..9d451df45 100644
--- a/program/include/rcube_ldap.php
+++ b/program/include/rcube_ldap.php
@@ -99,7 +99,7 @@ class rcube_ldap extends rcube_addressbook
foreach ($this->prop['hosts'] as $host)
{
- $host = rcube_parse_host($host);
+ $host = idn_to_ascii(rcube_parse_host($host));
$this->_debug("C: Connect [$host".($this->prop['port'] ? ':'.$this->prop['port'] : '')."]");
if ($lc = @ldap_connect($host, $this->prop['port']))
diff --git a/program/include/rcube_shared.inc b/program/include/rcube_shared.inc
index 575a28ae0..fb4a959f6 100644
--- a/program/include/rcube_shared.inc
+++ b/program/include/rcube_shared.inc
@@ -680,3 +680,51 @@ if (!extension_loaded('mbstring'))
}
}
+/**
+ * intl replacement functions
+ */
+
+if (!function_exists('idn_to_utf8'))
+{
+ function idn_to_utf8($domain, $flags=null)
+ {
+ static $idn, $loaded;
+
+ if (!$loaded) {
+ $idn = new Net_IDNA2();
+ $loaded = true;
+ }
+
+ if ($idn && $domain && preg_match('/(^|@|\.)xn--/i', $domain)) {
+ try {
+ $domain = $idn->decode($domain);
+ }
+ catch (Exception $e) {
+ }
+ }
+ return $domain;
+ }
+}
+
+if (!function_exists('idn_to_ascii'))
+{
+ function idn_to_ascii($domain, $flags=null)
+ {
+ static $idn, $loaded;
+
+ if (!$loaded) {
+ $idn = new Net_IDNA2();
+ $loaded = true;
+ }
+
+ if ($idn && $domain && preg_match('/[^\x20-\x7E]/', $domain)) {
+ try {
+ $domain = $idn->encode($domain);
+ }
+ catch (Exception $e) {
+ }
+ }
+ return $domain;
+ }
+}
+
diff --git a/program/include/rcube_smtp.php b/program/include/rcube_smtp.php
index 3c9f66977..b45747661 100644
--- a/program/include/rcube_smtp.php
+++ b/program/include/rcube_smtp.php
@@ -98,6 +98,9 @@ class rcube_smtp
else
$helo_host = 'localhost';
+ // IDNA Support
+ $smtp_host = idn_to_ascii($smtp_host);
+
$this->conn = new Net_SMTP($smtp_host, $smtp_port, $helo_host);
if($RCMAIL->config->get('smtp_debug'))
@@ -116,10 +119,14 @@ class rcube_smtp
$smtp_user = str_replace('%u', $_SESSION['username'], $CONFIG['smtp_user']);
$smtp_pass = str_replace('%p', $RCMAIL->decrypt($_SESSION['password']), $CONFIG['smtp_pass']);
$smtp_auth_type = empty($CONFIG['smtp_auth_type']) ? NULL : $CONFIG['smtp_auth_type'];
-
+
// attempt to authenticate to the SMTP server
if ($smtp_user && $smtp_pass)
{
+ // IDNA Support
+ if (strpos($smtp_user, '@'))
+ $smtp_user = idn_to_ascii($smtp_user);
+
$result = $this->conn->auth($smtp_user, $smtp_pass, $smtp_auth_type, $use_tls);
if (PEAR::isError($result))
diff --git a/program/include/rcube_template.php b/program/include/rcube_template.php
index 4dcabb9a1..d923c6478 100755
--- a/program/include/rcube_template.php
+++ b/program/include/rcube_template.php
@@ -994,15 +994,19 @@ class rcube_template extends rcube_html_page
return $username;
}
+ // Current username is an e-mail address
+ if (strpos($_SESSION['username'], '@')) {
+ $username = $_SESSION['username'];
+ }
// get e-mail address from default identity
- if ($sql_arr = $this->app->user->get_identity()) {
+ else if ($sql_arr = $this->app->user->get_identity()) {
$username = $sql_arr['email'];
}
else {
$username = $this->app->user->get_username();
}
- return $username;
+ return idn_to_utf8($username);
}
diff --git a/program/include/rcube_user.php b/program/include/rcube_user.php
index 6a222e296..abd53134c 100644
--- a/program/include/rcube_user.php
+++ b/program/include/rcube_user.php
@@ -44,7 +44,7 @@ class rcube_user
function __construct($id = null, $sql_arr = null)
{
$this->db = rcmail::get_instance()->get_dbh();
-
+
if ($id && !$sql_arr) {
$sql_result = $this->db->query(
"SELECT * FROM ".get_table_name('users')." WHERE user_id = ?", $id);
@@ -121,14 +121,14 @@ class rcube_user
{
if (!$this->ID)
return false;
-
+
$config = rcmail::get_instance()->config;
$old_prefs = (array)$this->get_prefs();
// merge (partial) prefs array with existing settings
$save_prefs = $a_user_prefs + $old_prefs;
unset($save_prefs['language']);
-
+
// don't save prefs with default values if they haven't been changed yet
foreach ($a_user_prefs as $key => $value) {
if (!isset($old_prefs[$key]) && ($value == $config->get($key)))
@@ -186,11 +186,11 @@ class rcube_user
($sql_add ? " ".$sql_add : "").
" ORDER BY ".$this->db->quoteIdentifier('standard')." DESC, name ASC, identity_id ASC",
$this->ID);
-
+
while ($sql_arr = $this->db->fetch_assoc($sql_result)) {
$result[] = $sql_arr;
}
-
+
return $result;
}
@@ -208,7 +208,7 @@ class rcube_user
return false;
$query_cols = $query_params = array();
-
+
foreach ((array)$data as $col => $value) {
$query_cols[] = $this->db->quoteIdentifier($col) . ' = ?';
$query_params[] = $value;
@@ -224,11 +224,11 @@ class rcube_user
call_user_func_array(array($this->db, 'query'),
array_merge(array($sql), $query_params));
-
+
return $this->db->affected_rows();
}
-
-
+
+
/**
* Create a new identity record linked with this user
*
@@ -259,8 +259,8 @@ class rcube_user
return $this->db->insert_id('identities');
}
-
-
+
+
/**
* Mark the given identity as deleted
*
@@ -282,7 +282,7 @@ class rcube_user
// we'll not delete last identity
if ($sql_arr['ident_count'] <= 1)
return false;
-
+
$this->db->query(
"UPDATE ".get_table_name('identities').
" SET del = 1, changed = ".$this->db->now().
@@ -293,8 +293,8 @@ class rcube_user
return $this->db->affected_rows();
}
-
-
+
+
/**
* Make this identity the default one for this user
*
@@ -313,8 +313,8 @@ class rcube_user
$iid);
}
}
-
-
+
+
/**
* Update user's last_login timestamp
*/
@@ -328,8 +328,8 @@ class rcube_user
$this->ID);
}
}
-
-
+
+
/**
* Clear the saved object state
*/
@@ -338,8 +338,8 @@ class rcube_user
$this->ID = null;
$this->data = null;
}
-
-
+
+
/**
* Find a user record matching the given name and host
*
@@ -350,25 +350,25 @@ class rcube_user
static function query($user, $host)
{
$dbh = rcmail::get_instance()->get_dbh();
-
+
// query for matching user name
$query = "SELECT * FROM ".get_table_name('users')." WHERE mail_host = ? AND %s = ?";
$sql_result = $dbh->query(sprintf($query, 'username'), $host, $user);
-
+
// query for matching alias
if (!($sql_arr = $dbh->fetch_assoc($sql_result))) {
$sql_result = $dbh->query(sprintf($query, 'alias'), $host, $user);
$sql_arr = $dbh->fetch_assoc($sql_result);
}
-
+
// user already registered -> overwrite username
if ($sql_arr)
return new rcube_user($sql_arr['user_id'], $sql_arr);
else
return false;
}
-
-
+
+
/**
* Create a new user record and return a rcube_user instance
*
@@ -448,7 +448,7 @@ class rcube_user
$plugin = $rcmail->plugins->exec_hook('identity_create',
array('login' => true, 'record' => $record));
-
+
if (!$plugin['abort'] && $plugin['record']['email']) {
$rcmail->user->insert_identity($plugin['record']);
}
@@ -463,11 +463,11 @@ class rcube_user
'file' => __FILE__,
'message' => "Failed to create new user"), true, false);
}
-
+
return $user_id ? $user_instance : false;
}
-
-
+
+
/**
* Resolve username using a virtuser plugins
*