Maintenance updates to IMP 5.
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 2 Dec 2008 22:39:13 +0000 (15:39 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 2 Dec 2008 22:39:13 +0000 (15:39 -0700)
imp/lib/Maintenance/Task/delete_attachments_monthly.php
imp/lib/Maintenance/Task/delete_sentmail_monthly.php
imp/lib/Maintenance/Task/fetchmail_login.php
imp/lib/Maintenance/Task/purge_sentmail.php
imp/lib/Maintenance/Task/purge_spam.php
imp/lib/Maintenance/Task/purge_trash.php
imp/lib/Maintenance/Task/rename_sentmail_monthly.php
imp/lib/Maintenance/Task/tos_agreement.php
imp/lib/Maintenance/imp.php

index 8f47638..3d25703 100644 (file)
@@ -8,8 +8,8 @@
  * @author  Andrew Coleman <mercury@appisolutions.net>
  * @package Horde_Maintenance
  */
-class Maintenance_Task_delete_attachments_monthly extends Maintenance_Task {
-
+class Maintenance_Task_delete_attachments_monthly extends Maintenance_Task
+{
     /**
      * Purges the old linked attachment folders.
      *
@@ -17,17 +17,13 @@ class Maintenance_Task_delete_attachments_monthly extends Maintenance_Task {
      */
     function doMaintenance()
     {
-        global $conf, $prefs;
-
-        require_once IMP_BASE . '/lib/Compose.php';
-        require_once 'Horde/Auth.php';
         require_once 'VFS.php';
 
         /* Find the UNIX timestamp of the last second that we will not
          * purge. */
-        $del_time = gmmktime(0, 0, 0, date('n') - $prefs->getValue('delete_attachments_monthly_keep'), 1, date('Y'));
+        $del_time = gmmktime(0, 0, 0, date('n') - $GLOBALS['prefs']->getValue('delete_attachments_monthly_keep'), 1, date('Y'));
 
-        $vfs = &VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs', $conf['vfs']['type']));
+        $vfs = &VFS::singleton($GLOBALS['conf']['vfs']['type'], Horde::getDriverConfig('vfs', $GLOBALS['conf']['vfs']['type']));
         $path = IMP_Compose::VFS_LINK_ATTACH_PATH . '/' . Auth::getAuth();
 
         /* Make sure cleaning is done recursively. */
index b57db75..363ddab 100644 (file)
@@ -10,8 +10,8 @@
  * @author  Michael Slusarz <slusarz@horde.org>
  * @package Horde_Maintenance
  */
-class Maintenance_Task_delete_sentmail_monthly extends Maintenance_Task {
-
+class Maintenance_Task_delete_sentmail_monthly extends Maintenance_Task
+{
     /**
      * Purge the old sent-mail folders.
      *
@@ -25,7 +25,6 @@ class Maintenance_Task_delete_sentmail_monthly extends Maintenance_Task {
            old sent-mail folders. Then sort this array according to
            the date. */
         include_once 'Horde/Identity.php';
-        include_once IMP_BASE . '/lib/Folder.php';
 
         $identity = &Identity::singleton(array('imp', 'imp'));
         $imp_folder = &IMP_Folder::singleton();
@@ -65,9 +64,7 @@ class Maintenance_Task_delete_sentmail_monthly extends Maintenance_Task {
      */
     function describeMaintenance()
     {
-        global $prefs;
-
-        return sprintf(_("All old sent-mail folders more than %s months old will be deleted."), $prefs->getValue('delete_sentmail_monthly_keep'));
+        return sprintf(_("All old sent-mail folders more than %s months old will be deleted."), $GLOBALS['prefs']->getValue('delete_sentmail_monthly_keep'));
     }
 
 }
index 830fda9..d172070 100644 (file)
@@ -11,8 +11,8 @@
  * @author  Michael Slusarz <slusarz@horde.org>
  * @package Horde_Maintenance
  */
-class Maintenance_Task_fetchmail_login extends Maintenance_Task {
-
+class Maintenance_Task_fetchmail_login extends Maintenance_Task
+{
     /**
      * The style of the maintenance page output.
      *
index 1ac6088..4d38b9e 100644 (file)
@@ -11,8 +11,8 @@
  * @author  Jan Schneider <jan@horde.org>
  * @package Horde_Maintenance
  */
-class Maintenance_Task_purge_sentmail extends Maintenance_Task {
-
+class Maintenance_Task_purge_sentmail extends Maintenance_Task
+{
     /**
      * Purge old messages in the sent-mail folder.
      *
@@ -23,41 +23,41 @@ class Maintenance_Task_purge_sentmail extends Maintenance_Task {
     {
         global $prefs, $notification;
 
-        require_once IMP_BASE . '/lib/Folder.php';
-        require_once IMP_BASE . '/lib/Message.php';
         $imp_folder = &IMP_Folder::singleton();
-        $imp_imap = &IMP_IMAP::singleton();
         $imp_message = &IMP_Message::singleton();
 
-        $folder_list = Maintenance_Task_purge_sentmail::_getFolders();
+        $mbox_list = Maintenance_Task_purge_sentmail::_getFolders();
 
         /* Get the current UNIX timestamp minus the number of days specified
          * in 'purge_sentmail_keep'.  If a message has a timestamp prior to
          * this value, it will be deleted. */
-        $del_time = date('r', time() - ($prefs->getValue('purge_sentmail_keep') * 86400));
+        $del_time = new DateTime(time() - ($prefs->getValue('purge_sentmail_keep') * 86400));
+        $month = $del_time->format('n');
+        $day = $del_time->format('j');
+        $year = $del_time->format('Y');
 
-        foreach ($folder_list as $sentmail_folder) {
-            /* Make sure the sent-mail folder exists. */
-            if (!$imp_folder->exists($sentmail_folder)) {
+        foreach ($mbox_list as $mbox) {
+            /* Make sure the sent-mail mailbox exists. */
+            if (!$imp_folder->exists($mbox)) {
                 continue;
             }
 
             /* Open the sent-mail mailbox and get the list of messages older
              * than 'purge_sentmail_keep' days. */
-            $imp_imap->changeMbox($sentmail_folder, IMP_IMAP_AUTO);
-            $msg_ids = @imap_search($imp_imap->stream(), "BEFORE \"$del_time\"", SE_UID);
+            $query = new Horde_Imap_Client_Search_Query();
+            $query->dateSearch($month, $day, $year, Horde_Imap_Client_Search_Query::DATE_BEFORE);
+            $msg_ids = $GLOBALS['imp_search']->runSearchQuery($query, $mbox);
             if (empty($msg_ids)) {
                 continue;
             }
 
             /* Go through the message list and delete the messages. */
-            $indices = array($sentmail_folder => $msg_ids);
-            if ($imp_message->delete($indices, true)) {
+            if ($imp_message->delete(array($mbox => $msg_ids), true)) {
                 $msgcount = count($msg_ids);
                 if ($msgcount == 1) {
-                    $notification->push(sprintf(_("Purging 1 message from sent-mail folder %s."), IMP::displayFolder($sentmail_folder)), 'horde.message');
+                    $notification->push(sprintf(_("Purging 1 message from sent-mail folder %s."), IMP::displayFolder($mbox)), 'horde.message');
                 } else {
-                    $notification->push(sprintf(_("Purging %d messages from sent-mail folder."), $msgcount, IMP::displayFolder($sentmail_folder)), 'horde.message');
+                    $notification->push(sprintf(_("Purging %d messages from sent-mail folder."), $msgcount, IMP::displayFolder($mbox)), 'horde.message');
                 }
             }
         }
@@ -73,11 +73,10 @@ class Maintenance_Task_purge_sentmail extends Maintenance_Task {
      */
     function describeMaintenance()
     {
-        $folder_list = array_map(array('IMP', 'displayFolder'),
-                                 Maintenance_Task_purge_sentmail::_getFolders());
+        $mbox_list = array_map(array('IMP', 'displayFolder'), Maintenance_Task_purge_sentmail::_getFolders());
 
         return sprintf(_("All messages in the folder(s) \"%s\" older than %s days will be permanently deleted."),
-                       implode(', ', $folder_list),
+                       implode(', ', $mbox_list),
                        $GLOBALS['prefs']->getValue('purge_sentmail_keep'));
     }
 
index 9b2a7a4..f16631c 100644 (file)
@@ -11,8 +11,8 @@
  * @author  Matt Selsky <selsky@columbia.edu>
  * @package Horde_Maintenance
  */
-class Maintenance_Task_purge_spam extends Maintenance_Task {
-
+class Maintenance_Task_purge_spam extends Maintenance_Task
+{
     /**
      * Purge old messages in the Spam folder.
      *
@@ -29,7 +29,6 @@ class Maintenance_Task_purge_spam extends Maintenance_Task {
         }
 
         /* Make sure the Spam folder exists. */
-        require_once IMP_BASE . '/lib/Folder.php';
         $imp_folder = &IMP_Folder::singleton();
         if (!$imp_folder->exists($spam_folder)) {
             return false;
@@ -38,22 +37,22 @@ class Maintenance_Task_purge_spam extends Maintenance_Task {
         /* Get the current UNIX timestamp minus the number of days
            specified in 'purge_spam_keep'.  If a message has a
            timestamp prior to this value, it will be deleted. */
-        $del_time = date("r", time() - ($prefs->getValue('purge_spam_keep') * 86400));
+        $del_time = new DateTime(time() - ($prefs->getValue('purge_spam_keep') * 86400));
+        $month = $del_time->format('n');
+        $day = $del_time->format('j');
+        $year = $del_time->format('Y');
 
-        /* Open the Spam mailbox and get the list of messages older
-           than 'purge_spam_keep' days. */
-        require_once IMP_BASE . '/lib/Message.php';
-        $imp_imap = &IMP_IMAP::singleton();
-        $imp_message = &IMP_Message::singleton();
-        $imp_imap->changeMbox($spam_folder, IMP_IMAP_AUTO);
-        $msg_ids = @imap_search($imp_imap->stream(), "BEFORE \"$del_time\"", SE_UID);
+        /* Get the list of messages older than 'purge_spam_keep' days. */
+        $query = new Horde_Imap_Client_Search_Query();
+        $query->dateSearch($month, $day, $year, Horde_Imap_Client_Search_Query::DATE_BEFORE);
+        $msg_ids = $GLOBALS['imp_search']->runSearchQuery($query, $mbox);
         if (empty($msg_ids)) {
             return false;
         }
 
         /* Go through the message list and delete the messages. */
-        $indices = array($spam_folder => $msg_ids);
-        if ($imp_message->delete($indices, true)) {
+        $imp_message = &IMP_Message::singleton();
+        if ($imp_message->delete(array($spam_folder => $msg_ids), true)) {
             $msgcount = count($msg_ids);
             if ($msgcount == 1) {
                 $notification->push(_("Purging 1 message from Spam folder."), 'horde.message');
index 175dd27..d656606 100644 (file)
@@ -10,8 +10,8 @@
  * @author  Michael Slusarz <slusarz@horde.org>
  * @package Horde_Maintenance
  */
-class Maintenance_Task_purge_trash extends Maintenance_Task {
-
+class Maintenance_Task_purge_trash extends Maintenance_Task
+{
     /**
      * Purge old messages in the Trash folder.
      *
@@ -29,7 +29,6 @@ class Maintenance_Task_purge_trash extends Maintenance_Task {
         }
 
         /* Make sure the Trash folder exists. */
-        require_once IMP_BASE . '/lib/Folder.php';
         $imp_folder = &IMP_Folder::singleton();
         if (!$imp_folder->exists($trash_folder)) {
             return false;
@@ -38,22 +37,22 @@ class Maintenance_Task_purge_trash extends Maintenance_Task {
         /* Get the current UNIX timestamp minus the number of days
            specified in 'purge_trash_keep'.  If a message has a
            timestamp prior to this value, it will be deleted. */
-        $del_time = date("r", time() - ($prefs->getValue('purge_trash_keep') * 86400));
+        $del_time = new DateTime(time() - ($prefs->getValue('purge_trash_keep') * 86400));
+        $month = $del_time->format('n');
+        $day = $del_time->format('j');
+        $year = $del_time->format('Y');
 
-        /* Open the Trash mailbox and get the list of messages older
-           than 'purge_trash_keep' days. */
-        require_once IMP_BASE . '/lib/Message.php';
-        $imp_imap = &IMP_IMAP::singleton();
-        $imp_message = &IMP_Message::singleton();
-        $imp_imap->changeMbox($trash_folder, IMP_IMAP_AUTO);
-        $msg_ids = @imap_search($imp_imap->stream(), "BEFORE \"$del_time\"", SE_UID);
+        /* Get the list of messages older than 'purge_trash_keep' days. */
+        $query = new Horde_Imap_Client_Search_Query();
+        $query->dateSearch($month, $day, $year, Horde_Imap_Client_Search_Query::DATE_BEFORE);
+        $msg_ids = $GLOBALS['imp_search']->runSearchQuery($query, $mbox);
         if (empty($msg_ids)) {
             return false;
         }
 
         /* Go through the message list and delete the messages. */
-        $indices = array($trash_folder => $msg_ids);
-        if ($imp_message->delete($indices, true)) {
+        $imp_message = &IMP_Message::singleton();
+        if ($imp_message->delete(array($trash_folder => $msg_ids), true)) {
             $msgcount = count($msg_ids);
             if ($msgcount == 1) {
                 $notification->push(_("Purging 1 message from Trash folder."), 'horde.message');
index 33aeab5..a63ebaa 100644 (file)
@@ -10,8 +10,8 @@
  * @author  Michael Slusarz <slusarz@horde.org>
  * @package Horde_Maintenance
  */
-class Maintenance_Task_rename_sentmail_monthly extends Maintenance_Task {
-
+class Maintenance_Task_rename_sentmail_monthly extends Maintenance_Task
+{
     /**
      * Renames the old sent-mail folders.
      *
@@ -22,7 +22,6 @@ class Maintenance_Task_rename_sentmail_monthly extends Maintenance_Task {
         $success = true;
 
         include_once 'Horde/Identity.php';
-        include_once IMP_BASE . '/lib/Folder.php';
 
         $identity = &Identity::singleton(array('imp', 'imp'));
         $imp_folder = &IMP_Folder::singleton();
index 950406a..0c62ef8 100644 (file)
@@ -11,8 +11,8 @@
  * @author  Michael Slusarz <slusarz@horde.org>
  * @package Horde_Maintenance
  */
-class Maintenance_Task_tos_agreement extends Maintenance_Task {
-
+class Maintenance_Task_tos_agreement extends Maintenance_Task
+{
     /**
      * The style of the maintenance page output.
      *
index 12c3481..6d6d78c 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 require_once 'Horde/Maintenance.php';
-require_once $GLOBALS['registry']->get('fileroot', 'imp') . '/lib/base.php';
+require_once dirname(__FILE__) . '/../base.php';
 
 /**
  * The Maintenance_IMP class defines the maintenance operations run upon