From ef4998c11084b2c99f8af9976f9860d5f7709a0f Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Thu, 22 Sep 2011 04:48:05 -0400
Subject: [PATCH] Fix compose command from other tasks than mail and address book; skip common request parameters

---
 program/include/rcube_config.php |  110 +++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 75 insertions(+), 35 deletions(-)

diff --git a/program/include/rcube_config.php b/program/include/rcube_config.php
index bd53517..31b7ed6 100644
--- a/program/include/rcube_config.php
+++ b/program/include/rcube_config.php
@@ -4,8 +4,8 @@
  +-----------------------------------------------------------------------+
  | program/include/rcube_config.php                                      |
  |                                                                       |
- | This file is part of the RoundCube Webmail client                     |
- | Copyright (C) 2008-2010, RoundCube Dev. - Switzerland                 |
+ | This file is part of the Roundcube Webmail client                     |
+ | Copyright (C) 2008-2010, The Roundcube Dev Team                       |
  | Licensed under the GNU GPL                                            |
  |                                                                       |
  | PURPOSE:                                                              |
@@ -20,7 +20,7 @@
 */
 
 /**
- * Configuration class for RoundCube
+ * Configuration class for Roundcube
  *
  * @package Core
  */
@@ -47,10 +47,6 @@
      */
     private function load()
     {
-        // start output buffering, we don't need any output yet, 
-        // it'll be cleared after reading of config files, etc.
-        ob_start();
-    
         // load main config file
         if (!$this->load_from_file(RCMAIL_CONFIG_DIR . '/main.inc.php'))
             $this->errors[] = 'main.inc.php was not found.';
@@ -58,7 +54,7 @@
         // load database config
         if (!$this->load_from_file(RCMAIL_CONFIG_DIR . '/db.inc.php'))
             $this->errors[] = 'db.inc.php was not found.';
-    
+
         // load host-specific configuration
         $this->load_host_config();
 
@@ -71,7 +67,7 @@
         // fix paths
         $this->prop['log_dir'] = $this->prop['log_dir'] ? realpath(unslashify($this->prop['log_dir'])) : INSTALL_PATH . 'logs';
         $this->prop['temp_dir'] = $this->prop['temp_dir'] ? realpath(unslashify($this->prop['temp_dir'])) : INSTALL_PATH . 'temp';
-    
+
         // fix default imap folders encoding
         foreach (array('drafts_mbox', 'junk_mbox', 'sent_mbox', 'trash_mbox') as $folder)
             $this->prop[$folder] = rcube_charset_convert($this->prop[$folder], RCMAIL_CHARSET, 'UTF7-IMAP');
@@ -91,15 +87,9 @@
                 ini_set('error_log', $this->prop['log_dir'].'/errors');
             }
         }
-        if ($this->prop['debug_level'] & 4) {
-            ini_set('display_errors', 1);
-        }
-        else {
-            ini_set('display_errors', 0);
-        }
 
-        // clear output buffer
-        ob_end_clean();
+        // enable display_errors in 'show' level, but not for ajax requests
+        ini_set('display_errors', intval(empty($_REQUEST['_remote']) && ($this->prop['debug_level'] & 4)));
 
         // export config data
         $GLOBALS['CONFIG'] = &$this->prop;
@@ -130,13 +120,17 @@
      * Read configuration from a file
      * and merge with the already stored config values
      *
-     * @param string Full path to the config file to be loaded
+     * @param string $fpath Full path to the config file to be loaded
      * @return booelan True on success, false on failure
      */
     public function load_from_file($fpath)
     {
         if (is_file($fpath) && is_readable($fpath)) {
+            // use output buffering, we don't need any output here 
+            ob_start();
             include($fpath);
+            ob_end_clean();
+
             if (is_array($rcmail_config)) {
                 $this->prop = array_merge($this->prop, $rcmail_config, $this->userprefs);
                 return true;
@@ -150,21 +144,31 @@
     /**
      * Getter for a specific config parameter
      *
-     * @param  string Parameter name
-     * @param  mixed  Default value if not set
+     * @param  string $name Parameter name
+     * @param  mixed  $def  Default value if not set
      * @return mixed  The requested config value
      */
     public function get($name, $def = null)
     {
-        return isset($this->prop[$name]) ? $this->prop[$name] : $def;
+        $result = isset($this->prop[$name]) ? $this->prop[$name] : $def;
+        $rcmail = rcmail::get_instance();
+
+        if (is_object($rcmail->plugins)) {
+            $plugin = $rcmail->plugins->exec_hook('config_get', array(
+                'name' => $name, 'default' => $def, 'result' => $result));
+
+            return $plugin['result'];
+        }
+
+        return $result;
     }
 
 
     /**
      * Setter for a config parameter
      *
-     * @param string Parameter name
-     * @param mixed  Parameter value
+     * @param string $name  Parameter name
+     * @param mixed  $value Parameter value
      */
     public function set($name, $value)
     {
@@ -175,7 +179,7 @@
     /**
      * Override config options with the given values (eg. user prefs)
      *
-     * @param array Hash array with config props to merge over
+     * @param array $prefs Hash array with config props to merge over
      */
     public function merge($prefs)
     {
@@ -187,12 +191,22 @@
      * Merge the given prefs over the current config
      * and make sure that they survive further merging.
      *
-     * @param array  Hash array with user prefs
+     * @param array $prefs Hash array with user prefs
      */
     public function set_user_prefs($prefs)
     {
+        // Honor the dont_override setting for any existing user preferences
+        $dont_override = $this->get('dont_override');
+        if (is_array($dont_override) && !empty($dont_override)) {
+            foreach ($prefs as $key => $pref) {
+                if (in_array($key, $dont_override)) {
+                    unset($prefs[$key]);
+                }
+            }
+        }
+
         $this->userprefs = $prefs;
-        $this->prop = array_merge($this->prop, $prefs);
+        $this->prop      = array_merge($this->prop, $prefs);
     }
 
 
@@ -206,11 +220,24 @@
         return $this->prop;
     }
 
+    /**
+     * Special getter for user's timezone
+     */
+    public function get_timezone()
+    {
+      $tz = $this->get('timezone');
+      if ($tz == 'auto')
+        $tz = isset($_SESSION['timezone']) ? $_SESSION['timezone'] : date('Z') / 3600;
+      else
+        $tz = intval($tz) + intval($this->get('dst_active'));
+
+      return $tz;
+    }
 
     /**
      * Return requested DES crypto key.
      *
-     * @param string Crypto key name
+     * @param string $key Crypto key name
      * @return string Crypto key
      */
     public function get_crypto_key($key)
@@ -247,8 +274,17 @@
     public function header_delimiter()
     {
         // use the configured delimiter for headers
-        if (!empty($this->prop['mail_header_delimiter']))
-            return $this->prop['mail_header_delimiter'];
+        if (!empty($this->prop['mail_header_delimiter'])) {
+            $delim = $this->prop['mail_header_delimiter'];
+            if ($delim == "\n" || $delim == "\r\n")
+                return $delim;
+            else
+                raise_error(array(
+                    'code' => 500, 'type' => 'php',
+	                'file' => __FILE__, 'line' => __LINE__,
+                    'message' => "Invalid mail_header_delimiter setting"
+                ), true, false);
+        }
 
         $php_os = strtolower(substr(PHP_OS, 0, 3));
 
@@ -265,10 +301,11 @@
     /**
      * Return the mail domain configured for the given host
      *
-     * @param string IMAP host
+     * @param string  $host   IMAP host
+     * @param boolean $encode If true, domain name will be converted to IDN ASCII
      * @return string Resolved SMTP host
      */
-    public function mail_domain($host)
+    public function mail_domain($host, $encode=true)
     {
         $domain = $host;
 
@@ -277,12 +314,15 @@
                 $domain = $this->prop['mail_domain'][$host];
         }
         else if (!empty($this->prop['mail_domain']))
-            $domain = $this->prop['mail_domain'];
-    
+            $domain = rcube_parse_host($this->prop['mail_domain']);
+
+        if ($encode)
+            $domain = rcube_idn_to_ascii($domain);
+
         return $domain;
     }
-  
-  
+
+
     /**
      * Getter for error state
      *

--
Gitblit v1.9.1