From 38bf401cf88bc88d3b4d96fee8d2166cc2cac8c6 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Sun, 01 Dec 2013 04:55:13 -0500
Subject: [PATCH] Fix performance of listing writeable folders (#1489451)

---
 program/include/rcmail.php |   61 +++++++++++++++++++++---------
 1 files changed, 42 insertions(+), 19 deletions(-)

diff --git a/program/include/rcmail.php b/program/include/rcmail.php
index 9713cdb..8abe873 100644
--- a/program/include/rcmail.php
+++ b/program/include/rcmail.php
@@ -351,24 +351,37 @@
    * These are stored in local config and user preferences.
    *
    * @param boolean True to sort the list alphabetically
+   * @param boolean True if only this user's responses shall be listed
    * @return array List of the current user's stored responses
    */
-  public function get_compose_responses($sorted = false)
+  public function get_compose_responses($sorted = false, $user_only = false)
   {
+    $responses = array();
+
+    if (!$user_only) {
+      foreach ($this->config->get('compose_responses_static', array()) as $response) {
+        if (empty($response['key']))
+          $response['key'] = substr(md5($response['name']), 0, 16);
+        $response['static'] = true;
+        $response['class'] = 'readonly';
+        $k = $sorted ? '0000-' . strtolower($response['name']) : $response['key'];
+        $responses[$k] = $response;
+      }
+    }
+
     foreach ($this->config->get('compose_responses', array()) as $response) {
       if (empty($response['key']))
         $response['key'] = substr(md5($response['name']), 0, 16);
-        $k = $sorted ? strtolower($response['name']) : $response['key'];
-        $responses[$k] = $response;
-      }
+      $k = $sorted ? strtolower($response['name']) : $response['key'];
+      $responses[$k] = $response;
+    }
 
-      if ($sorted) {
-        // sort list by name
-        ksort($responses, SORT_LOCALE_STRING);
-        return array_values($responses);
-      }
+    // sort list by name
+    if ($sorted) {
+      ksort($responses, SORT_LOCALE_STRING);
+    }
 
-      return $responses;
+    return array_values($responses);
   }
 
 
@@ -399,6 +412,9 @@
     $this->output->set_env('action', $this->action);
     $this->output->set_env('comm_path', $this->comm_path);
     $this->output->set_charset(RCUBE_CHARSET);
+
+    if ($this->user && $this->user->ID)
+      $this->output->set_env('user_id', $this->user->get_hash());
 
     // add some basic labels to client
     $this->output->add_label('loading', 'servererror', 'requesttimedout', 'refreshing');
@@ -506,15 +522,22 @@
         $port = $config['default_port'];
     }
 
-    /* Modify username with domain if required
-       Inspired by Marco <P0L0_notspam_binware.org>
-    */
-    // Check if we need to add domain
-    if (!empty($config['username_domain']) && strpos($username, '@') === false) {
-      if (is_array($config['username_domain']) && isset($config['username_domain'][$host]))
-        $username .= '@'.rcube_utils::parse_host($config['username_domain'][$host], $host);
-      else if (is_string($config['username_domain']))
-        $username .= '@'.rcube_utils::parse_host($config['username_domain'], $host);
+    // Check if we need to add/force domain to username
+    if (!empty($config['username_domain'])) {
+      $domain = is_array($config['username_domain']) ? $config['username_domain'][$host] : $config['username_domain'];
+
+      if ($domain = rcube_utils::parse_host((string)$domain, $host)) {
+        $pos = strpos($username, '@');
+
+        // force configured domains
+        if (!empty($config['username_domain_forced']) && $pos !== false) {
+          $username = substr($username, 0, $pos) . '@' . $domain;
+        }
+        // just add domain if not specified
+        else if ($pos === false) {
+          $username .= '@' . $domain;
+        }
+      }
     }
 
     if (!isset($config['login_lc'])) {

--
Gitblit v1.9.1