summaryrefslogtreecommitdiff
path: root/program/include
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2012-08-06 11:08:58 +0200
committerAleksander Machniak <alec@alec.pl>2012-08-06 11:08:58 +0200
commit565c472918e7f9707cd8d7909ad5dbcc5a921fdf (patch)
tree8c4c40ab241766d931c69ee3ddcca5b3511cc800 /program/include
parent83121ece3348bfe09bb1026eace79a74a5ccf2c9 (diff)
Removed users.alias column, added option ('user_aliases')
to use email address from identities as username (#1488581)
Diffstat (limited to 'program/include')
-rw-r--r--program/include/rcube_user.php19
1 files changed, 13 insertions, 6 deletions
diff --git a/program/include/rcube_user.php b/program/include/rcube_user.php
index 24ded3d2d..d5421526b 100644
--- a/program/include/rcube_user.php
+++ b/program/include/rcube_user.php
@@ -397,15 +397,22 @@ class rcube_user
*/
static function query($user, $host)
{
- $dbh = rcube::get_instance()->get_dbh();
+ $dbh = rcube::get_instance()->get_dbh();
+ $config = rcube::get_instance()->config;
// query for matching user name
- $query = "SELECT * FROM ".$dbh->table_name('users')." WHERE mail_host = ? AND %s = ?";
- $sql_result = $dbh->query(sprintf($query, 'username'), $host, $user);
+ $sql_result = $dbh->query("SELECT * FROM " . $dbh->table_name('users')
+ ." WHERE mail_host = ? AND username = ?", $host, $user);
+
+ $sql_arr = $dbh->fetch_assoc($sql_result);
+
+ // username not found, try aliases from identities
+ if (empty($sql_arr) && $config->get('user_aliases') && strpos($user, '@')) {
+ $sql_result = $dbh->limitquery("SELECT u.*"
+ ." FROM " . $dbh->table_name('users') . " u"
+ ." JOIN " . $dbh->table_name('identities') . " i ON (i.user_id = u.user_id)"
+ ." WHERE email = ? AND del <> 1", 0, 1, $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);
}