예제 #1
1
 /**
  * Modify user preferences
  *
  * @param string Option name
  * @param string Option value
  * @param int    Optional user identifier
  * @param string Optional value type (bool, int, string)
  */
 public static function mod_pref($name, $value, $userid = null, $type = 'string')
 {
     $db = self::db();
     if ($userid) {
         $query = '`user_id` = ' . intval($userid);
     } else {
         $query = '1=1';
     }
     $type = strtolower($type);
     if ($type == 'bool' || $type == 'boolean') {
         $value = rcube_utils::get_boolean($value);
     } else {
         if ($type == 'int' || $type == 'integer') {
             $value = (int) $value;
         }
     }
     // iterate over all users
     $sql_result = $db->query("SELECT * FROM " . $db->table_name('users', true) . " WHERE {$query}");
     while ($sql_result && ($sql_arr = $db->fetch_assoc($sql_result))) {
         echo "Updating prefs for user " . $sql_arr['user_id'] . "...";
         $user = new rcube_user($sql_arr['user_id'], $sql_arr);
         $prefs = $old_prefs = $user->get_prefs();
         $prefs[$name] = $value;
         if ($prefs != $old_prefs) {
             $user->save_prefs($prefs, true);
             echo "saved.\n";
         } else {
             echo "nothing changed.\n";
         }
     }
 }
예제 #2
0
 /**
  * Fixes some user preferences according to namespace handling change.
  * Old Roundcube versions were using folder names with removed namespace prefix.
  * Now we need to add the prefix on servers where personal namespace has prefix.
  *
  * @param rcube_user $user User object
  */
 private function fix_namespace_settings($user)
 {
     $prefix = $this->storage->get_namespace('prefix');
     $prefix_len = strlen($prefix);
     if (!$prefix_len) {
         return;
     }
     if ($this->config->get('namespace_fixed')) {
         return;
     }
     $prefs = array();
     // Build namespace prefix regexp
     $ns = $this->storage->get_namespace();
     $regexp = array();
     foreach ($ns as $entry) {
         if (!empty($entry)) {
             foreach ($entry as $item) {
                 if (strlen($item[0])) {
                     $regexp[] = preg_quote($item[0], '/');
                 }
             }
         }
     }
     $regexp = '/^(' . implode('|', $regexp) . ')/';
     // Fix preferences
     $opts = array('drafts_mbox', 'junk_mbox', 'sent_mbox', 'trash_mbox', 'archive_mbox');
     foreach ($opts as $opt) {
         if ($value = $this->config->get($opt)) {
             if ($value != 'INBOX' && !preg_match($regexp, $value)) {
                 $prefs[$opt] = $prefix . $value;
             }
         }
     }
     if (($search_mods = $this->config->get('search_mods')) && !empty($search_mods)) {
         $folders = array();
         foreach ($search_mods as $idx => $value) {
             if ($idx != 'INBOX' && $idx != '*' && !preg_match($regexp, $idx)) {
                 $idx = $prefix . $idx;
             }
             $folders[$idx] = $value;
         }
         $prefs['search_mods'] = $folders;
     }
     if (($threading = $this->config->get('message_threading')) && !empty($threading)) {
         $folders = array();
         foreach ($threading as $idx => $value) {
             if ($idx != 'INBOX' && !preg_match($regexp, $idx)) {
                 $idx = $prefix . $idx;
             }
             $folders[$prefix . $idx] = $value;
         }
         $prefs['message_threading'] = $folders;
     }
     if ($collapsed = $this->config->get('collapsed_folders')) {
         $folders = explode('&&', $collapsed);
         $count = count($folders);
         $folders_str = '';
         if ($count) {
             $folders[0] = substr($folders[0], 1);
             $folders[$count - 1] = substr($folders[$count - 1], 0, -1);
         }
         foreach ($folders as $value) {
             if ($value != 'INBOX' && !preg_match($regexp, $value)) {
                 $value = $prefix . $value;
             }
             $folders_str .= '&' . $value . '&';
         }
         $prefs['collapsed_folders'] = $folders_str;
     }
     $prefs['namespace_fixed'] = true;
     // save updated preferences and reset imap settings (default folders)
     $user->save_prefs($prefs);
     $this->set_storage_prop();
 }
예제 #3
0
 /**
  * Set special folders type association.
  * This must be done AFTER connecting to the server!
  */
 protected function set_special_folders()
 {
     $storage = $this->get_storage();
     $folders = $storage->get_special_folders(true);
     $prefs = array();
     // check SPECIAL-USE flags on IMAP folders
     foreach ($folders as $type => $folder) {
         $idx = $type . '_mbox';
         if ($folder !== $this->config->get($idx)) {
             $prefs[$idx] = $folder;
         }
     }
     // Some special folders differ, update user preferences
     if (!empty($prefs) && $this->user) {
         $this->user->save_prefs($prefs);
     }
     // create default folders (on login)
     if ($this->config->get('create_default_folders')) {
         $storage->create_default_folders();
     }
 }