From 5e35126796f14e0910a007972779d96fd49e1789 Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Wed, 25 Jan 2006 17:56:53 -0500
Subject: [PATCH] Added folder purge function and some checks

---
 index.php                                 |    2 
 skins/default/templates/mail.html         |    1 
 program/js/common.js                      |    6 +-
 program/steps/mail/folders.inc            |    8 ++--
 program/steps/mail/check_recent.inc       |    4 +-
 program/steps/addressbook/func.inc        |    3 +
 program/steps/mail/func.inc               |    3 +
 program/lib/MDB2/Driver/Manager/fbsql.php |    1 
 program/js/app.js                         |   44 ++++++++++++++++++---
 program/include/rcube_imap.inc            |   14 ++++++-
 10 files changed, 66 insertions(+), 20 deletions(-)

diff --git a/index.php b/index.php
index 25e3b6f..527f4f2 100644
--- a/index.php
+++ b/index.php
@@ -244,7 +244,7 @@
   if ($_action=='addcontact')
     include('program/steps/mail/addcontact.inc');
 
-  if ($_action=='expunge')
+  if ($_action=='expunge' || $_action=='purge')
     include('program/steps/mail/folders.inc');
 
   if ($_action=='check-recent')
diff --git a/program/include/rcube_imap.inc b/program/include/rcube_imap.inc
index 7f91d3a..fa13e02 100644
--- a/program/include/rcube_imap.inc
+++ b/program/include/rcube_imap.inc
@@ -986,8 +986,18 @@
     
     if ($msg_count>0)
       {
-      $this->clear_message_cache($mailbox.'.msg');
-      return iil_C_ClearFolder($this->conn, $mailbox);
+      $cleared = iil_C_ClearFolder($this->conn, $mailbox);
+      
+      // make sure the message count cache is cleared as well
+      if ($cleared)
+        {
+        $this->clear_message_cache($mailbox.'.msg');      
+        $a_mailbox_cache = $this->get_cache('messagecount');
+        unset($a_mailbox_cache[$mailbox]);
+        $this->update_cache('messagecount', $a_mailbox_cache);
+        }
+        
+      return $cleared;
       }
     else
       return 0;
diff --git a/program/js/app.js b/program/js/app.js
index 3c91490..e0e31ed 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -145,6 +145,9 @@
         if (this.env.messagecount)
           this.enable_command('select-all', 'select-none', 'sort', 'expunge', true);
 
+        if (this.env.messagecount && this.env.mailbox==this.env.trash_mailbox)
+          this.enable_command('purge', true);
+
         this.set_page_buttons();
 
         // focus this window
@@ -622,9 +625,10 @@
           this.expunge_mailbox(this.env.mailbox);
         break;
 
-      case 'clear-mailbox':
-        //if (this.env.messagecount)
-          //this.clear_mailbox(this.env.mailbox);
+      case 'purge':
+      case 'empty-mailbox':
+        if (this.env.messagecount)
+          this.purge_mailbox(this.env.mailbox);
         break;
 
 
@@ -1435,6 +1439,28 @@
     };
 
 
+  this.purge_mailbox = function(mbox)
+    {
+    var lock = false;
+    var add_url = '';
+    
+    if (!confirm(this.get_label('purgefolderconfirm')))
+      return false;
+    
+    // lock interface if it's the active mailbox
+    if (mbox == this.env.mailbox)
+       {
+       lock = true;
+       this.set_busy(true, 'loading');
+       add_url = '&_reload=1';
+       }
+
+    // send request to server
+    var url = '_mbox='+escape(mbox);
+    this.http_request('purge', url+add_url, lock);
+    };
+    
+
   // move selected messages to the specified mailbox
   this.move_messages = function(mbox)
     {
@@ -2068,6 +2094,7 @@
       return false;
       
     //if (this.env.framed && add_url=='')
+    
     //  add_url = '&_framed=1';
     
     if (action && (cid || action=='add'))
@@ -2081,9 +2108,9 @@
   this.delete_contacts = function()
     {
     // exit if no mailbox specified or if selection is empty
-    if (!(this.selection.length || this.env.cid))
+    if (!(this.selection.length || this.env.cid) || !confirm(this.get_label('deletecontactconfirm')))
       return;
-    
+      
     var a_cids = new Array();
 
     if (this.env.cid)
@@ -2821,7 +2848,7 @@
     if (request_obj.__lock)
       this.set_busy(false);
 
-  console(request_obj.responseText);
+  console(request_obj.get_text());
 
     // if we get javascript code from server -> execute it
     if (request_obj.get_text() && (ctype=='text/javascript' || ctype=='application/x-javascript'))
@@ -2837,9 +2864,12 @@
         break;
 
       case 'list':
+        if (this.env.messagecount)
+          this.enable_command('purge', (this.env.mailbox==this.env.trash_mailbox));
+
       case 'expunge':
         this.enable_command('select-all', 'select-none', 'expunge', this.env.messagecount ? true : false);
-        break;
+        break;      
       }
 
     request_obj.reset();
diff --git a/program/js/common.js b/program/js/common.js
index 02f698b..8378e2e 100644
--- a/program/js/common.js
+++ b/program/js/common.js
@@ -6,11 +6,11 @@
  | Copyright (C) 2005, RoundCube Dev, - Switzerland                      |
  | Licensed under the GNU GPL                                            |
  |                                                                       |
- | Modified:2005/11/06 (roundcube)                                       |
- |                                                                       |
  +-----------------------------------------------------------------------+
  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
  +-----------------------------------------------------------------------+
+ 
+ $Id$
 */
 
 
@@ -271,7 +271,7 @@
     {
     var reg_str = '([a-z0-9][-a-z0-9\.\+_]*)\@(([-a-z0-9][\.]?)*[a-z0-9]\.[a-z]{2,9})';
     var reg1 = inline ? new RegExp(reg_str, 'i') : new RegExp('^'+reg_str+'$', 'i');
-    var reg2 = /[\._\-\@]{2}/;
+    var reg2 = /[\._\-]{2}/;
     return reg1.test(input) && !reg2.test(input) ? true : false;
     }
   return false;
diff --git a/program/lib/MDB2/Driver/Manager/fbsql.php b/program/lib/MDB2/Driver/Manager/fbsql.php
index 60850bb..c1895ce 100755
--- a/program/lib/MDB2/Driver/Manager/fbsql.php
+++ b/program/lib/MDB2/Driver/Manager/fbsql.php
@@ -478,7 +478,6 @@
      * @return mixed data array on success, a MDB2 error on failure
      * @access public
      */
-     */
     function listTableIndexes($table)
     {
         $db =& $this->getDBInstance();
diff --git a/program/steps/addressbook/func.inc b/program/steps/addressbook/func.inc
index f7993c9..6d3e95e 100644
--- a/program/steps/addressbook/func.inc
+++ b/program/steps/addressbook/func.inc
@@ -91,6 +91,9 @@
   
   $OUTPUT->add_script($javascript);  
 
+  // add some labels to client
+  rcube_add_label('deletecontactconfirm');
+
   return $out;
   }
 
diff --git a/program/steps/mail/check_recent.inc b/program/steps/mail/check_recent.inc
index fbf8871..3d0ceb2 100644
--- a/program/steps/mail/check_recent.inc
+++ b/program/steps/mail/check_recent.inc
@@ -22,10 +22,10 @@
 $REMOTE_REQUEST = TRUE;
 $mbox = $IMAP->get_mailbox_name();
 
-if ($recent_count = $IMAP->messagecount(NULL, 'RECENT'))
+if ($recent_count = $IMAP->messagecount(NULL, 'RECENT', TRUE))
   {
   $count = $IMAP->messagecount();
-  $unread_count = $IMAP->messagecount(NULL, 'UNSEEN');
+  $unread_count = $IMAP->messagecount(NULL, 'UNSEEN', TRUE);
     
   $commands = sprintf("this.set_unread_count('%s', %d, true);\n", addslashes($mbox), $unread_count);
   $commands .= sprintf("this.set_env('messagecount', %d);\n", $count);
diff --git a/program/steps/mail/folders.inc b/program/steps/mail/folders.inc
index e1730ef..5a22b7e 100644
--- a/program/steps/mail/folders.inc
+++ b/program/steps/mail/folders.inc
@@ -16,7 +16,6 @@
  +-----------------------------------------------------------------------+
 
  $Id$
-
 */
 
 $REMOTE_REQUEST = TRUE;
@@ -26,7 +25,7 @@
 // send EXPUNGE command
 if ($_action=='expunge')
   {
-  $success = $IMAP->expunge();
+  $success = $IMAP->expunge($_GET['_mbox']);
 
   // reload message list if current mailbox  
   if ($success && $_GET['_reload'])
@@ -42,11 +41,12 @@
 // clear mailbox
 else if ($_action=='purge')
   {
-  $success = $IMAP->clear_mailbox();
+  $success = $IMAP->clear_mailbox($_GET['_mbox']);
   
   if ($success && $_GET['_reload'])
     {
-    $commands = "this.set_env('messagecount', 0);\n";
+    $commands = "this.clear_message_list();\n";
+    $commands .= "this.set_env('messagecount', 0);\n";
     $commands .= "this.set_env('pagecount', 0);\n";
     $commands .= sprintf("this.set_rowcount('%s');\n", rcmail_get_messagecount_text());
     $commands .= sprintf("this.set_unread_count('%s', 0);\n", addslashes($mbox));
diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc
index 4f84e20..8e0178d 100644
--- a/program/steps/mail/func.inc
+++ b/program/steps/mail/func.inc
@@ -66,6 +66,9 @@
   global $IMAP, $CONFIG, $OUTPUT, $JS_OBJECT_NAME, $COMM_PATH;
   static $s_added_script = FALSE;
   static $a_mailboxes;
+
+  // add some labels to client
+  rcube_add_label('purgefolderconfirm');
   
 // $mboxlist_start = rcube_timer();
   
diff --git a/skins/default/templates/mail.html b/skins/default/templates/mail.html
index 1af25ed..0913018 100644
--- a/skins/default/templates/mail.html
+++ b/skins/default/templates/mail.html
@@ -31,6 +31,7 @@
 <div id="mailboxcontrols">
 <roundcube:label name="folder" />:&nbsp;
 <roundcube:button command="expunge" label="compact" classAct="active" />&nbsp;
+<roundcube:button command="purge" label="empty" classAct="active" />&nbsp;
 </div>
 
 

--
Gitblit v1.9.1