4 * DB based User-to-Email and Email-to-User lookup
6 * Add it to the plugins list in config/main.inc.php and set
7 * SQL queries to resolve usernames, e-mail addresses and hostnames from the database
8 * %u will be replaced with the current username for login.
9 * %m will be replaced with the current e-mail address for login.
11 * Queries should select the user's e-mail address, username or the imap hostname as first column
12 * The email query could optionally select identity data columns in specified order:
13 * name, organization, reply-to, bcc, signature, html_signature
15 * $rcmail_config['virtuser_query'] = array('email' => '', 'user' => '', 'host' => '');
18 * @author Aleksander Machniak
19 * @author Steffen Vogel
21 class virtuser_query extends rcube_plugin
28 $this->app = rcmail::get_instance();
29 $this->config = $this->app->config->get('virtuser_query');
31 if (!empty($this->config)) {
32 if (is_string($this->config)) {
33 $this->config = array('email' => $this->config);
36 if ($this->config['email']) {
37 $this->add_hook('user2email', array($this, 'user2email'));
39 if ($this->config['user']) {
40 $this->add_hook('email2user', array($this, 'email2user'));
42 if ($this->config['host']) {
43 $this->add_hook('authenticate', array($this, 'user2host'));
51 function user2email($p)
53 $dbh = $this->app->get_dbh();
55 $sql_result = $dbh->query(preg_replace('/%u/', $dbh->escapeSimple($p['user']), $this->config['email']));
57 while ($sql_arr = $dbh->fetch_array($sql_result)) {
58 if (strpos($sql_arr[0], '@')) {
59 if ($p['extended'] && count($sql_arr) > 1) {
61 'email' => idn_to_ascii($sql_arr[0]),
62 'name' => $sql_arr[1],
63 'organization' => $sql_arr[2],
64 'reply-to' => idn_to_ascii($sql_arr[3]),
65 'bcc' => idn_to_ascii($sql_arr[4]),
66 'signature' => $sql_arr[5],
67 'html_signature' => (int)$sql_arr[6],
71 $result[] = $sql_arr[0];
79 $p['email'] = $result;
87 function email2user($p)
89 $dbh = $this->app->get_dbh();
91 $sql_result = $dbh->query(preg_replace('/%m/', $dbh->escapeSimple($p['email']), $this->config['user']));
93 if ($sql_arr = $dbh->fetch_array($sql_result)) {
94 $p['user'] = $sql_arr[0];
103 function user2host($p)
105 $dbh = $this->app->get_dbh();
107 $sql_result = $dbh->query(preg_replace('/%u/', $dbh->escapeSimple($p['user']), $this->config['host']));
109 if ($sql_arr = $dbh->fetch_array($sql_result)) {
110 $p['host'] = $sql_arr[0];