+ }
+ /**** Database backend ****/
+ else if ($rcmail->config->get('squirrelmail_driver') == 'sql') {
+ $this->prefs = array();
+
+ /* connect to squirrelmail database */
+ $db = new rcube_mdb2($rcmail->config->get('squirrelmail_dsn'));
+ $db->db_connect('r'); // connect in read mode
+
+ // $db->set_debug(true);
+
+ /* retrieve prefs */
+ $userprefs_table = $rcmail->config->get('squirrelmail_userprefs_table');
+ $address_table = $rcmail->config->get('squirrelmail_address_table');
+ $db_charset = $rcmail->config->get('squirrelmail_db_charset');
+
+ if ($db_charset)
+ $db->query('SET NAMES '.$db_charset);
+
+ $sql_result = $db->query('SELECT * FROM '.$userprefs_table.' WHERE user=?', $uname); // ? is replaced with emailaddress
+
+ while ($sql_array = $db->fetch_assoc($sql_result) ) { // fetch one row from result
+ $this->prefs[$sql_array['prefkey']] = rcube_charset_convert(rtrim($sql_array['prefval']), $db_charset);
+ }
+
+ /* retrieve address table data */
+ $sql_result = $db->query('SELECT * FROM '.$address_table.' WHERE owner=?', $uname); // ? is replaced with emailaddress
+
+ // parse addres book
+ while ($sql_array = $db->fetch_assoc($sql_result) ) { // fetch one row from result
+ $rec['name'] = rcube_charset_convert(rtrim($sql_array['nickname']), $db_charset);
+ $rec['firstname'] = rcube_charset_convert(rtrim($sql_array['firstname']), $db_charset);
+ $rec['surname'] = rcube_charset_convert(rtrim($sql_array['lastname']), $db_charset);
+ $rec['email'] = rcube_charset_convert(rtrim($sql_array['email']), $db_charset);
+ $rec['note'] = rcube_charset_convert(rtrim($sql_array['label']), $db_charset);
+
+ if ($rec['name'] && $rec['email'])
+ $this->abook[] = $rec;
+ }
+ } // end if 'sql'-driver