From 9b624ba1493786bf2a03a4bb5f6faa173736c899 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Thu, 24 Feb 2011 07:12:09 -0500
Subject: [PATCH] - Merge fixes from trunk

---
 CHANGELOG                                 |    1 
 skins/default/templates/messageprint.html |    1 
 program/include/main.inc                  |   15 ++++++-
 plugins/managesieve/Changelog             |    3 +
 config/main.inc.php.dist                  |    1 
 plugins/managesieve/lib/Net/Sieve.php     |   43 ++++++++++++++++++---
 6 files changed, 55 insertions(+), 9 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 2a304c5..7195813 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
 CHANGELOG Roundcube Webmail
 ===========================
 
+- Add variable for 'Today' label in date_today option (#1486120)
 - Applied plugin changes since 0.5-stable release
 - Fix SQL query in rcube_user::query() so it uses index on MySQL again
 - Use only one from IMAP authentication methods to prevent login delays (1487784)
diff --git a/config/main.inc.php.dist b/config/main.inc.php.dist
index ea0092b..f00bfa8 100644
--- a/config/main.inc.php.dist
+++ b/config/main.inc.php.dist
@@ -347,6 +347,7 @@
 $rcmail_config['date_long'] = 'd.m.Y H:i';
 
 // use this format for today's date display (date or strftime format)
+// Note: $ character will be replaced with 'Today' label
 $rcmail_config['date_today'] = 'H:i';
 
 // store draft message is this mailbox
diff --git a/plugins/managesieve/Changelog b/plugins/managesieve/Changelog
index ef75739..20e3bb8 100644
--- a/plugins/managesieve/Changelog
+++ b/plugins/managesieve/Changelog
@@ -1,5 +1,8 @@
 - Fix escaping of backslash character in quoted strings (#1487780)
 - Fix STARTTLS for timsieved < 2.3.10
+- Fix handling of non-safe characters (double-quote, backslash)
+  or UTF-8 characters (dovecot's implementation bug workaround)
+  in script names
 
 * version 3.0 [2011-02-01]
 -----------------------------------------------------------
diff --git a/plugins/managesieve/lib/Net/Sieve.php b/plugins/managesieve/lib/Net/Sieve.php
index d4cc3ee..0f6a5f6 100644
--- a/plugins/managesieve/lib/Net/Sieve.php
+++ b/plugins/managesieve/lib/Net/Sieve.php
@@ -475,7 +475,9 @@
         if (NET_SIEVE_STATE_TRANSACTION != $this->_state) {
             return PEAR::raiseError('Not currently in TRANSACTION state', 1);
         }
-        if (PEAR::isError($res = $this->_doCmd(sprintf('HAVESPACE "%s" %d', $scriptname, $size)))) {
+
+        $command = sprintf('HAVESPACE %s %d', $this->_escape($scriptname), $size);
+        if (PEAR::isError($res = $this->_doCmd($command))) {
             return $res;
         }
         return true;
@@ -740,7 +742,9 @@
         if (NET_SIEVE_STATE_TRANSACTION != $this->_state) {
             return PEAR::raiseError('Not currently in AUTHORISATION state', 1);
         }
-        if (PEAR::isError($res = $this->_doCmd(sprintf('DELETESCRIPT "%s"', $scriptname)))) {
+
+        $command = sprintf('DELETESCRIPT %s', $this->_escape($scriptname));
+        if (PEAR::isError($res = $this->_doCmd($command))) {
             return $res;
         }
         return true;
@@ -759,7 +763,8 @@
             return PEAR::raiseError('Not currently in AUTHORISATION state', 1);
         }
 
-        if (PEAR::isError($res = $this->_doCmd(sprintf('GETSCRIPT "%s"', $scriptname)))) {
+        $command = sprintf('GETSCRIPT %s', $this->_escape($scriptname));
+        if (PEAR::isError($res = $this->_doCmd($command))) {
             return $res;
         }
 
@@ -779,9 +784,12 @@
         if (NET_SIEVE_STATE_TRANSACTION != $this->_state) {
             return PEAR::raiseError('Not currently in AUTHORISATION state', 1);
         }
-        if (PEAR::isError($res = $this->_doCmd(sprintf('SETACTIVE "%s"', $scriptname)))) {
+
+        $command = sprintf('SETACTIVE %s', $this->_escape($scriptname));
+        if (PEAR::isError($res = $this->_doCmd($command))) {
             return $res;
         }
+
         $this->_activeScript = $scriptname;
         return true;
     }
@@ -808,9 +816,10 @@
         $res = explode("\r\n", $res);
         foreach ($res as $value) {
             if (preg_match('/^"(.*)"( ACTIVE)?$/i', $value, $matches)) {
-                $scripts[] = $matches[1];
+                $script_name = stripslashes($matches[1]);
+                $scripts[] = $script_name;
                 if (!empty($matches[2])) {
-                    $activescript = $matches[1];
+                    $activescript = $script_name;
                 }
             }
         }
@@ -833,8 +842,10 @@
         }
 
         $stringLength = $this->_getLineLength($scriptdata);
+        $command      = sprintf("PUTSCRIPT %s {%d+}\r\n%s",
+            $this->_escape($scriptname), $stringLength, $scriptdata);
 
-        if (PEAR::isError($res = $this->_doCmd(sprintf("PUTSCRIPT \"%s\" {%d+}\r\n%s", $scriptname, $stringLength, $scriptdata)))) {
+        if (PEAR::isError($res = $this->_doCmd($command))) {
             return $res;
         }
 
@@ -1213,6 +1224,24 @@
     }
 
     /**
+     * Convert string into RFC's quoted-string or literal-c2s form
+     *
+     * @param string $string The string to convert.
+     *
+     * @return string Result string
+     */
+    function _escape($string)
+    {
+        // Some implementations doesn't allow UTF-8 characters in quoted-string
+        // It's safe to use literal-c2s
+        if (preg_match('/[^\x01-\x09\x0B-\x0C\x0E-\x7F]/', $string)) {
+            return sprintf("{%d+}\r\n%s", $this->_getLineLength($string), $string);
+        }
+
+        return '"' . addcslashes($string, '\\"') . '"';
+    }
+
+    /**
      * Write debug text to the current debug output handler.
      *
      * @param string $message Debug message text.
diff --git a/program/include/main.inc b/program/include/main.inc
index 7be7488..3ac26dc 100644
--- a/program/include/main.inc
+++ b/program/include/main.inc
@@ -1067,7 +1067,18 @@
       $out .= date($format{$i}, $timestamp);
   }
 
-  return $today ? (rcube_label('today') . ' ' . $out) : $out;
+  if ($today) {
+    $label = rcube_label('today');
+    // replcae $ character with "Today" label (#1486120)
+    if (strpos($out, '$') !== false) {
+      $out = preg_replace('/\$/', $label, $out, 1);
+    }
+    else {
+      $out = $label . ' ' . $out;
+    }
+  }
+
+  return $out;
 }
 
 
@@ -1685,7 +1696,7 @@
 {
   global $RCMAIL, $CONFIG;
 
-  $hook = $RCMAIL->plugins->exec_hook('hmtl_editor', array('mode' => $mode));
+  $hook = $RCMAIL->plugins->exec_hook('html_editor', array('mode' => $mode));
 
   if ($hook['abort'])
     return;  
diff --git a/skins/default/templates/messageprint.html b/skins/default/templates/messageprint.html
index f2775cd..ea7a320 100644
--- a/skins/default/templates/messageprint.html
+++ b/skins/default/templates/messageprint.html
@@ -2,6 +2,7 @@
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
 <title><roundcube:object name="pagetitle" /></title>
+<link rel="shortcut icon" href="/images/favicon.ico"/>
 <link rel="stylesheet" type="text/css" href="/print.css" />
 </head>
 <body>

--
Gitblit v1.9.1