From 188247894f6aff3a11f68bbdf94626b8bf58b852 Mon Sep 17 00:00:00 2001
From: Thomas Bruederli <thomas@roundcube.net>
Date: Tue, 08 Apr 2014 13:11:12 -0400
Subject: [PATCH] Make multi-folder message identifiers work with folders containing commas

---
 program/include/rcmail.php              |   10 +++++++---
 program/lib/Roundcube/rcube_imap.php    |    4 ++--
 program/steps/mail/func.inc             |    2 +-
 program/lib/Roundcube/rcube_message.php |    2 +-
 program/steps/mail/mark.inc             |    4 +++-
 program/js/app.js                       |    5 +++--
 program/steps/mail/copy.inc             |    7 +++++--
 7 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/program/include/rcmail.php b/program/include/rcmail.php
index 2ccad03..5da1814 100644
--- a/program/include/rcmail.php
+++ b/program/include/rcmail.php
@@ -2025,8 +2025,9 @@
         $_uid  = $uids ?: rcube_utils::get_input_value('_uid', RCUBE_INPUT_GPC);
         $_mbox = $mbox ?: (string)rcube_utils::get_input_value('_mbox', RCUBE_INPUT_GPC);
 
-        if (is_array($uid)) {
-            return $uid;
+        // already a hash array
+        if (is_array($_uid) && !isset($_uid[0])) {
+            return $_uid;
         }
 
         $result = array();
@@ -2040,8 +2041,11 @@
             }
         }
         else {
+            if (is_string($_uid))
+                $_uid = explode(',', $_uid);
+
             // create a per-folder UIDs array
-            foreach (explode(',', $_uid) as $uid) {
+            foreach ((array)$_uid as $uid) {
                 list($uid, $mbox) = explode('-', $uid, 2);
                 if (empty($mbox))
                     $mbox = $_mbox;
diff --git a/program/js/app.js b/program/js/app.js
index 952c542..7f19382 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -3014,7 +3014,8 @@
     var icn_src, uid, i, len,
       rows = this.message_list ? this.message_list.rows : {};
 
-    uids = String(uids).split(',');
+    if (typeof uids == 'string')
+      uids = String(uids).split(',');
 
     for (i=0, len=uids.length; i<len; i++) {
       uid = uids[i];
@@ -3027,7 +3028,7 @@
   // with select_all mode checking
   this.uids_to_list = function(uids)
   {
-    return this.select_all_mode ? '*' : uids.join(',');
+    return this.select_all_mode ? '*' : (uids.length <= 1 ? uids.join(',') : uids);
   };
 
   // Sets title of the delete button
diff --git a/program/lib/Roundcube/rcube_imap.php b/program/lib/Roundcube/rcube_imap.php
index a2f610a..5c30327 100644
--- a/program/lib/Roundcube/rcube_imap.php
+++ b/program/lib/Roundcube/rcube_imap.php
@@ -1712,7 +1712,7 @@
         }
 
         // decode combined UID-folder identifier
-        if (preg_match('/^\d+-[^,]+$/', $uid)) {
+        if (preg_match('/^\d+-.+/', $uid)) {
             list($uid, $folder) = explode('-', $uid, 2);
         }
 
@@ -1748,7 +1748,7 @@
         }
 
         // decode combined UID-folder identifier
-        if (preg_match('/^\d+-[^,]+$/', $uid)) {
+        if (preg_match('/^\d+-.+/', $uid)) {
             list($uid, $folder) = explode('-', $uid, 2);
         }
 
diff --git a/program/lib/Roundcube/rcube_message.php b/program/lib/Roundcube/rcube_message.php
index edfd339..a648ae7 100644
--- a/program/lib/Roundcube/rcube_message.php
+++ b/program/lib/Roundcube/rcube_message.php
@@ -75,7 +75,7 @@
     function __construct($uid, $folder = null)
     {
         // decode combined UID-folder identifier
-        if (preg_match('/^\d+-[^,]+$/', $uid)) {
+        if (preg_match('/^\d+-.+/', $uid)) {
             list($uid, $folder) = explode('-', $uid, 2);
         }
 
diff --git a/program/steps/mail/copy.inc b/program/steps/mail/copy.inc
index 79e207a..5668f7c 100644
--- a/program/steps/mail/copy.inc
+++ b/program/steps/mail/copy.inc
@@ -5,7 +5,7 @@
  | program/steps/mail/copy.inc                                           |
  |                                                                       |
  | This file is part of the Roundcube Webmail client                     |
- | Copyright (C) 2005-2013, The Roundcube Dev Team                       |
+ | Copyright (C) 2005-2014, The Roundcube Dev Team                       |
  |                                                                       |
  | Licensed under the GNU General Public License version 3 or            |
  | any later version with exceptions for skins & plugins.                |
@@ -29,7 +29,10 @@
     $target = rcube_utils::get_input_value('_target_mbox', rcube_utils::INPUT_POST, true);
 
     foreach (rcmail::get_uids() as $mbox => $uids) {
-      $copied += (int)$RCMAIL->storage->copy_message($uids, $target, $mbox);
+        if ($mbox == $target)
+            $copied++;
+        else
+            $copied += (int)$RCMAIL->storage->copy_message($uids, $target, $mbox);
     }
 
     if (!$copied) {
diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc
index 630086a..f711da3 100644
--- a/program/steps/mail/func.inc
+++ b/program/steps/mail/func.inc
@@ -69,7 +69,7 @@
 }
 
 // remove mbox part from _uid
-if (($_uid  = get_input_value('_uid', RCUBE_INPUT_GPC)) && preg_match('/^\d+-[^,]+$/', $_uid)) {
+if (($_uid  = rcube_utils::get_input_value('_uid', RCUBE_INPUT_GPC)) && !is_array($_uid) && preg_match('/^\d+-.+/', $_uid)) {
   list($_uid, $mbox) = explode('-', $_uid, 2);
   if (isset($_GET['_uid']))  $_GET['_uid']  = $_uid;
   if (isset($_POST['_uid'])) $_POST['_uid'] = $_uid;
diff --git a/program/steps/mail/mark.inc b/program/steps/mail/mark.inc
index e81f6c9..4e83f97 100644
--- a/program/steps/mail/mark.inc
+++ b/program/steps/mail/mark.inc
@@ -68,7 +68,9 @@
 
     if ($flag == 'DELETED' && $read_deleted && !empty($_POST['_ruid'])) {
         $ruids = rcube_utils::get_input_value('_ruid', rcube_utils::INPUT_POST);
-        $read  = $RCMAIL->storage->set_flag($ruids, 'SEEN');
+        foreach (rcmail::get_uids($ruids) as $mbox => $uids) {
+            $read += (int)$RCMAIL->storage->set_flag($uids, 'SEEN', $mbox);
+        }
 
         if ($read && !$skip_deleted) {
             $OUTPUT->command('flag_deleted_as_read', $ruids);

--
Gitblit v1.9.1