Patch to empty any folder

Marcus I. Ryan marcus@riboflavin.net
Thu, 21 Mar 2002 12:01:02 -0600


The following patch adds the action "Empty folder(s)" in the Folders
view.  It deletes and expunges all messages form the given mailbox.
Created and tested under HEAD.

diff -ru imp.orig/folders.php imp/folders.php
--- imp.orig/folders.php        Thu Mar 21 10:38:33 2002
+++ imp/folders.php     Thu Mar 21 11:54:17 2002
@@ -240,6 +240,24 @@
          $prefs->store();
      }
      break;
+
+ case EMPTY_MAILBOX:
+     $folder_list = Horde::getFormData('folder_list');
+     if (is_array($folder_list) && count($folder_list)) {
+         foreach ($folder_list as $folder) {
+             if (imap_reopen($imp['stream'], IMP::serverString() .
$folder) !== true) {
+                 $notification->push(_("Could not delete messages from
$folder"), horde.error);
+             } else {
+                 if (imap_delete($imp['stream'], "1:*") !== true) {
+                    $notification->push(_("Could not delete messages
from $folder"), horde.error);
+                 } else if (imap_expunge($imp['stream']) !== true) {
+                    $notification->push(_("Could not delete messages
from $folder"), horde.error);
+                }
+            }
+             $notification->push(_("Cleared all messages from
$folder."), 'horde.message');
+        }
+     }
+     break;
 }

 /* Display the correct message on the action bar */
diff -ru imp.orig/templates/folders/actions.inc
imp/templates/folders/actions.inc
--- imp.orig/templates/folders/actions.inc      Thu Mar 21 11:56:52 2002
+++ imp/templates/folders/actions.inc   Thu Mar 21 10:43:47 2002
@@ -14,6 +14,7 @@
             <option value="<?= NOPOLL_FOLDER ?>"><?= _("Do Not Check
Folder(s) for New Mail") ?></option>
             <?php endif; ?>
             <option value="<?= DOWNLOAD_FOLDER ?>"><?= _("Download
Folder(s)") ?></option>
+            <option value="<?= EMPTY_MAILBOX ?>"><?= _("Empty
Folder(s)") ?></option>
         </select>
         <?php if ($conf['user']['online_help'] &&
$browser->hasFeature('javascript')) echo Help::link('imp',
'folder-options') ?>
     </td>
diff -ru imp.orig/templates/folders/javascript.inc
imp/templates/folders/javascript.inc
--- imp.orig/templates/folders/javascript.inc   Tue Mar  5 15:20:38 2002
+++ imp/templates/folders/javascript.inc        Thu Mar 21 11:55:50 2002
@@ -63,6 +63,10 @@
         submitAction(<?= NOPOLL_FOLDER ?>);
     } else if (action == <?= DOWNLOAD_FOLDER ?>) {
         downloadMailbox();
+    } else if (action == <?= EMPTY_MAILBOX ?>) {
+        if (window.confirm('<?= addslashes(_("Are you sure you wish to
PERMANENTLY delete these messages?")) ?>')) {
+            submitAction(<?= EMPTY_MAILBOX ?>);
+        }
     }
 }



-- 
Marcus I. Ryan, marcus@riboflavin.net
-----------------------------------------------------------------------
 "Love is a snowmobile racing across the tundra and then suddenly it
 flips over, pinning you underneath.  At night, the ice weasels come."
                 -- Matt Groening
-----------------------------------------------------------------------