Changeset 56505a1 in github


Ignore:
Timestamp:
Mar 11, 2010 1:34:01 PM (3 years ago)
Author:
alecpl <alec@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
bc404ff
Parents:
a4cf457
Message:
  • Options virtuser_* replaced with virtuser_* plugins
  • Plugin API: Implemented 'email2user' and 'user2email' hooks
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • CHANGELOG

    ra4cf457 r56505a1  
    22=========================== 
    33 
     4- Options virtuser_* replaced with virtuser_* plugins 
     5- Plugin API: Implemented 'email2user' and 'user2email' hooks 
    46- Fix forwarding message omits CC header (#1486305) 
    57- Add 'default_charset' option to user preferences (#1485451) 
  • config/main.inc.php.dist

    re55ab02 r56505a1  
    167167// Specify an array with 'host' => 'domain' values to support multiple hosts 
    168168$rcmail_config['mail_domain'] = ''; 
    169  
    170 // Path to a virtuser table file to resolve user names and e-mail addresses 
    171 $rcmail_config['virtuser_file'] = ''; 
    172  
    173 // Query to resolve user names and e-mail addresses from the database 
    174 // %u will be replaced with the current username for login. 
    175 // The query should select the user's e-mail address as first column 
    176 // and optional identity name as second column 
    177 $rcmail_config['virtuser_query'] = ''; 
    178169 
    179170// Password charset. 
  • program/include/rcube_user.php

    r929a508 r56505a1  
    448448   
    449449  /** 
    450    * Resolve username using a virtuser file 
     450   * Resolve username using a virtuser plugins 
    451451   * 
    452452   * @param string E-mail address to resolve 
     
    455455  static function email2user($email) 
    456456  { 
    457     $r = self::findinvirtual('/^' . preg_quote($email, '/') . '\s/'); 
    458  
    459     for ($i=0; $i<count($r); $i++) 
    460     { 
    461       $data = trim($r[$i]); 
    462       $arr = preg_split('/\s+/', $data); 
    463       if (count($arr) > 0) 
    464         return trim($arr[count($arr)-1]); 
    465     } 
    466  
    467     return NULL; 
    468   } 
    469  
    470  
    471   /** 
    472    * Resolve e-mail address from virtuser file/table 
     457    $rcmail = rcmail::get_instance(); 
     458    $plugin = $rcmail->plugins->exec_hook('email2user', 
     459      array('email' => $email, 'user' => NULL)); 
     460 
     461    return $plugin['user']; 
     462  } 
     463 
     464 
     465  /** 
     466   * Resolve e-mail address from virtuser plugins 
    473467   * 
    474468   * @param string User name 
     
    479473  static function user2email($user, $first=true, $extended=false) 
    480474  { 
    481     $result = array(); 
    482475    $rcmail = rcmail::get_instance(); 
    483     $dbh = $rcmail->get_dbh(); 
    484  
    485     // SQL lookup 
    486     if ($virtuser_query = $rcmail->config->get('virtuser_query')) { 
    487       $sql_result = $dbh->query(preg_replace('/%u/', $dbh->escapeSimple($user), $virtuser_query)); 
    488       while ($sql_arr = $dbh->fetch_array($sql_result)) 
    489         if (strpos($sql_arr[0], '@')) { 
    490           $result[] = ($extended && count($sql_arr) > 1) ? $sql_arr : $sql_arr[0]; 
    491           if ($first) 
    492             return $result[0]; 
    493         } 
    494     } 
    495     // File lookup 
    496     $r = self::findinvirtual('/\s' . preg_quote($user, '/') . '\s*$/'); 
    497     for ($i=0; $i<count($r); $i++) 
    498     { 
    499       $data = $r[$i]; 
    500       $arr = preg_split('/\s+/', $data); 
    501       if (count($arr) > 0 && strpos($arr[0], '@')) 
    502       { 
    503         $result[] = trim(str_replace('\\@', '@', $arr[0])); 
    504  
    505         if ($first) 
    506           return $result[0]; 
    507       } 
    508     } 
    509      
    510     return empty($result) ? NULL : $result; 
    511   } 
    512    
    513    
    514   /** 
    515    * Find matches of the given pattern in virtuser file 
    516    *  
    517    * @param string Regular expression to search for 
    518    * @return array Matching entries 
    519    */ 
    520   private static function findinvirtual($pattern) 
    521   { 
    522     $result = array(); 
    523     $virtual = null; 
    524      
    525     if ($virtuser_file = rcmail::get_instance()->config->get('virtuser_file')) 
    526       $virtual = file($virtuser_file); 
    527      
    528     if (empty($virtual)) 
    529       return $result; 
    530      
    531     // check each line for matches 
    532     foreach ($virtual as $line) 
    533     { 
    534       $line = trim($line); 
    535       if (empty($line) || $line{0}=='#') 
    536         continue; 
    537          
    538       if (preg_match($pattern, $line)) 
    539         $result[] = $line; 
    540     } 
    541      
    542     return $result; 
    543   } 
    544  
     476    $plugin = $rcmail->plugins->exec_hook('user2email', 
     477      array('email' => NULL, 'user' => $user, 
     478        'first' => $first, 'extended' => $extended)); 
     479 
     480    return empty($plugin['email']) ? NULL : $plugin['email']; 
     481  } 
     482   
    545483} 
    546  
    547  
Note: See TracChangeset for help on using the changeset viewer.