function save_prefs($a_user_prefs, $no_session = false)
    {
        if (!$this->ID)
            return false;

        $plugin = $this->rc->plugins->exec_hook('preferences_update', array(
            'userid' => $this->ID, 'prefs' => $a_user_prefs, 'old' => (array)$this->get_prefs()));

        if (!empty($plugin['abort'])) {
            return;
        }

        $a_user_prefs = $plugin['prefs'];
        $old_prefs    = $plugin['old'];
        $config       = $this->rc->config;
        $defaults     = $config->all();

        // merge (partial) prefs array with existing settings
        $this->prefs = $save_prefs = $a_user_prefs + $old_prefs;
        unset($save_prefs['language']);

        // don't save prefs with default values if they haven't been changed yet
        // Warning: we use result of rcube_config::all() here instead of just get() (#5782)
        foreach ($a_user_prefs as $key => $value) {
            if ($value === null || (!isset($old_prefs[$key]) && $value === $defaults[$key])) {
                unset($save_prefs[$key]);
            }
        }

        $save_prefs = serialize($save_prefs);
        if (!$no_session) {
            $this->language = $_SESSION['language'];
        }

        $this->db->query(
            "UPDATE ".$this->db->table_name('users', true).
            " SET `preferences` = ?, `language` = ?".
            " WHERE `user_id` = ?",
            $save_prefs,
            $this->language,
            $this->ID);

        // Update success
        if ($this->db->affected_rows() !== false) {
            $this->data['preferences'] = $save_prefs;

            if (!$no_session) {
                $config->set_user_prefs($this->prefs);

                if (isset($_SESSION['preferences'])) {
                    $this->rc->session->remove('preferences');
                    $this->rc->session->remove('preferences_time');
                }
            }

            return true;
        }
        // Update error, but we are using replication (we have read-only DB connection)
        // and we are storing session not in the SQL database
        // we can store preferences in session and try to write later (see get_prefs())
        else if (!$no_session && $this->db->is_replicated()
            && $config->get('session_storage', 'db') != 'db'
        ) {
            $_SESSION['preferences'] = $save_prefs;
            $_SESSION['preferences_time'] = time();
            $config->set_user_prefs($this->prefs);
            $this->data['preferences'] = $save_prefs;
        }

        return false;
    }