Changeset 5708 in subversion


Ignore:
Timestamp:
Jan 4, 2012 8:32:14 AM (17 months ago)
Author:
alec
Message:
  • Fix strict email address searching if contact has more than one address
Location:
trunk/roundcubemail
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/CHANGELOG

    r5707 r5708  
    22=========================== 
    33 
     4- Fix strict email address searching if contact has more than one address 
    45- Use proper timezones from PHP's internal timezonedb (#1485592) 
    56- Add separate pagesize setting for mail messages and contacts (#1488269) 
  • trunk/roundcubemail/program/include/rcube_contacts.php

    r5406 r5708  
    6363      'birthday', 'anniversary', 'website', 'im', 'notes', 'photo'); 
    6464 
     65    const SEPARATOR = ','; 
     66 
    6567 
    6668    /** 
     
    233235            if ($read_vcard) 
    234236                $sql_arr = $this->convert_db_data($sql_arr); 
    235             else 
    236                 $sql_arr['email'] = preg_split('/,\s*/', $sql_arr['email']); 
     237            else { 
     238                $sql_arr['email'] = explode(self::SEPARATOR, $sql_arr['email']); 
     239                $sql_arr['email'] = array_map('trim', $sql_arr['email']); 
     240            } 
    237241 
    238242            // make sure we have a name to display 
     
    288292        $where = $and_where = array(); 
    289293        $mode = intval($mode); 
     294        $WS = ' '; 
     295        $AS = self::SEPARATOR; 
    290296 
    291297        foreach ($fields as $idx => $col) { 
    292298            // direct ID search 
    293299            if ($col == 'ID' || $col == $this->primary_key) { 
    294                 $ids     = !is_array($value) ? explode(',', $value) : $value; 
     300                $ids     = !is_array($value) ? explode(self::SEPARATOR, $value) : $value; 
    295301                $ids     = $this->db->array2list($ids, 'integer'); 
    296302                $where[] = 'c.' . $this->primary_key.' IN ('.$ids.')'; 
     
    300306            else if ($col == '*') { 
    301307                $words = array(); 
    302                 foreach (explode(" ", self::normalize_string($value)) as $word) { 
     308                foreach (explode($WS, self::normalize_string($value)) as $word) { 
    303309                    switch ($mode) { 
    304310                    case 1: // strict 
    305                         $words[] = '(' . $this->db->ilike('words', $word.' %') 
    306                             . ' OR ' . $this->db->ilike('words', '% '.$word.' %') 
    307                             . ' OR ' . $this->db->ilike('words', '% '.$word) . ')'; 
     311                        $words[] = '(' . $this->db->ilike('words', $word . '%') 
     312                            . ' OR ' . $this->db->ilike('words', '%' . $WS . $word . $WS . '%') 
     313                            . ' OR ' . $this->db->ilike('words', '%' . $WS . $word) . ')'; 
    308314                        break; 
    309315                    case 2: // prefix 
    310                         $words[] = '(' . $this->db->ilike('words', $word.'%') 
    311                             . ' OR ' . $this->db->ilike('words', '% '.$word.'%') . ')'; 
     316                        $words[] = '(' . $this->db->ilike('words', $word . '%') 
     317                            . ' OR ' . $this->db->ilike('words', '%' . $WS . $word . '%') . ')'; 
    312318                        break; 
    313319                    default: // partial 
    314                         $words[] = $this->db->ilike('words', '%'.$word.'%'); 
     320                        $words[] = $this->db->ilike('words', '%' . $word . '%'); 
    315321                    } 
    316322                } 
     
    323329                    switch ($mode) { 
    324330                    case 1: // strict 
    325                         $where[] = $this->db->quoteIdentifier($col).' = '.$this->db->quote($val); 
     331                        $where[] = '(' . $this->db->quoteIdentifier($col) . ' = ' . $this->db->quote($val) 
     332                            . ' OR ' . $this->db->ilike($col, $val . $AS . '%') 
     333                            . ' OR ' . $this->db->ilike($col, '%' . $AS . $val . $AS . '%') 
     334                            . ' OR ' . $this->db->ilike($col, '%' . $AS . $val) . ')'; 
    326335                        break; 
    327336                    case 2: // prefix 
    328                         $where[] = $this->db->ilike($col, $val.'%'); 
     337                        $where[] = '(' . $this->db->ilike($col, $val . '%') 
     338                            . ' OR ' . $this->db->ilike($col, $AS . $val . '%') . ')'; 
    329339                        break; 
    330340                    default: // partial 
    331                         $where[] = $this->db->ilike($col, '%'.$val.'%'); 
     341                        $where[] = $this->db->ilike($col, '%' . $val . '%'); 
    332342                    } 
    333343                } 
     
    338348                            switch ($mode) { 
    339349                            case 1: // strict 
    340                                 $words[] = '(' . $this->db->ilike('words', $word.' %') 
    341                                     . ' OR ' . $this->db->ilike('words', '% '.$word.' %') 
    342                                     . ' OR ' . $this->db->ilike('words', '% '.$word) . ')'; 
     350                                $words[] = '(' . $this->db->ilike('words', $word . $WS . '%') 
     351                                    . ' OR ' . $this->db->ilike('words', '%' . $AS . $word . $WS .'%') 
     352                                    . ' OR ' . $this->db->ilike('words', '%' . $AS . $word) . ')'; 
    343353                                break; 
    344354                            case 2: // prefix 
    345                                 $words[] = '(' . $this->db->ilike('words', $word.'%') 
    346                                     . ' OR ' . $this->db->ilike('words', ' '.$word.'%') . ')'; 
     355                                $words[] = '(' . $this->db->ilike('words', $word . '%') 
     356                                    . ' OR ' . $this->db->ilike('words', $AS . $word . '%') . ')'; 
    347357                                break; 
    348358                            default: // partial 
    349                                 $words[] = $this->db->ilike('words', '%'.$word.'%'); 
     359                                $words[] = $this->db->ilike('words', '%' . $word . '%'); 
    350360                            } 
    351361                        } 
     
    688698        else { 
    689699            $record += $sql_arr; 
    690             $record['email'] = preg_split('/,\s*/', $record['email']); 
     700            $record['email'] = explode(self::SEPARATOR, $record['email']); 
     701            $record['email'] = array_map('trim', $record['email']); 
    691702        } 
    692703 
     
    721732            if (!isset($save_data[$key])) 
    722733                $key .= ':home'; 
    723             if (isset($save_data[$key])) 
    724                 $out[$col] = is_array($save_data[$key]) ? join(',', $save_data[$key]) : $save_data[$key]; 
     734            if (isset($save_data[$key])) { 
     735                if (is_array($save_data[$key])) 
     736                    $out[$col] = join(self::SEPARATOR, $save_data[$key]); 
     737                else 
     738                    $out[$col] = $save_data[$key]; 
     739            } 
    725740        } 
    726741 
    727742        // save all e-mails in database column 
    728         $out['email'] = join(", ", $vcard->email); 
     743        $out['email'] = join(self::SEPARATOR, $vcard->email); 
    729744 
    730745        // join words for fulltext search 
     
    744759    { 
    745760        if (!is_array($ids)) 
    746             $ids = explode(',', $ids); 
     761            $ids = explode(self::SEPARATOR, $ids); 
    747762 
    748763        $ids = $this->db->array2list($ids, 'integer'); 
     
    771786    { 
    772787        if (!is_array($ids)) 
    773             $ids = explode(',', $ids); 
     788            $ids = explode(self::SEPARATOR, $ids); 
    774789 
    775790        $ids = $this->db->array2list($ids, 'integer'); 
     
    888903    { 
    889904        if (!is_array($ids)) 
    890             $ids = explode(',', $ids); 
     905            $ids = explode(self::SEPARATOR, $ids); 
    891906 
    892907        $added = 0; 
     
    933948    { 
    934949        if (!is_array($ids)) 
    935             $ids = explode(',', $ids); 
     950            $ids = explode(self::SEPARATOR, $ids); 
    936951 
    937952        $ids = $this->db->array2list($ids, 'integer'); 
Note: See TracChangeset for help on using the changeset viewer.