From 7fb0aedc9bddc00e22cd75ca5ea4a9d8d2f1819c Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Sat, 03 Oct 2015 07:06:24 -0400
Subject: [PATCH] Fix fetchMIMEHeaders() so it really works with multiple parts, various CS fixes
---
program/lib/Roundcube/rcube_user.php | 62 +++++++++++++++++++++----------
1 files changed, 42 insertions(+), 20 deletions(-)
diff --git a/program/lib/Roundcube/rcube_user.php b/program/lib/Roundcube/rcube_user.php
index 77c58dd..ac245d3 100644
--- a/program/lib/Roundcube/rcube_user.php
+++ b/program/lib/Roundcube/rcube_user.php
@@ -1,6 +1,6 @@
<?php
-/*
+/**
+-----------------------------------------------------------------------+
| This file is part of the Roundcube Webmail client |
| Copyright (C) 2005-2012, The Roundcube Dev Team |
@@ -29,6 +29,7 @@
public $ID;
public $data;
public $language;
+ public $prefs;
/**
* Holds database connection.
@@ -132,10 +133,14 @@
*/
function get_prefs()
{
- $prefs = array();
+ if (isset($this->prefs)) {
+ return $this->prefs;
+ }
+
+ $this->prefs = array();
if (!empty($this->language))
- $prefs['language'] = $this->language;
+ $this->prefs['language'] = $this->language;
if ($this->ID) {
// Preferences from session (write-master is unavailable)
@@ -153,20 +158,22 @@
}
if ($this->data['preferences']) {
- $prefs += (array)unserialize($this->data['preferences']);
+ $this->prefs += (array)unserialize($this->data['preferences']);
}
}
- return $prefs;
+ return $this->prefs;
}
/**
* Write the given user prefs to the user's record
*
* @param array $a_user_prefs User prefs to save
+ * @param bool $no_session Simplified language/preferences handling
+ *
* @return boolean True on success, False on failure
*/
- function save_prefs($a_user_prefs)
+ function save_prefs($a_user_prefs, $no_session = false)
{
if (!$this->ID)
return false;
@@ -183,45 +190,53 @@
$config = $this->rc->config;
// merge (partial) prefs array with existing settings
- $save_prefs = $a_user_prefs + $old_prefs;
+ $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
foreach ($a_user_prefs as $key => $value) {
- if ($value === null || (!isset($old_prefs[$key]) && ($value == $config->get($key))))
+ if ($value === null || (!isset($old_prefs[$key]) && ($value == $config->get($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,
- $_SESSION['language'],
+ $this->language,
$this->ID);
-
- $this->language = $_SESSION['language'];
// Update success
if ($this->db->affected_rows() !== false) {
- $config->set_user_prefs($a_user_prefs);
$this->data['preferences'] = $save_prefs;
- if (isset($_SESSION['preferences'])) {
- $this->rc->session->remove('preferences');
- $this->rc->session->remove('preferences_time');
+ 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 ($this->db->is_replicated() && $config->get('session_storage', 'db') != 'db') {
+ 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($a_user_prefs);
+ $config->set_user_prefs($this->prefs);
$this->data['preferences'] = $save_prefs;
}
@@ -229,12 +244,19 @@
}
/**
- * Generate a unique hash to identify this user which
+ * Generate a unique hash to identify this user whith
*/
function get_hash()
{
- $key = substr($this->rc->config->get('des_key'), 1, 4);
- return md5($this->data['user_id'] . $key . $this->data['username'] . '@' . $this->data['mail_host']);
+ $prefs = $this->get_prefs();
+
+ // generate a random hash and store it in user prefs
+ if (empty($prefs['client_hash'])) {
+ $prefs['client_hash'] = md5($this->data['username'] . mt_rand() . $this->data['mail_host']);
+ $this->save_prefs(array('client_hash' => $prefs['client_hash']));
+ }
+
+ return $prefs['client_hash'];
}
/**
--
Gitblit v1.9.1