From 00de8ddf8d899a8c9a9ca89009f845f88eb7a6cc Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Wed, 06 Nov 2013 07:11:31 -0500
Subject: [PATCH] Small performance improvements, use str_replace() instead of strtr(), do not parse query if there are no params to replace, keep one instance of (potentially long) query less in memory

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

diff --git a/program/include/rcmail.php b/program/include/rcmail.php
index 9713cdb..4b3f137 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);
   }
 
 
@@ -506,15 +519,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