alecpl
2012-01-04 e2c9ab4df80ec9077408e59531a6f8d1baae53e4
- Fix strict email address searching if contact has more than one address


2 files modified
58 ■■■■■ changed files
CHANGELOG 1 ●●●● patch | view | raw | blame | history
program/include/rcube_contacts.php 57 ●●●●● patch | view | raw | blame | history
CHANGELOG
@@ -1,6 +1,7 @@
CHANGELOG Roundcube Webmail
===========================
- Fix strict email address searching if contact has more than one address
- Use proper timezones from PHP's internal timezonedb (#1485592)
- Add separate pagesize setting for mail messages and contacts (#1488269)
- Fix handling of INBOX's subfolders in special folders config (#1488279)
program/include/rcube_contacts.php
@@ -62,6 +62,8 @@
      'gender', 'maidenname', 'spouse', 'email', 'phone', 'address',
      'birthday', 'anniversary', 'website', 'im', 'notes', 'photo');
    const SEPARATOR = ',';
    /**
     * Object constructor
@@ -232,8 +234,10 @@
            if ($read_vcard)
                $sql_arr = $this->convert_db_data($sql_arr);
            else
                $sql_arr['email'] = preg_split('/,\s*/', $sql_arr['email']);
            else {
                $sql_arr['email'] = explode(self::SEPARATOR, $sql_arr['email']);
                $sql_arr['email'] = array_map('trim', $sql_arr['email']);
            }
            // make sure we have a name to display
            if (empty($sql_arr['name'])) {
@@ -287,11 +291,13 @@
        $where = $and_where = array();
        $mode = intval($mode);
        $WS = ' ';
        $AS = self::SEPARATOR;
        foreach ($fields as $idx => $col) {
            // direct ID search
            if ($col == 'ID' || $col == $this->primary_key) {
                $ids     = !is_array($value) ? explode(',', $value) : $value;
                $ids     = !is_array($value) ? explode(self::SEPARATOR, $value) : $value;
                $ids     = $this->db->array2list($ids, 'integer');
                $where[] = 'c.' . $this->primary_key.' IN ('.$ids.')';
                continue;
@@ -299,16 +305,16 @@
            // fulltext search in all fields
            else if ($col == '*') {
                $words = array();
                foreach (explode(" ", self::normalize_string($value)) as $word) {
                foreach (explode($WS, self::normalize_string($value)) as $word) {
                    switch ($mode) {
                    case 1: // strict
                        $words[] = '(' . $this->db->ilike('words', $word.' %')
                            . ' OR ' . $this->db->ilike('words', '% '.$word.' %')
                            . ' OR ' . $this->db->ilike('words', '% '.$word) . ')';
                            . ' OR ' . $this->db->ilike('words', '%' . $WS . $word . $WS . '%')
                            . ' OR ' . $this->db->ilike('words', '%' . $WS . $word) . ')';
                        break;
                    case 2: // prefix
                        $words[] = '(' . $this->db->ilike('words', $word.'%')
                            . ' OR ' . $this->db->ilike('words', '% '.$word.'%') . ')';
                            . ' OR ' . $this->db->ilike('words', '%' . $WS . $word . '%') . ')';
                        break;
                    default: // partial
                        $words[] = $this->db->ilike('words', '%'.$word.'%');
@@ -322,10 +328,14 @@
                if (in_array($col, $this->table_cols)) {
                    switch ($mode) {
                    case 1: // strict
                        $where[] = $this->db->quoteIdentifier($col).' = '.$this->db->quote($val);
                        $where[] = '(' . $this->db->quoteIdentifier($col) . ' = ' . $this->db->quote($val)
                            . ' OR ' . $this->db->ilike($col, $val . $AS . '%')
                            . ' OR ' . $this->db->ilike($col, '%' . $AS . $val . $AS . '%')
                            . ' OR ' . $this->db->ilike($col, '%' . $AS . $val) . ')';
                        break;
                    case 2: // prefix
                        $where[] = $this->db->ilike($col, $val.'%');
                        $where[] = '(' . $this->db->ilike($col, $val . '%')
                            . ' OR ' . $this->db->ilike($col, $AS . $val . '%') . ')';
                        break;
                    default: // partial
                        $where[] = $this->db->ilike($col, '%'.$val.'%');
@@ -337,13 +347,13 @@
                        foreach (explode(" ", self::normalize_string($val)) as $word) {
                            switch ($mode) {
                            case 1: // strict
                                $words[] = '(' . $this->db->ilike('words', $word.' %')
                                    . ' OR ' . $this->db->ilike('words', '% '.$word.' %')
                                    . ' OR ' . $this->db->ilike('words', '% '.$word) . ')';
                                $words[] = '(' . $this->db->ilike('words', $word . $WS . '%')
                                    . ' OR ' . $this->db->ilike('words', '%' . $AS . $word . $WS .'%')
                                    . ' OR ' . $this->db->ilike('words', '%' . $AS . $word) . ')';
                                break;
                            case 2: // prefix
                                $words[] = '(' . $this->db->ilike('words', $word.'%')
                                    . ' OR ' . $this->db->ilike('words', ' '.$word.'%') . ')';
                                    . ' OR ' . $this->db->ilike('words', $AS . $word . '%') . ')';
                                break;
                            default: // partial
                                $words[] = $this->db->ilike('words', '%'.$word.'%');
@@ -687,7 +697,8 @@
        }
        else {
            $record += $sql_arr;
            $record['email'] = preg_split('/,\s*/', $record['email']);
            $record['email'] = explode(self::SEPARATOR, $record['email']);
            $record['email'] = array_map('trim', $record['email']);
        }
        return $record;
@@ -720,12 +731,16 @@
            $key = $col;
            if (!isset($save_data[$key]))
                $key .= ':home';
            if (isset($save_data[$key]))
                $out[$col] = is_array($save_data[$key]) ? join(',', $save_data[$key]) : $save_data[$key];
            if (isset($save_data[$key])) {
                if (is_array($save_data[$key]))
                    $out[$col] = join(self::SEPARATOR, $save_data[$key]);
                else
                    $out[$col] = $save_data[$key];
            }
        }
        // save all e-mails in database column
        $out['email'] = join(", ", $vcard->email);
        $out['email'] = join(self::SEPARATOR, $vcard->email);
        // join words for fulltext search
        $out['words'] = join(" ", array_unique(explode(" ", $words)));
@@ -743,7 +758,7 @@
    function delete($ids, $force=true)
    {
        if (!is_array($ids))
            $ids = explode(',', $ids);
            $ids = explode(self::SEPARATOR, $ids);
        $ids = $this->db->array2list($ids, 'integer');
@@ -770,7 +785,7 @@
    function undelete($ids)
    {
        if (!is_array($ids))
            $ids = explode(',', $ids);
            $ids = explode(self::SEPARATOR, $ids);
        $ids = $this->db->array2list($ids, 'integer');
@@ -887,7 +902,7 @@
    function add_to_group($group_id, $ids)
    {
        if (!is_array($ids))
            $ids = explode(',', $ids);
            $ids = explode(self::SEPARATOR, $ids);
        $added = 0;
        $exists = array();
@@ -932,7 +947,7 @@
    function remove_from_group($group_id, $ids)
    {
        if (!is_array($ids))
            $ids = explode(',', $ids);
            $ids = explode(self::SEPARATOR, $ids);
        $ids = $this->db->array2list($ids, 'integer');