| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /** |
|---|
| 4 | * DB based User-to-Email and Email-to-User lookup |
|---|
| 5 | * |
|---|
| 6 | * Add it to the plugins list in config/main.inc.php and set |
|---|
| 7 | * SQL query to resolve user names and e-mail addresses from the database |
|---|
| 8 | * %u will be replaced with the current username for login. |
|---|
| 9 | * The query should select the user's e-mail address as first column |
|---|
| 10 | * and optional identity data columns in specified order: |
|---|
| 11 | * name, organization, reply-to, bcc, signature, html_signature |
|---|
| 12 | * |
|---|
| 13 | * $rcmail_config['virtuser_query'] = ''; |
|---|
| 14 | * |
|---|
| 15 | * @version 1.0 |
|---|
| 16 | * @author Aleksander Machniak |
|---|
| 17 | */ |
|---|
| 18 | class virtuser_query extends rcube_plugin |
|---|
| 19 | { |
|---|
| 20 | private $query; |
|---|
| 21 | private $app; |
|---|
| 22 | |
|---|
| 23 | function init() |
|---|
| 24 | { |
|---|
| 25 | $this->app = rcmail::get_instance(); |
|---|
| 26 | $this->query = $this->app->config->get('virtuser_query'); |
|---|
| 27 | |
|---|
| 28 | if ($this->query) { |
|---|
| 29 | $this->add_hook('user2email', array($this, 'user2email')); |
|---|
| 30 | // $this->add_hook('email2user', array($this, 'email2user')); |
|---|
| 31 | } |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | /** |
|---|
| 35 | * User > Email |
|---|
| 36 | */ |
|---|
| 37 | function user2email($p) |
|---|
| 38 | { |
|---|
| 39 | $dbh = $this->app->get_dbh(); |
|---|
| 40 | |
|---|
| 41 | $sql_result = $dbh->query(preg_replace('/%u/', $dbh->escapeSimple($p['user']), $this->query)); |
|---|
| 42 | |
|---|
| 43 | while ($sql_arr = $dbh->fetch_array($sql_result)) { |
|---|
| 44 | if (strpos($sql_arr[0], '@')) { |
|---|
| 45 | if ($p['extended'] && count($sql_arr) > 1) { |
|---|
| 46 | $result[] = array( |
|---|
| 47 | 'email' => idn_to_ascii($sql_arr[0]), |
|---|
| 48 | 'name' => $sql_arr[1], |
|---|
| 49 | 'organization' => $sql_arr[2], |
|---|
| 50 | 'reply-to' => idn_to_ascii($sql_arr[3]), |
|---|
| 51 | 'bcc' => idn_to_ascii($sql_arr[4]), |
|---|
| 52 | 'signature' => $sql_arr[5], |
|---|
| 53 | 'html_signature' => (int)$sql_arr[6], |
|---|
| 54 | ); |
|---|
| 55 | } |
|---|
| 56 | else { |
|---|
| 57 | $result[] = $sql_arr[0]; |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | if ($p['first']) |
|---|
| 61 | break; |
|---|
| 62 | } |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | $p['email'] = $result; |
|---|
| 66 | |
|---|
| 67 | return $p; |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | } |
|---|