Ticket #1486750: virtuser_query.patch

File virtuser_query.patch, 5.0 KB (added by steffenvogel, 3 years ago)

my patch

Line 
1*** virtuser_query.php  2010-04-23 11:25:22.000000000 +0200
2--- virtuser_query.php.new      2010-05-22 16:37:10.000000000 +0200
3***************
4*** 4,19 ****
5   * DB based User-to-Email and Email-to-User lookup
6   *
7   * Add it to the plugins list in config/main.inc.php and set
8!  * SQL query to resolve user names and e-mail addresses from the database
9   * %u will be replaced with the current username for login.
10!  * The query should select the user's e-mail address as first column
11!  * and optional identity data columns in specified order:
12   *    name, organization, reply-to, bcc, signature, html_signature
13   *
14!  * $rcmail_config['virtuser_query'] = '';
15   *
16!  * @version 1.0
17   * @author Aleksander Machniak
18   */
19  class virtuser_query extends rcube_plugin
20  {
21--- 4,21 ----
22   * DB based User-to-Email and Email-to-User lookup
23   *
24   * Add it to the plugins list in config/main.inc.php and set
25!  * SQL queries to resolve usernames, e-mail addresses and hostnames from the database
26   * %u will be replaced with the current username for login.
27!  * %m will be replaced with the current e-mail address for login.
28!  * The query should select the user's e-mail address, username or the imap hostname as first column
29!  * The email query could optionally select identity data columns in specified order:
30   *    name, organization, reply-to, bcc, signature, html_signature
31   *
32!  * $rcmail_config['virtuser_query'] = array('user' => '', 'email' => '', 'host' => '');
33   *
34!  * @version 1.1
35   * @author Aleksander Machniak
36+  * @author Steffen Vogel
37   */
38  class virtuser_query extends rcube_plugin
39  {
40***************
41*** 22,34 ****
42 
43      function init()
44      {
45!           $this->app = rcmail::get_instance();
46!           $this->query = $this->app->config->get('virtuser_query');
47 
48!           if ($this->query) {
49!               $this->add_hook('user2email', array($this, 'user2email'));
50! //            $this->add_hook('email2user', array($this, 'email2user'));
51!           }
52      }
53 
54      /**
55--- 24,48 ----
56 
57      function init()
58      {
59!       $this->app = rcmail::get_instance();
60!       $this->config = $this->app->config->get('virtuser_query');
61 
62!       if (is_array($this->config)) {
63!               if ($this->config['email']) {
64!                   $this->add_hook('user2email', array($this, 'user2email'));
65!               }
66!       
67!               if ($this->config['user']) {
68!                   $this->add_hook('email2user', array($this, 'email2user'));
69!               }
70!       
71!               if ($this->config['host']) {
72!                   $this->add_hook('authenticate', array($this, 'user2host'));
73!               }
74!       }
75!       elseif (is_string($this->config)) {
76!               $this->add_hook('user2email', array($this, 'user2email'));
77!       }
78      }
79 
80      /**
81***************
82*** 36,70 ****
83       */
84      function user2email($p)
85      {
86!           $dbh = $this->app->get_dbh();
87 
88!           $sql_result = $dbh->query(preg_replace('/%u/', $dbh->escapeSimple($p['user']), $this->query));
89 
90!           while ($sql_arr = $dbh->fetch_array($sql_result)) {
91!               if (strpos($sql_arr[0], '@')) {
92!                       if ($p['extended'] && count($sql_arr) > 1) {
93!                           $result[] = array(
94!                                   'email'         => $sql_arr[0],
95!                               'name'              => $sql_arr[1],
96!                                   'organization'  => $sql_arr[2],
97!                               'reply-to'          => $sql_arr[3],
98!                                   'bcc'                   => $sql_arr[4],
99!                                   'signature'         => $sql_arr[5],
100!                               'html_signature' => (int)$sql_arr[6],
101!                       );
102!                       }
103!                       else {
104!                           $result[] = $sql_arr[0];
105!                       }
106!
107!                       if ($p['first'])
108!                           break;
109!               }
110            }
111       
112!           $p['email'] = $result;
113 
114!           return $p;
115      }
116 
117  }
118--- 50,115 ----
119       */
120      function user2email($p)
121      {
122!       $dbh = $this->app->get_dbh();
123 
124!       $sql_result = $dbh->query(preg_replace('/%u/', $dbh->escapeSimple($p['user']), $this->config['email']));
125 
126!       while ($sql_arr = $dbh->fetch_array($sql_result)) {
127!           if (strpos($sql_arr[0], '@')) {
128!               if ($p['extended'] && count($sql_arr) > 1) {
129!                   $result[] = array(
130!                       'email'         => $sql_arr[0],
131!                       'name'          => $sql_arr[1],
132!                       'organization'  => $sql_arr[2],
133!                       'reply-to'      => $sql_arr[3],
134!                       'bcc'           => $sql_arr[4],
135!                       'signature'     => $sql_arr[5],
136!                       'html_signature' => (int)$sql_arr[6],
137!                   );
138!               }
139!               else {
140!                   $result[] = $sql_arr[0];
141!               }
142!
143!               if ($p['first'])
144!                   break;
145            }
146+       }
147       
148!       $p['email'] = $result;
149 
150!       return $p;
151      }
152 
153+     /**
154+      * EMail > User
155+      */
156+     function email2user($p)
157+     {
158+       $dbh = $this->app->get_dbh();
159+
160+       $sql_result = $dbh->query(preg_replace('/%m/', $dbh->escapeSimple($p['email']), $this->config['user']));
161+
162+       if ($sql_arr = $dbh->fetch_array($sql_result)) {
163+               $p['user'] = $sql_arr[0];
164+       }
165+
166+       return $p;
167+     }
168+
169+     /**
170+      * User > Host
171+      */
172+     function user2host($p)
173+     {
174+       $dbh = $this->app->get_dbh();
175+
176+       $sql_result = $dbh->query(preg_replace('/%u/', $dbh->escapeSimple($p['user']), $this->config['host']));
177+
178+       if ($sql_arr = $dbh->fetch_array($sql_result)) {
179+               $p['host'] = $sql_arr[0];
180+       }
181+
182+       return $p;
183+     }
184  }