From 04689fa7ee89c29b57278a354b39d9ee5397a442 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Wed, 12 Dec 2012 13:59:08 -0500
Subject: [PATCH] Fix so compacting of non-empty folder is possible also when messages list is empty (#1488858)

---
 CHANGELOG                           |    1 +
 program/steps/mail/list.inc         |    1 +
 program/steps/mail/search.inc       |    1 +
 program/steps/mail/folders.inc      |    1 +
 program/steps/mail/check_recent.inc |    4 +++-
 program/js/app.js                   |   11 ++++++-----
 program/steps/mail/move_del.inc     |    7 +++----
 7 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 8fd17b4..095a240 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
 CHANGELOG Roundcube Webmail
 ===========================
 
+- Fix so compacting of non-empty folder is possible also when messages list is empty (#1488858)
 - Allow forwarding of multiple emails (#1486854)
 - Fix big memory consumption of DB layer (#1488856)
 - Add workaround for IE<=8 bug where Content-Disposition:inline was ignored (#1488844)
diff --git a/program/js/app.js b/program/js/app.js
index 4094a67..b5bf184 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -651,13 +651,13 @@
         break;
 
       case 'expunge':
-        if (this.env.messagecount)
+        if (this.env.exists)
           this.expunge_mailbox(this.env.mailbox);
         break;
 
       case 'purge':
       case 'empty-mailbox':
-        if (this.env.messagecount)
+        if (this.env.exists)
           this.purge_mailbox(this.env.mailbox);
         break;
 
@@ -2971,7 +2971,7 @@
   // test if purge command is allowed
   this.purge_mailbox_test = function()
   {
-    return (this.env.messagecount && (this.env.mailbox == this.env.trash_mailbox || this.env.mailbox == this.env.junk_mailbox
+    return (this.env.exists && (this.env.mailbox == this.env.trash_mailbox || this.env.mailbox == this.env.junk_mailbox
       || this.env.mailbox.match('^' + RegExp.escape(this.env.trash_mailbox) + RegExp.escape(this.env.delimiter))
       || this.env.mailbox.match('^' + RegExp.escape(this.env.junk_mailbox) + RegExp.escape(this.env.delimiter))));
   };
@@ -6228,7 +6228,7 @@
       case 'purge':
       case 'expunge':
         if (this.task == 'mail') {
-          if (!this.env.messagecount) {
+          if (!this.env.exists) {
             // clear preview pane content
             if (this.env.contentframe)
               this.show_contentframe(false);
@@ -6248,7 +6248,8 @@
         this.env.qsearch = null;
       case 'list':
         if (this.task == 'mail') {
-          this.enable_command('show', 'expunge', 'select-all', 'select-none', (this.env.messagecount > 0));
+          this.enable_command('show', 'select-all', 'select-none', this.env.messagecount > 0);
+          this.enable_command('expunge', this.env.exists);
           this.enable_command('purge', this.purge_mailbox_test());
           this.enable_command('expand-all', 'expand-unread', 'collapse-all', this.env.threading && this.env.messagecount);
 
diff --git a/program/steps/mail/check_recent.inc b/program/steps/mail/check_recent.inc
index 61693b4..4befbf2 100644
--- a/program/steps/mail/check_recent.inc
+++ b/program/steps/mail/check_recent.inc
@@ -75,13 +75,15 @@
         if (!empty($_GET['_quota']))
             $OUTPUT->command('set_quota', rcmail_quota_content());
 
+        $OUTPUT->set_env('exists', $RCMAIL->storage->count($mbox_name, 'EXISTS'));
+
         // "No-list" mode, don't get messages
         if (empty($_GET['_list']))
             continue;
 
         // get overall message count; allow caching because rcube_storage::folder_status() did a refresh
         $list_mode = $RCMAIL->storage->get_threading() ? 'THREADS' : 'ALL';
-        $all_count = $RCMAIL->storage->count(null, $list_mode, false, false);
+        $all_count = $RCMAIL->storage->count($mbox_name, $list_mode, false, false);
         $page      = $RCMAIL->storage->get_page();
         $page_size = $RCMAIL->storage->get_pagesize();
 
diff --git a/program/steps/mail/folders.inc b/program/steps/mail/folders.inc
index c56c914..574d6e9 100644
--- a/program/steps/mail/folders.inc
+++ b/program/steps/mail/folders.inc
@@ -65,6 +65,7 @@
             if (!empty($_REQUEST['_reload'])) {
                 $OUTPUT->set_env('messagecount', 0);
                 $OUTPUT->set_env('pagecount', 0);
+                $OUTPUT->set_env('exists', 0);
                 $OUTPUT->command('message_list.clear');
                 $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text(), $mbox);
                 $OUTPUT->command('set_unread_count', $mbox, 0);
diff --git a/program/steps/mail/list.inc b/program/steps/mail/list.inc
index b433f81..b8c3ee0 100644
--- a/program/steps/mail/list.inc
+++ b/program/steps/mail/list.inc
@@ -95,6 +95,7 @@
 $OUTPUT->set_env('pagecount', $pages);
 $OUTPUT->set_env('threading', $threading);
 $OUTPUT->set_env('current_page', $count ? $RCMAIL->storage->get_page() : 1);
+$OUTPUT->set_env('exists', $RCMAIL->storage->count($mbox_name, 'EXISTS'));
 $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($count), $mbox_name);
 $OUTPUT->command('set_mailboxname', rcmail_get_mailbox_name_text());
 
diff --git a/program/steps/mail/move_del.inc b/program/steps/mail/move_del.inc
index da43b40..3e22526 100644
--- a/program/steps/mail/move_del.inc
+++ b/program/steps/mail/move_del.inc
@@ -38,7 +38,7 @@
 
     if (!$moved) {
         // send error message
-	    if ($_POST['_from'] != 'show')
+        if ($_POST['_from'] != 'show')
             $OUTPUT->command('list_mailbox');
         rcmail_display_server_error('errormoving');
         $OUTPUT->send();
@@ -59,7 +59,7 @@
 
     if (!$del) {
         // send error message
-	    if ($_POST['_from'] != 'show')
+        if ($_POST['_from'] != 'show')
             $OUTPUT->command('list_mailbox');
         rcmail_display_server_error('errordeleting');
         $OUTPUT->send();
@@ -111,6 +111,7 @@
   $OUTPUT->set_env('messagecount', $msg_count);
   $OUTPUT->set_env('current_page', $page);
   $OUTPUT->set_env('pagecount', $pages);
+  $OUTPUT->set_env('exists', $RCMAIL->storage->count($mbox, 'EXISTS', true));
 
   // update mailboxlist
   $mbox = $RCMAIL->storage->get_folder();
@@ -144,5 +145,3 @@
 
 // send response
 $OUTPUT->send();
-
-
diff --git a/program/steps/mail/search.inc b/program/steps/mail/search.inc
index db5424b..f9b8f9e 100644
--- a/program/steps/mail/search.inc
+++ b/program/steps/mail/search.inc
@@ -143,5 +143,6 @@
 $OUTPUT->set_env('search_request', $search_str ? $search_request : '');
 $OUTPUT->set_env('messagecount', $count);
 $OUTPUT->set_env('pagecount', ceil($count/$RCMAIL->storage->get_pagesize()));
+$OUTPUT->set_env('exists', $RCMAIL->storage->count($mbox_name, 'EXISTS'));
 $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($count, 1), $mbox);
 $OUTPUT->send();

--
Gitblit v1.9.1