Convert from Maintenance:: -> Horde_LoginTasks::.
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 24 Jun 2009 06:17:16 +0000 (00:17 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 24 Jun 2009 21:09:44 +0000 (15:09 -0600)
29 files changed:
imp/config/conf.xml
imp/config/prefs.php.dist
imp/docs/UPGRADING
imp/lib/LoginTasks/Task/DeleteAttachmentsMonthly.php [new file with mode: 0644]
imp/lib/LoginTasks/Task/DeleteSentmailMonthly.php [new file with mode: 0644]
imp/lib/LoginTasks/Task/PurgeSentmail.php [new file with mode: 0644]
imp/lib/LoginTasks/Task/PurgeSpam.php [new file with mode: 0644]
imp/lib/LoginTasks/Task/PurgeTrash.php [new file with mode: 0644]
imp/lib/LoginTasks/Task/RenameSentmailMonthly.php [new file with mode: 0644]
imp/lib/Maintenance/Task/delete_attachments_monthly.php [deleted file]
imp/lib/Maintenance/Task/delete_sentmail_monthly.php [deleted file]
imp/lib/Maintenance/Task/fetchmail_login.php [deleted file]
imp/lib/Maintenance/Task/purge_sentmail.php [deleted file]
imp/lib/Maintenance/Task/purge_spam.php [deleted file]
imp/lib/Maintenance/Task/purge_trash.php [deleted file]
imp/lib/Maintenance/Task/rename_sentmail_monthly.php [deleted file]
imp/lib/Maintenance/Task/tos_agreement.php [deleted file]
imp/lib/Maintenance/imp.php [deleted file]
imp/lib/Session.php
imp/lib/base.php
imp/lib/prefs.php
imp/redirect.php
kronolith/config/prefs.php.dist
kronolith/docs/UPGRADING
kronolith/lib/LoginTasks/Task/PurgeEvents.php [new file with mode: 0644]
kronolith/lib/Maintenance/Task/purge_events.php [deleted file]
kronolith/lib/Maintenance/kronolith.php [deleted file]
kronolith/lib/base.php
kronolith/lib/prefs.php

index 2c1fecb..8a37f2b 100644 (file)
    load because the list of available note categories must be generated on
    every page load), you should disable this checkbox.">true</configboolean>
   </configsection>
-
-  <configsection name="tos">
-   <configheader>Terms of Service Agreement</configheader>
-   <configstring name="file" required="false" desc="If you want to require users to
-   accept certain terms before they can use the system, enter the name of the
-   agreement file to display here. Also, make sure to activate the preference in
-   prefs.php (set the value of 'tos_agreement' to 1)."/>
-  </configsection>
  </configtab>
 
  <configtab name="mimp" desc="Mobile View (mimp) Options">
index 1985b25..18a93ca 100644 (file)
@@ -41,7 +41,8 @@ $prefGroups['logintasks'] = array(
     'column' => _("General Options"),
     'label' => _("Login Tasks"),
     'desc' => sprintf(_("Customize tasks to run upon logon to %s."), $GLOBALS['registry']->get('name')),
-    'members' => array()
+    'members' => array('delete_attachments_monthly',
+                       'delete_attachments_monthly_keep')
 );
 if (!$is_pop3) {
     $prefGroups['logintasks']['members'] = array_merge(
@@ -53,9 +54,6 @@ if (!$is_pop3) {
               'purge_trash_keep', 'purge_spam', 'purge_spam_interval',
               'purge_spam_keep'));
 }
-$prefGroups['logintasks']['members'] = array_merge(
-    $prefGroups['logintasks']['members'],
-    array('delete_attachments_monthly', 'delete_attachments_monthly_keep'));
 
 $prefGroups['compose'] = array(
     'column' => _("Message Options"),
@@ -380,7 +378,16 @@ $_prefs['acl'] = array(
 // End folder sharing preferences
 
 
-// Login/Maintenance Tasks preferences
+// Login Tasks preferences
+
+// Listing of Horde_LoginTasks constants -> strings
+$logintasks_labels = array(
+    Horde_LoginTasks::YEARLY => _("Yearly"),
+    Horde_LoginTasks::MONTHLY => _("Monthly"),
+    Horde_LoginTasks::WEEKLY => _("Weekly"),
+    Horde_LoginTasks::DAILY => _("Daily"),
+    Horde_LoginTasks::EVERY => _("Every Login")
+);
 
 // select widget for the initial_page preference
 $_prefs['initialpageselect'] = array('type' => 'special');
@@ -430,12 +437,12 @@ $_prefs['purge_sentmail'] = array(
     'help' => 'prefs-purge_sentmail');
 
 // how often to purge the Sent-Mail folder?
-// 'value': yearly = 1, monthly = 2, weekly = 3, daily = 4, every login = 5
 $_prefs['purge_sentmail_interval'] = array(
-    'value' => '2',
+    'value' => Horde_LoginTasks::MONTHLY,
     'locked' => false,
     'shared' => false,
-    'type' => 'select',
+    'type' => 'enum',
+    'enum' => $logintasks_labels,
     'desc' => _("Purge sent-mail how often:"),
     'help' => 'prefs-purge_sentmail_interval');
 
@@ -476,12 +483,12 @@ $_prefs['purge_spam'] = array(
     'help' => 'prefs-purge_spam');
 
 // how often to purge the Spam folder?
-// 'value': yearly = 1, monthly = 2, weekly = 3, daily = 4, every login = 5
 $_prefs['purge_spam_interval'] = array(
-    'value' => '2',
+    'value' => Horde_LoginTasks::MONTHLY,
     'locked' => false,
     'shared' => false,
-    'type' => 'select',
+    'type' => 'enum',
+    'enum' => $logintasks_labels,
     'desc' => _("Purge Spam how often:"),
     'help' => 'prefs-purge_spam_interval');
 
@@ -504,12 +511,12 @@ $_prefs['purge_trash'] = array(
     'help' => 'prefs-purge_trash');
 
 // how often to purge the Trash folder?
-// 'value': yearly = 1, monthly = 2, weekly = 3, daily = 4, every login = 5
 $_prefs['purge_trash_interval'] = array(
-    'value' => '2',
+    'value' => Horde_LoginTasks::MONTHLY,
     'locked' => false,
     'shared' => false,
-    'type' => 'select',
+    'type' => 'enum',
+    'enum' => $logintasks_labels,
     'desc' => _("Purge Trash how often:"),
     'help' => 'prefs-purge_trash_interval');
 
@@ -522,14 +529,7 @@ $_prefs['purge_trash_keep'] = array(
     'desc' => _("Purge messages in Trash folder older than this amount of days."),
     'help' => 'prefs-purge_trash_keep');
 
-// show tos agreement?
-$_prefs['tos_agreement'] = array(
-    'value' => 0,
-    'locked' => false,
-    'shared' => false,
-    'type' => 'implicit');
-
-// End Login/Maintenance preferences
+// End Login Tasks preferences
 
 
 // Message Composition preferences
index 7256c33..cfdca24 100644 (file)
@@ -29,6 +29,8 @@ supported.
 *  x-priority now handled in the core code
 *  old attachment icon handling see atc_flag pref
 *  imp_hook_msglist_flags hook now used to dynamically set flags on messages
+* maintenance tasks
+* tos_agreement (moved to Horde)
 
 
 
diff --git a/imp/lib/LoginTasks/Task/DeleteAttachmentsMonthly.php b/imp/lib/LoginTasks/Task/DeleteAttachmentsMonthly.php
new file mode 100644 (file)
index 0000000..9352876
--- /dev/null
@@ -0,0 +1,66 @@
+<?php
+/**
+ * Login tasks module that deletes old linked attachments.
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author  Andrew Coleman <mercury@appisolutions.net>
+ * @package Horde_LoginTasks
+ */
+class IMP_LoginTasks_Task_DeleteAttachmentsMonthly extends Horde_LoginTasks_Task
+{
+    /**
+     * Constructor.
+     */
+    public function __construct()
+    {
+        $this->active = $GLOBALS['prefs']->getValue('delete_attachments_monthly');
+        if ($this->active &&
+            $GLOBALS['prefs']->isLocked('delete_attachments_monthly')) {
+            $this->display = Horde_LoginTasks::DISPLAY_NONE;
+        }
+    }
+
+    /**
+     * Purges the old linked attachment folders.
+     *
+     * @return boolean  Whether any old attachments were deleted.
+     */
+    public function execute()
+    {
+        /* Find the UNIX timestamp of the last second that we will not
+         * purge. */
+        $del_time = gmmktime(0, 0, 0, date('n') - $GLOBALS['prefs']->getValue('delete_attachments_monthly_keep'), 1, date('Y'));
+
+        $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. */
+        $files = $vfs->listFolder($path, null, true, false, true);
+        if (is_a($files, 'PEAR_Error') || !is_array($files)) {
+            return false;
+        }
+
+        foreach ($files as $dir) {
+            $filetime = (isset($dir['date'])) ? $dir['date'] : intval(basename($dir['name']));
+            if ($del_time > $filetime) {
+                $vfs->deleteFolder($path, $dir['name'], true);
+            }
+        }
+
+        return true;
+    }
+
+    /**
+     * Returns information for the login task.
+     *
+     * @return string  Description of what the operation is going to do during
+     *                 this login.
+     */
+    public function describe()
+    {
+        return sprintf(_("All old linked attachments more than %s months old will be deleted."), $GLOBALS['prefs']->getValue('delete_attachments_monthly_keep'));
+    }
+
+}
diff --git a/imp/lib/LoginTasks/Task/DeleteSentmailMonthly.php b/imp/lib/LoginTasks/Task/DeleteSentmailMonthly.php
new file mode 100644 (file)
index 0000000..6e1b440
--- /dev/null
@@ -0,0 +1,79 @@
+<?php
+/**
+ * Logint tasks module that deletes old sent-mail folders.
+ *
+ * Copyright 2001-2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author  Michael Slusarz <slusarz@horde.org>
+ * @package Horde_LoginTasks
+ */
+class IMP_LoginTasks_Task_DeleteSentmailMonthly extends Horde_LoginTasks_Task
+{
+    /**
+     * Constructor.
+     */
+    public function __construct()
+    {
+        $this->active = $GLOBALS['prefs']->getValue('delete_sentmail_monthly');
+        if ($this->active &&
+            $GLOBALS['prefs']->isLocked('delete_sentmail_monthly')) {
+            $this->display = Horde_LoginTasks::DISPLAY_NONE;
+        }
+    }
+
+    /**
+     * Purge the old sent-mail folders.
+     *
+     * @return boolean  Whether any sent-mail folders were deleted.
+     */
+    public function execute()
+    {
+        /* Get list of all folders, parse through and get the list of all
+           old sent-mail folders. Then sort this array according to
+           the date. */
+        include_once 'Horde/Identity.php';
+        $identity = &Identity::singleton(array('imp', 'imp'));
+        $imp_folder = &IMP_Folder::singleton();
+        $sent_mail_folders = $identity->getAllSentmailFolders();
+
+        $folder_array = array();
+        $old_folders = $imp_folder->flist();
+
+        foreach (array_keys($old_folders) as $k) {
+            foreach ($sent_mail_folders as $folder) {
+                if (preg_match('/^' . str_replace('/', '\/', $folder) . '-([^-]+)-([0-9]{4})$/i', $k, $regs)) {
+                    $folder_array[$k] = Horde_String::convertCharset((is_numeric($regs[1])) ? mktime(0, 0, 0,$regs[1], 1, $regs[2]) : strtotime("$regs[1] 1, $regs[2]"), NLS::getCharset(), 'UTF7-IMAP');
+                }
+            }
+        }
+        arsort($folder_array, SORT_NUMERIC);
+
+        /* See if any folders need to be purged. */
+        $purge_folders = array_slice(array_keys($folder_array), $GLOBALS['prefs']->getValue('delete_sentmail_monthly_keep'));
+        if (count($purge_folders)) {
+            $GLOBALS['notification']->push(_("Old sent-mail folders being purged."), 'horde.message');
+
+            /* Delete the old folders now. */
+            if ($imp_folder->delete($purge_folders, true)) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    /**
+     * Return information for the login task.
+     *
+     * @return string  Description of what the operation is going to do during
+     *                 this login.
+     */
+    public function describe()
+    {
+        return sprintf(_("All old sent-mail folders more than %s months old will be deleted."), $GLOBALS['prefs']->getValue('delete_sentmail_monthly_keep'));
+    }
+
+}
diff --git a/imp/lib/LoginTasks/Task/PurgeSentmail.php b/imp/lib/LoginTasks/Task/PurgeSentmail.php
new file mode 100644 (file)
index 0000000..335560e
--- /dev/null
@@ -0,0 +1,103 @@
+<?php
+/**
+ * Login tasks module that purges old messages in the sent-mail folder.
+ *
+ * Copyright 2001-2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author  Michael Slusarz <slusarz@horde.org>
+ * @author  Jan Schneider <jan@horde.org>
+ * @package Horde_LoginTasks
+ */
+class IMP_LoginTasks_Task_PurgeSentmail extends Horde_LoginTasks_Task
+{
+    /**
+     * Constructor.
+     */
+    public function __construct()
+    {
+        $this->active = $GLOBALS['prefs']->getValue('purge_sentmail');
+        if ($this->active) {
+            $this->interval = $GLOBALS['prefs']->getValue('purge_sentmail_interval');
+            if ($GLOBALS['prefs']->isLocked('purge_sentmail')) {
+                $this->display = Horde_LoginTasks::DISPLAY_NONE;
+            }
+        }
+    }
+
+    /**
+     * Purge old messages in the sent-mail folder.
+     *
+     * @return boolean  Whether any messages were purged from the sent-mail
+     *                  folder.
+     */
+    public function execute()
+    {
+        $imp_folder = IMP_Folder::singleton();
+        $imp_message = IMP_Message::singleton();
+
+        $mbox_list = $this->_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 = new Horde_Date(time() - ($GLOBALS['prefs']->getValue('purge_sentmail_keep') * 86400));
+
+        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. */
+            $query = new Horde_Imap_Client_Search_Query();
+            $query->dateSearch($del_time, 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. */
+            if ($imp_message->delete(array($mbox => $msg_ids), array('nuke' => true))) {
+                $msgcount = count($msg_ids);
+                if ($msgcount == 1) {
+                    $GLOBALS['notification']->push(sprintf(_("Purging 1 message from sent-mail folder %s."), IMP::displayFolder($mbox)), 'horde.message');
+                } else {
+                    $GLOBALS['notification']->push(sprintf(_("Purging %d messages from sent-mail folder."), $msgcount, IMP::displayFolder($mbox)), 'horde.message');
+                }
+            }
+        }
+
+        return true;
+    }
+
+    /**
+     * Return information for the login task.
+     *
+     * @return string  Description of what the operation is going to do during
+     *                 this login.
+     */
+    public function describe()
+    {
+        $mbox_list = array_map(array('IMP', 'displayFolder'), $this->_getFolders());
+
+        return sprintf(_("All messages in the folder(s) \"%s\" older than %s days will be permanently deleted."),
+                       implode(', ', $mbox_list),
+                       $GLOBALS['prefs']->getValue('purge_sentmail_keep'));
+    }
+
+    /**
+     * Returns the list of sent-mail folders.
+     *
+     * @return array  All sent-mail folders.
+     */
+    protected function _getFolders()
+    {
+        require_once 'Horde/Identity.php';
+        return Identity::singleton(array('imp', 'imp'))->getAllSentmailfolders();
+    }
+
+}
diff --git a/imp/lib/LoginTasks/Task/PurgeSpam.php b/imp/lib/LoginTasks/Task/PurgeSpam.php
new file mode 100644 (file)
index 0000000..244ff32
--- /dev/null
@@ -0,0 +1,85 @@
+<?php
+/**
+ * Login tasks module that purges old messages in the Spam folder.  Based on
+ * the purge_trash task, written by Michael Slusarz <slusarz@horde.org>.
+ *
+ * Copyright 2006-2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author  Matt Selsky <selsky@columbia.edu>
+ * @package Horde_LoginTasks
+ */
+class IMP_LoginTasks_Task_PurgeSpam extends Horde_LoginTasks_Task
+{
+    /**
+     * Constructor.
+     */
+    public function __construct()
+    {
+        $this->active = $GLOBALS['prefs']->getValue('purge_spam');
+        if ($this->active) {
+            $this->interval = $GLOBALS['prefs']->getValue('purge_spam_interval');
+            if ($GLOBALS['prefs']->isLocked('purge_spam')) {
+                $this->display = Horde_LoginTasks::DISPLAY_NONE;
+            }
+        }
+    }
+
+    /**
+     * Purge old messages in the Spam folder.
+     *
+     * @return boolean  Whether any messages were purged from the Spam folder.
+     */
+    public function execute()
+    {
+        /* If there is no Spam folder set, just return. */
+        $spam_folder = IMP::folderPref($GLOBALS['prefs']->getValue('spam_folder'), true);
+        if (!$spam_folder) {
+            return false;
+        }
+
+        /* Make sure the Spam folder exists. */
+        $imp_folder = IMP_Folder::singleton();
+        if (!$imp_folder->exists($spam_folder)) {
+            return false;
+        }
+
+        /* 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 = new Horde_Date(time() - ($GLOBALS['prefs']->getValue('purge_spam_keep') * 86400));
+
+        /* Get the list of messages older than 'purge_spam_keep' days. */
+        $query = new Horde_Imap_Client_Search_Query();
+        $query->dateSearch($del_time, Horde_Imap_Client_Search_Query::DATE_BEFORE);
+        $msg_ids = $GLOBALS['imp_search']->runSearchQuery($query, $spam_folder);
+        if (empty($msg_ids)) {
+            return false;
+        }
+
+        /* Go through the message list and delete the messages. */
+        $imp_message = IMP_Message::singleton();
+        if ($imp_message->delete(array($spam_folder => $msg_ids), array('nuke' => true))) {
+            $msgcount = count($msg_ids);
+            $notification->push(sprintf(ngettext("Purging %d message from Spam folder.", "Purging %d messages from Spam folder.", $msgcount), $msgcount), 'horde.message');
+        }
+
+        return true;
+    }
+
+    /**
+     * Return information for the login task.
+     *
+     * @return string  Description of what the operation is going to do during
+     *                 this login.
+     */
+    public function describe()
+    {
+        return sprintf(_("All messages in your \"%s\" folder older than %s days will be permanently deleted."),
+                       IMP::displayFolder(IMP::folderPref($GLOBALS['prefs']->getValue('spam_folder'), true)),
+                       $GLOBALS['prefs']->getValue('purge_spam_keep'));
+    }
+
+}
diff --git a/imp/lib/LoginTasks/Task/PurgeTrash.php b/imp/lib/LoginTasks/Task/PurgeTrash.php
new file mode 100644 (file)
index 0000000..6fad947
--- /dev/null
@@ -0,0 +1,85 @@
+<?php
+/**
+ * Login tasks module that purges old messages in the Trash folder.
+ *
+ * Copyright 2001-2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author  Michael Slusarz <slusarz@horde.org>
+ * @package Horde_LoginTasks
+ */
+class IMP_LoginTasks_Task_PurgeTrash extends Horde_LoginTasks_Task
+{
+    /**
+     * Constructor.
+     */
+    public function __construct()
+    {
+        $this->active = $GLOBALS['prefs']->getValue('purge_trash');
+        if ($this->active) {
+            $this->interval = $GLOBALS['prefs']->getValue('purge_trash_interval');
+            if ($GLOBALS['prefs']->isLocked('purge_trash')) {
+                $this->display = Horde_LoginTasks::DISPLAY_NONE;
+            }
+        }
+    }
+
+    /**
+     * Purge old messages in the Trash folder.
+     *
+     * @return boolean  Whether any messages were purged from the Trash folder.
+     */
+    public function execute()
+    {
+        /* If we aren't using a Trash folder or if there is no Trash
+           folder set, just return. */
+        $trash_folder = IMP::folderPref($GLOBALS['prefs']->getValue('trash_folder'), true);
+        if (!$GLOBALS['prefs']->getValue('use_trash') || !$trash_folder) {
+            return false;
+        }
+
+        /* Make sure the Trash folder exists. */
+        $imp_folder = IMP_Folder::singleton();
+        if (!$imp_folder->exists($trash_folder)) {
+            return false;
+        }
+
+        /* 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 = new Horde_Date(time() - ($GLOBALS['prefs']->getValue('purge_trash_keep') * 86400));
+
+        /* Get the list of messages older than 'purge_trash_keep' days. */
+        $query = new Horde_Imap_Client_Search_Query();
+        $query->dateSearch($del_time, Horde_Imap_Client_Search_Query::DATE_BEFORE);
+        $msg_ids = $GLOBALS['imp_search']->runSearchQuery($query, $trash_folder);
+        if (empty($msg_ids)) {
+            return false;
+        }
+
+        /* Go through the message list and delete the messages. */
+        $imp_message = IMP_Message::singleton();
+        if ($imp_message->delete(array($trash_folder => $msg_ids), array('nuke' => true))) {
+            $msgcount = count($msg_ids);
+            $notification->push(sprintf(ngettext("Purging %d message from Trash folder.", "Purging %d messages from Trash folder.", $msgcount), $msgcount), 'horde.message');
+        }
+
+        return true;
+    }
+
+    /**
+     * Return information for the login task.
+     *
+     * @return string  Description of what the operation is going to do during
+     *                 this login.
+     */
+    public function describe()
+    {
+        return sprintf(_("All messages in your \"%s\" folder older than %s days will be permanently deleted."),
+                       IMP::displayFolder(IMP::folderPref($GLOBALS['prefs']->getValue('trash_folder'), true)),
+                       $GLOBALS['prefs']->getValue('purge_trash_keep'));
+    }
+
+}
diff --git a/imp/lib/LoginTasks/Task/RenameSentmailMonthly.php b/imp/lib/LoginTasks/Task/RenameSentmailMonthly.php
new file mode 100644 (file)
index 0000000..a84cbd1
--- /dev/null
@@ -0,0 +1,108 @@
+<?php
+/**
+ * Login tasks module that renames the sent-mail folder.
+ *
+ * Copyright 2001-2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author  Michael Slusarz <slusarz@horde.org>
+ * @package Horde_LoginTasks
+ */
+class IMP_LoginTasks_Task_RenameSentmailMonthly extends Horde_LoginTasks_Task
+{
+    /**
+     * Constructor.
+     */
+    public function __construct()
+    {
+        $this->active = $GLOBALS['prefs']->getValue('rename_sentmail_monthly');
+        if ($this->active &&
+            $GLOBALS['prefs']->isLocked('rename_sentmail_monthly')) {
+            $this->display = Horde_LoginTasks::DISPLAY_NONE;
+        }
+    }
+
+    /**
+     * Renames the old sent-mail folders.
+     *
+     * @return boolean  Whether all sent-mail folders were renamed.
+     */
+    public function execute()
+    {
+        $success = true;
+
+        include_once 'Horde/Identity.php';
+
+        $identity = &Identity::singleton(array('imp', 'imp'));
+        $imp_folder = &IMP_Folder::singleton();
+
+        foreach ($identity->getAllSentmailfolders() as $sent_folder) {
+            /* Display a message to the user and rename the folder.
+               Only do this if sent-mail folder currently exists. */
+            if ($imp_folder->exists($sent_folder)) {
+                $old_folder = $this->_renameSentmailMonthlyName($sent_folder);
+                $GLOBALS['notification']->push(sprintf(_("%s folder being renamed at the start of the month."), IMP::displayFolder($sent_folder)), 'horde.message');
+                if ($imp_folder->exists($old_folder)) {
+                    $GLOBALS['notification']->push(sprintf(_("%s already exists. Your %s folder was not renamed."), IMP::displayFolder($old_folder), IMP::displayFolder($sent_folder)), 'horde.warning');
+                    $success = false;
+                } else {
+                    $success =
+                        $imp_folder->rename($sent_folder, $old_folder, true) &&
+                        $imp_folder->create($sent_folder, $GLOBALS['prefs']->getValue('subscribe'));
+                }
+            }
+        }
+
+        return $success;
+    }
+
+    /**
+     * Returns information for the login task.
+     *
+     * @return string  Description of what the operation is going to do during
+     *                 this login.
+     */
+    public function describe()
+    {
+        include_once 'Horde/Identity.php';
+        $identity = &Identity::singleton(array('imp', 'imp'));
+
+        $new_folders = $old_folders = array();
+        foreach ($identity->getAllSentmailfolders() as $folder) {
+            $old_folders[] = IMP::displayFolder($folder);
+            $new_folders[] = IMP::displayFolder($this->_renameSentmailMonthlyName($folder));
+        }
+
+        return sprintf(_("The current folder(s) \"%s\" will be renamed to \"%s\"."), implode(', ', $old_folders), implode(', ', $new_folders));
+    }
+
+    /**
+     * Determines the name the sent-mail folder will be renamed to.
+     * <pre>
+     * Folder name: sent-mail-month-year
+     *   month = English:         3 letter abbreviation
+     *           Other Languages: Month value (01-12)
+     *   year  = 4 digit year
+     * The folder name needs to be in this specific format (as opposed to a
+     *   user-defined one) to ensure that 'delete_sentmail_monthly' processing
+     *   can accurately find all the old sent-mail folders.
+     * </pre>
+     *
+     * @param string $folder  The name of the sent-mail folder to rename.
+     *
+     * @return string  New sent-mail folder name.
+     */
+    protected function _renameSentmailMonthlyName($folder)
+    {
+        // @TODO
+        $last_maintenance = $GLOBALS['prefs']->getValue('last_maintenance');
+        $last_maintenance = empty($last_maintenance) ? mktime(0, 0, 0, date('m') - 1, 1) : $last_maintenance;
+
+        $text = (substr($GLOBALS['language'], 0, 2) == 'en') ? strtolower(strftime('-%b-%Y', $last_maintenance)) : strftime('-%m-%Y', $last_maintenance);
+
+        return $folder . Horde_String::convertCharset($text, NLS::getExternalCharset(), 'UTF7-IMAP');
+    }
+
+}
diff --git a/imp/lib/Maintenance/Task/delete_attachments_monthly.php b/imp/lib/Maintenance/Task/delete_attachments_monthly.php
deleted file mode 100644 (file)
index 81e0ec8..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-<?php
-/**
- * Maintenance module that deletes old linked attachments.
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @author  Andrew Coleman <mercury@appisolutions.net>
- * @package Horde_Maintenance
- */
-class Maintenance_Task_delete_attachments_monthly extends Maintenance_Task
-{
-    /**
-     * Purges the old linked attachment folders.
-     *
-     * @return boolean  Whether any old attachments were deleted.
-     */
-    public function doMaintenance()
-    {
-        /* Find the UNIX timestamp of the last second that we will not
-         * purge. */
-        $del_time = gmmktime(0, 0, 0, date('n') - $GLOBALS['prefs']->getValue('delete_attachments_monthly_keep'), 1, date('Y'));
-
-        $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. */
-        $files = $vfs->listFolder($path, null, true, false, true);
-        if (is_a($files, 'PEAR_Error') || !is_array($files)) {
-            return false;
-        }
-
-        foreach ($files as $dir) {
-            $filetime = (isset($dir['date'])) ? $dir['date'] : intval(basename($dir['name']));
-            if ($del_time > $filetime) {
-                $vfs->deleteFolder($path, $dir['name'], true);
-            }
-        }
-
-        return true;
-    }
-
-    /**
-     * Returns information for the maintenance function.
-     *
-     * @return string  Description of what the operation is going to do during
-     *                 this login.
-     */
-    public function describeMaintenance()
-    {
-        return sprintf(_("All old linked attachments more than %s months old will be deleted."), $GLOBALS['prefs']->getValue('delete_attachments_monthly_keep'));
-    }
-
-}
diff --git a/imp/lib/Maintenance/Task/delete_sentmail_monthly.php b/imp/lib/Maintenance/Task/delete_sentmail_monthly.php
deleted file mode 100644 (file)
index 0b8846a..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-<?php
-/**
- * Maintenance module that deletes old sent-mail folders.
- *
- * Copyright 2001-2009 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @author  Michael Slusarz <slusarz@horde.org>
- * @package Horde_Maintenance
- */
-class Maintenance_Task_delete_sentmail_monthly extends Maintenance_Task
-{
-    /**
-     * Purge the old sent-mail folders.
-     *
-     * @return boolean  Whether any sent-mail folders were deleted.
-     */
-    function doMaintenance()
-    {
-        global $notification, $prefs;
-
-        /* Get list of all folders, parse through and get the list of all
-           old sent-mail folders. Then sort this array according to
-           the date. */
-        include_once 'Horde/Identity.php';
-
-        $identity = &Identity::singleton(array('imp', 'imp'));
-        $imp_folder = &IMP_Folder::singleton();
-        $sent_mail_folders = $identity->getAllSentmailFolders();
-
-        $folder_array = array();
-        $old_folders = $imp_folder->flist();
-
-        foreach (array_keys($old_folders) as $k) {
-            foreach ($sent_mail_folders as $folder) {
-                if (preg_match('/^' . str_replace('/', '\/', $folder) . '-([^-]+)-([0-9]{4})$/i', $k, $regs)) {
-                    $folder_array[$k] = Horde_String::convertCharset((is_numeric($regs[1])) ? mktime(0, 0, 0,$regs[1], 1, $regs[2]) : strtotime("$regs[1] 1, $regs[2]"), NLS::getCharset(), 'UTF7-IMAP');
-                }
-            }
-        }
-        arsort($folder_array, SORT_NUMERIC);
-
-        /* See if any folders need to be purged. */
-        $purge_folders = array_slice(array_keys($folder_array), $prefs->getValue('delete_sentmail_monthly_keep'));
-        if (count($purge_folders)) {
-            $notification->push(_("Old sent-mail folders being purged."), 'horde.message');
-
-            /* Delete the old folders now. */
-            if ($imp_folder->delete($purge_folders, true)) {
-                return true;
-            }
-        }
-
-        return false;
-    }
-
-    /**
-     * Return information for the maintenance function.
-     *
-     * @return string  Description of what the operation is going to do during
-     *                 this login.
-     */
-    function describeMaintenance()
-    {
-        return sprintf(_("All old sent-mail folders more than %s months old will be deleted."), $GLOBALS['prefs']->getValue('delete_sentmail_monthly_keep'));
-    }
-
-}
diff --git a/imp/lib/Maintenance/Task/fetchmail_login.php b/imp/lib/Maintenance/Task/fetchmail_login.php
deleted file mode 100644 (file)
index 4b56ef3..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-<?php
-/**
- * Copyright 2003-2009 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * Maintenance module that fetch mail upon login
- *
- * @author  Nuno Loureiro <nuno@co.sapo.pt>
- * @author  Michael Slusarz <slusarz@horde.org>
- * @package Horde_Maintenance
- */
-class Maintenance_Task_fetchmail_login extends Maintenance_Task
-{
-    /**
-     * The style of the maintenance page output.
-     *
-     * @var integer
-     */
-    var $_display_type = MAINTENANCE_OUTPUT_CONFIRM;
-
-    /**
-     * Fetch email from other accounts.
-     */
-    function doMaintenance()
-    {
-        $fm_account = new IMP_Fetchmail_Account();
-
-        /* If the user wants to fetch emails from other accounts on login,
-         * go get those messages now. */
-        if ($fm_account->count()) {
-            $fm_list = array();
-
-            foreach ($fm_account->getAll('loginfetch') as $id => $val) {
-                if ($val) {
-                    $fm_list[] = $id;
-                }
-            }
-
-            if (!empty($fm_list)) {
-                IMP_Fetchmail::fetchmail($fm_list);
-            }
-        }
-    }
-
-    /**
-     * Returns the summary of the accounts to fetch email from.
-     *
-     * @return string  The summary of the accounts to fetch email from.
-     */
-    function describeMaintenance()
-    {
-        $str  = _("You are about to fetch email from the following account(s):") . "\n<blockquote>\n";
-
-        $fm_account = new IMP_Fetchmail_Account();
-        if ($fm_account->count()) {
-            foreach ($fm_account->getAll('loginfetch') as $id => $val) {
-                if ($val) {
-                    $str .= " - " . $fm_account->getValue('id', $id) . "<br />\n";
-                }
-            }
-        }
-
-        $str .= "\n</blockquote>\n<strong>" . _("Note that this can take some time") . ".</strong>\n";
-
-        return $str;
-    }
-
-}
diff --git a/imp/lib/Maintenance/Task/purge_sentmail.php b/imp/lib/Maintenance/Task/purge_sentmail.php
deleted file mode 100644 (file)
index e4c3ad6..0000000
+++ /dev/null
@@ -1,91 +0,0 @@
-<?php
-/**
- * Maintenance module that purges old messages in the sent-mail folder.
- *
- * Copyright 2001-2009 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @author  Michael Slusarz <slusarz@horde.org>
- * @author  Jan Schneider <jan@horde.org>
- * @package Horde_Maintenance
- */
-class Maintenance_Task_purge_sentmail extends Maintenance_Task
-{
-    /**
-     * Purge old messages in the sent-mail folder.
-     *
-     * @return boolean  Whether any messages were purged from the sent-mail
-     *                  folder.
-     */
-    function doMaintenance()
-    {
-        global $prefs, $notification;
-
-        $imp_folder = IMP_Folder::singleton();
-        $imp_message = IMP_Message::singleton();
-
-        $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 = new Horde_Date(time() - ($prefs->getValue('purge_sentmail_keep') * 86400));
-
-        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. */
-            $query = new Horde_Imap_Client_Search_Query();
-            $query->dateSearch($del_time, 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. */
-            if ($imp_message->delete(array($mbox => $msg_ids), array('nuke' => true))) {
-                $msgcount = count($msg_ids);
-                if ($msgcount == 1) {
-                    $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($mbox)), 'horde.message');
-                }
-            }
-        }
-
-        return true;
-    }
-
-    /**
-     * Return information for the maintenance function.
-     *
-     * @return string  Description of what the operation is going to do during
-     *                 this login.
-     */
-    function describeMaintenance()
-    {
-        $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(', ', $mbox_list),
-                       $GLOBALS['prefs']->getValue('purge_sentmail_keep'));
-    }
-
-    /**
-     * Returns the list of sent-mail folders.
-     *
-     * @return array  All sent-mail folders.
-     */
-    function _getFolders()
-    {
-        require_once 'Horde/Identity.php';
-        return Identity::singleton(array('imp', 'imp'))->getAllSentmailfolders();
-    }
-
-}
diff --git a/imp/lib/Maintenance/Task/purge_spam.php b/imp/lib/Maintenance/Task/purge_spam.php
deleted file mode 100644 (file)
index cced3fd..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-<?php
-/**
- * Maintenance module that purges old messages in the Spam folder.  Based on
- * the purge_trash task, written by Michael Slusarz <slusarz@horde.org>.
- *
- * Copyright 2006-2009 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @author  Matt Selsky <selsky@columbia.edu>
- * @package Horde_Maintenance
- */
-class Maintenance_Task_purge_spam extends Maintenance_Task
-{
-    /**
-     * Purge old messages in the Spam folder.
-     *
-     * @return boolean  Whether any messages were purged from the Spam folder.
-     */
-    function doMaintenance()
-    {
-        global $prefs, $notification;
-
-        /* If there is no Spam folder set, just return. */
-        $spam_folder = IMP::folderPref($prefs->getValue('spam_folder'), true);
-        if (!$spam_folder) {
-            return false;
-        }
-
-        /* Make sure the Spam folder exists. */
-        $imp_folder = IMP_Folder::singleton();
-        if (!$imp_folder->exists($spam_folder)) {
-            return false;
-        }
-
-        /* 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 = new Horde_Date(time() - ($prefs->getValue('purge_spam_keep') * 86400));
-
-        /* Get the list of messages older than 'purge_spam_keep' days. */
-        $query = new Horde_Imap_Client_Search_Query();
-        $query->dateSearch($del_time, Horde_Imap_Client_Search_Query::DATE_BEFORE);
-        $msg_ids = $GLOBALS['imp_search']->runSearchQuery($query, $spam_folder);
-        if (empty($msg_ids)) {
-            return false;
-        }
-
-        /* Go through the message list and delete the messages. */
-        $imp_message = IMP_Message::singleton();
-        if ($imp_message->delete(array($spam_folder => $msg_ids), array('nuke' => true))) {
-            $msgcount = count($msg_ids);
-            if ($msgcount == 1) {
-                $notification->push(_("Purging 1 message from Spam folder."), 'horde.message');
-            } else {
-                $notification->push(sprintf(_("Purging %d messages from Spam folder."), $msgcount), 'horde.message');
-            }
-        }
-
-        return true;
-    }
-
-    /**
-     * Return information for the maintenance function.
-     *
-     * @return string  Description of what the operation is going to do during
-     *                 this login.
-     */
-    function describeMaintenance()
-    {
-        return sprintf(_("All messages in your \"%s\" folder older than %s days will be permanently deleted."),
-                       IMP::displayFolder(IMP::folderPref($GLOBALS['prefs']->getValue('spam_folder'), true)),
-                       $GLOBALS['prefs']->getValue('purge_spam_keep'));
-    }
-
-}
diff --git a/imp/lib/Maintenance/Task/purge_trash.php b/imp/lib/Maintenance/Task/purge_trash.php
deleted file mode 100644 (file)
index 205c6f1..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-<?php
-/**
- * Maintenance module that purges old messages in the Trash folder.
- *
- * Copyright 2001-2009 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @author  Michael Slusarz <slusarz@horde.org>
- * @package Horde_Maintenance
- */
-class Maintenance_Task_purge_trash extends Maintenance_Task
-{
-    /**
-     * Purge old messages in the Trash folder.
-     *
-     * @return boolean  Whether any messages were purged from the Trash folder.
-     */
-    function doMaintenance()
-    {
-        global $prefs, $notification;
-
-        /* If we aren't using a Trash folder or if there is no Trash
-           folder set, just return. */
-        $trash_folder = IMP::folderPref($prefs->getValue('trash_folder'), true);
-        if (!$prefs->getValue('use_trash') || !$trash_folder) {
-            return false;
-        }
-
-        /* Make sure the Trash folder exists. */
-        $imp_folder = IMP_Folder::singleton();
-        if (!$imp_folder->exists($trash_folder)) {
-            return false;
-        }
-
-        /* 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 = new Horde_Date(time() - ($prefs->getValue('purge_trash_keep') * 86400));
-
-        /* Get the list of messages older than 'purge_trash_keep' days. */
-        $query = new Horde_Imap_Client_Search_Query();
-        $query->dateSearch($del_time, Horde_Imap_Client_Search_Query::DATE_BEFORE);
-        $msg_ids = $GLOBALS['imp_search']->runSearchQuery($query, $trash_folder);
-        if (empty($msg_ids)) {
-            return false;
-        }
-
-        /* Go through the message list and delete the messages. */
-        $imp_message = IMP_Message::singleton();
-        if ($imp_message->delete(array($trash_folder => $msg_ids), array('nuke' => true))) {
-            $msgcount = count($msg_ids);
-            if ($msgcount == 1) {
-                $notification->push(_("Purging 1 message from Trash folder."), 'horde.message');
-            } else {
-                $notification->push(sprintf(_("Purging %d messages from Trash folder."), $msgcount), 'horde.message');
-            }
-        }
-
-        return true;
-    }
-
-    /**
-     * Return information for the maintenance function.
-     *
-     * @return string  Description of what the operation is going to do during
-     *                 this login.
-     */
-    function describeMaintenance()
-    {
-        return sprintf(_("All messages in your \"%s\" folder older than %s days will be permanently deleted."),
-                       IMP::displayFolder(IMP::folderPref($GLOBALS['prefs']->getValue('trash_folder'), true)),
-                       $GLOBALS['prefs']->getValue('purge_trash_keep'));
-    }
-
-}
diff --git a/imp/lib/Maintenance/Task/rename_sentmail_monthly.php b/imp/lib/Maintenance/Task/rename_sentmail_monthly.php
deleted file mode 100644 (file)
index 8f8c07c..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-<?php
-/**
- * Maintenance module that renames the sent-mail folder.
- *
- * Copyright 2001-2009 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @author  Michael Slusarz <slusarz@horde.org>
- * @package Horde_Maintenance
- */
-class Maintenance_Task_rename_sentmail_monthly extends Maintenance_Task
-{
-    /**
-     * Renames the old sent-mail folders.
-     *
-     * @return boolean  Whether all sent-mail folders were renamed.
-     */
-    function doMaintenance()
-    {
-        $success = true;
-
-        include_once 'Horde/Identity.php';
-
-        $identity = &Identity::singleton(array('imp', 'imp'));
-        $imp_folder = &IMP_Folder::singleton();
-
-        foreach ($identity->getAllSentmailfolders() as $sent_folder) {
-            /* Display a message to the user and rename the folder.
-               Only do this if sent-mail folder currently exists. */
-            if ($imp_folder->exists($sent_folder)) {
-                $old_folder = Maintenance_Task_rename_sentmail_monthly::_renameSentmailMonthlyName($sent_folder);
-                $GLOBALS['notification']->push(sprintf(_("%s folder being renamed at the start of the month."), IMP::displayFolder($sent_folder)), 'horde.message');
-                if ($imp_folder->exists($old_folder)) {
-                    $GLOBALS['notification']->push(sprintf(_("%s already exists. Your %s folder was not renamed."), IMP::displayFolder($old_folder), IMP::displayFolder($sent_folder)), 'horde.warning');
-                    $success = false;
-                } else {
-                    $success =
-                        $imp_folder->rename($sent_folder, $old_folder, true) &&
-                        $imp_folder->create($sent_folder, $GLOBALS['prefs']->getValue('subscribe'));
-                }
-            }
-        }
-
-        return $success;
-    }
-
-    /**
-     * Returns information for the maintenance function.
-     *
-     * @return string  Description of what the operation is going to do during
-     *                 this login.
-     */
-    function describeMaintenance()
-    {
-        include_once 'Horde/Identity.php';
-        $identity = &Identity::singleton(array('imp', 'imp'));
-
-        $new_folders = $old_folders = array();
-        foreach ($identity->getAllSentmailfolders() as $folder) {
-            $old_folders[] = IMP::displayFolder($folder);
-            $new_folders[] = IMP::displayFolder(Maintenance_Task_rename_sentmail_monthly::_renameSentmailMonthlyName($folder));
-        }
-
-        return sprintf(_("The current folder(s) \"%s\" will be renamed to \"%s\"."), implode(', ', $old_folders), implode(', ', $new_folders));
-    }
-
-    /**
-     * Determines the name the sent-mail folder will be renamed to.
-     * <pre>
-     * Folder name: sent-mail-month-year
-     *   month = English:         3 letter abbreviation
-     *           Other Languages: Month value (01-12)
-     *   year  = 4 digit year
-     * The folder name needs to be in this specific format (as opposed to a
-     *   user-defined one) to ensure that 'delete_sentmail_monthly' processing
-     *   can accurately find all the old sent-mail folders.
-     * </pre>
-     *
-     * @access private
-     *
-     * @param string $folder  The name of the sent-mail folder to rename.
-     *
-     * @return string  New sent-mail folder name.
-     */
-    function _renameSentmailMonthlyName($folder)
-    {
-        $last_maintenance = $GLOBALS['prefs']->getValue('last_maintenance');
-        $last_maintenance = empty($last_maintenance) ? mktime(0, 0, 0, date('m') - 1, 1) : $last_maintenance;
-
-        $text = (substr($GLOBALS['language'], 0, 2) == 'en') ? strtolower(strftime('-%b-%Y', $last_maintenance)) : strftime('-%m-%Y', $last_maintenance);
-
-        return $folder . Horde_String::convertCharset($text, NLS::getExternalCharset(), 'UTF7-IMAP');
-    }
-
-}
diff --git a/imp/lib/Maintenance/Task/tos_agreement.php b/imp/lib/Maintenance/Task/tos_agreement.php
deleted file mode 100644 (file)
index 44f1a58..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-<?php
-/**
- * Maintenance module that presents a TOS Agreement page to user.
- * If user does not accept terms, user is not allowed to login.
- *
- * Copyright 2002-2009 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @author  Michael Slusarz <slusarz@horde.org>
- * @package Horde_Maintenance
- */
-class Maintenance_Task_tos_agreement extends Maintenance_Task
-{
-    /**
-     * The style of the maintenance page output.
-     *
-     * @var integer
-     */
-    var $_display_type = MAINTENANCE_OUTPUT_AGREE;
-
-    /**
-     * Determine if user agreed with the terms or not.  If the user does not
-     * agree, log him/her out immediately.
-     */
-    function doMaintenance()
-    {
-        $result = Horde_Util::getFormData('not_agree');
-        if (isset($result)) {
-            header('Location: ' . IMP::getLogoutUrl(array(AUTH_REASON_MESSAGE => _("You did not agree to the Terms of Service agreement, so you were not allowed to login.")), true));
-            exit;
-        }
-    }
-
-    /**
-     * Returns the TOS agreement for display on the maintenance page.
-     *
-     * @return string  The terms of service agreement.
-     */
-    function describeMaintenance()
-    {
-        if (empty($GLOBALS['conf']['tos']['file'])) {
-            Horde::fatal(new Horde_Exception(sprintf(_("Terms of Service file not specified in conf.php"))), __FILE__, __LINE__);
-        }
-
-        return file_get_contents($GLOBALS['conf']['tos']['file']);
-    }
-
-}
diff --git a/imp/lib/Maintenance/imp.php b/imp/lib/Maintenance/imp.php
deleted file mode 100644 (file)
index b876b4a..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-<?php
-
-require_once 'Horde/Maintenance.php';
-require_once dirname(__FILE__) . '/../base.php';
-
-/**
- * The Maintenance_IMP class defines the maintenance operations run upon
- * login to IMP.
- *
- * Copyright 2001-2009 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @author  Michael Slusarz <slusarz@horde.org>
- * @package Horde_Maintenance
- */
-class Maintenance_IMP extends Maintenance {
-
-    /**
-     * Hash holding maintenance preference names.
-     *
-     * @var array
-     */
-    var $maint_tasks = array(
-        'tos_agreement'              => MAINTENANCE_FIRST_LOGIN,
-        'fetchmail_login'            => MAINTENANCE_EVERY,
-        'rename_sentmail_monthly'    => MAINTENANCE_MONTHLY,
-        'delete_sentmail_monthly'    => MAINTENANCE_MONTHLY,
-        'delete_attachments_monthly' => MAINTENANCE_MONTHLY,
-        'purge_sentmail'             => MAINTENANCE_MONTHLY,
-        'purge_spam'                 => MAINTENANCE_MONTHLY,
-        'purge_trash'                => MAINTENANCE_MONTHLY
-    );
-
-}
index d6f06ae..35f6de5 100644 (file)
@@ -202,16 +202,9 @@ class IMP_Session
         IMP::loginTasksFlag(2);
         IMP::checkAuthentication(true);
 
-        /* Do maintenance operations. */
-        if ($GLOBALS['prefs']->getValue('do_maintenance')) {
-            require_once 'Horde/Maintenance.php';
-            $maint = &Maintenance::factory('imp', array('last_maintenance' => $GLOBALS['prefs']->getValue('last_maintenance')));
-            if (!$maint) {
-                $GLOBALS['notification']->push(_("Could not execute maintenance operations."), 'horde.warning');
-            } else {
-                $maint->runMaintenance();
-            }
-        }
+        /* Do login tasks. */
+        $tasks = &Horde_LoginTasks::singleton('imp', Horde_Util::addParameter(Horde::selfUrl(true, true, true), array('logintasks_done' => true)));
+        $tasks->runTasks();
 
         /* If the user wants to run filters on login, make sure they get
            run. */
@@ -221,7 +214,6 @@ class IMP_Session
             $imp_filter->filter('INBOX');
         }
 
-
         /* Check for drafts due to session timeouts. */
         $imp_compose = &IMP_Compose::singleton();
         $imp_compose->recoverSessionExpireDraft();
index 7dcb640..ac925d6 100644 (file)
@@ -176,12 +176,6 @@ if (($viewmode == 'mimp') ||
     $notification->attach('audio');
 }
 
-if ((IMP::loginTasksFlag() === 2) &&
-    !defined('AUTH_HANDLER') &&
-    !strstr($_SERVER['PHP_SELF'], 'maintenance.php')) {
-    IMP_Session::loginTasks();
-}
-
 // Initialize global $imp_mbox array.
 $GLOBALS['imp_mbox'] = IMP::getCurrentMailboxInfo();
 
index 021f19f..74a2644 100644 (file)
@@ -228,18 +228,6 @@ function prefs_callback()
         $imaptree->init();
     }
 
-    /* If a maintenance option has been activated, we need to make sure the
-     * global Horde 'do_maintenance' pref is also active. */
-    if (!$prefs->isLocked('do_maintenance') &&
-        !$prefs->getValue('do_maintenance')) {
-        foreach (array('rename_sentmail_monthly', 'delete_sentmail_monthly', 'purge_sentmail', 'delete_attachments_monthly', 'purge_trash') as $val) {
-            if ($prefs->getValue($val)) {
-                $prefs->setValue('do_maintenance', true);
-                break;
-            }
-        }
-    }
-
     if ($prefs->isDirty('mail_domain')) {
         $maildomain = preg_replace('/[^-\.a-z0-9]/i', '', $prefs->getValue('mail_domain'));
         $prefs->setValue('maildomain', $maildomain);
@@ -253,12 +241,6 @@ function prefs_callback()
     }
 }
 
-require_once IMP_BASE . '/lib/Maintenance/imp.php';
-$maint = &new Maintenance_IMP();
-foreach (($maint->exportIntervalPrefs()) as $val) {
-    $$val = &$intervals;
-}
-
 /* Make sure we have an active IMAP stream. */
 if (!$GLOBALS['registry']->call('mail/server')) {
     header('Location: ' . Horde_Util::addParameter(Horde::applicationUrl('redirect.php'), 'url', Horde::selfUrl(true)));
index 06873f0..0ea30e3 100644 (file)
@@ -80,7 +80,6 @@ function _addAnchor($url, $type)
 @define('AUTH_HANDLER', true);
 $authentication = 'none';
 require_once dirname(__FILE__) . '/lib/base.php';
-require_once 'Horde/Maintenance.php';
 
 $actionID = (Horde_Util::getFormData('action') == 'compose') ? 'login_compose' : Horde_Util::getFormData('actionID');
 $autologin = Horde_Util::getFormData('autologin');
@@ -101,8 +100,8 @@ if (($pos = strrpos($url_in, '#')) !== false) {
     $url_in = substr($url_in, 0, $pos);
 }
 
-/* If we are returning from Maintenance processing. */
-if (Horde_Util::getFormData(MAINTENANCE_DONE_PARAM)) {
+/* If we are returning from LoginTasks processing. */
+if (Horde_Util::getFormData('logintasks_done')) {
     /* Finish up any login tasks we haven't completed yet. */
     IMP_Session::loginTasks();
 
index 5e31eb9..f565360 100644 (file)
@@ -39,10 +39,11 @@ $prefGroups['event_options'] = array(
     'desc' => _("Set default values for new events."),
     'members' => array('default_alarm_management'),
 );
-$prefGroups['maintenance'] = array(
+
+$prefGroups['logintasks'] = array(
     'column' => _("Events"),
-    'label' => _("Maintenance"),
-    'desc' => _("Set options for deleting old events."),
+    'label' => _("Login Tasks"),
+    'desc' => sprintf(_("Customize tasks to run upon logon to %s."), $GLOBALS['registry']->get('name')),
     'members' => array('purge_events', 'purge_events_interval', 'purge_events_keep')
 );
 
@@ -404,20 +405,28 @@ $_prefs['fb_cals'] = array(
 // Free/Busy calendars selector.
 $_prefs['fb_cals_select'] = array('type' => 'special');
 
+
+// Login Tasks preferences
+
 $_prefs['purge_events'] = array(
     'value' => 0,
     'locked' => false,
     'shared' => false,
     'type' => 'checkbox',
-    'desc' => _("Purge old events from your calender?"),
+    'desc' => _("Purge old events from your calendar?"),
 );
 
-// 'value': yearly = 1, monthly = 2, weekly = 3, daily = 4, every login = 5
 $_prefs['purge_events_interval'] = array(
-    'value' => '2',
+    'value' => Horde_LoginTasks::MONTHLY,
     'locked' => false,
     'shared' => false,
-    'type' => 'select',
+    'type' => 'enum',
+    'enum' => array(
+        Horde_LoginTasks::YEARLY => _("Yearly"),
+        Horde_LoginTasks::MONTHLY => _("Monthly"),
+        Horde_LoginTasks::WEEKLY => _("Weekly"),
+        Horde_LoginTasks::DAILY => _("Daily"),
+        Horde_LoginTasks::EVERY => _("Every Login")),
     'desc' => _("Purge old events how often:"),
 );
 
@@ -429,11 +438,4 @@ $_prefs['purge_events_keep'] = array(
     'desc' => _("Purge old events older than this amount of days."),
 );
 
-// last time maintenance was run.
-// value is a UNIX timestamp of the last time maintenance ran for the user.
-$_prefs['last_kronolith_maintenance'] = array(
-    'value' => 0,
-    'locked' => false,
-    'shared' => false,
-    'type' => 'implicit'
-);
+// End Login Tasks preferences
index 0612cf8..4098843 100644 (file)
@@ -12,6 +12,12 @@ backup your existing data before running any of the steps described below. You
 can't use the updated data with your old Kronolith version anymore.
 
 
+Upgrading Kronolith from 2.3 to 3.x
+=====================================
+
+* Removed prefs: last_kronolith_maintenance
+
+
 Upgrading Kronolith from 2.3 to 2.3.x
 =====================================
 
diff --git a/kronolith/lib/LoginTasks/Task/PurgeEvents.php b/kronolith/lib/LoginTasks/Task/PurgeEvents.php
new file mode 100644 (file)
index 0000000..1b54202
--- /dev/null
@@ -0,0 +1,88 @@
+<?php
+/**
+ * Login tasks module that purges old events.
+ *
+ * Copyright 2008-2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author  Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Horde_LoginTasks
+ */
+class Kronolith_LoginTasks_Task_PurgeEvents extends Horde_LoginTasks_Task
+{
+    /**
+     * Constructor.
+     */
+    public function __construct()
+    {
+        $this->active = $GLOBALS['prefs']->getValue('purge_events');
+        if ($this->active) {
+            $this->interval = $GLOBALS['prefs']->getValue('purge_events_interval');
+            if ($GLOBALS['prefs']->isLocked('purge_events')) {
+                $this->display = Horde_LoginTasks::DISPLAY_NONE;
+            }
+        }
+    }
+
+    /**
+     * Purge old messages in the Trash folder.
+     *
+     * @return boolean  Whether any messages were purged from the Trash folder.
+     */
+    public function execute()
+    {
+        /* Get the current time minus the number of days specified in
+         * 'purge_events_keep'.  An event will be deleted if it has an end
+         * time prior to this time. */
+        $del_time = new Horde_Date($_SERVER['REQUEST_TIME']);
+        $del_time->mday -= $GLOBALS['prefs']->getValue('purge_events_keep');
+
+        /* Need to have PERMS_DELETE on a calendar to delete events from it */
+        $calendars = Kronolith::listCalendars(false, PERMS_DELETE);
+
+        /* Start building an event object to use for the search */
+        $kronolith_driver = Kronolith::getDriver();
+        $query = &$kronolith_driver->getEvent();
+        $query->start = null;
+        $query->end = $del_time;
+        $query->status = null;
+        $query->calendars = array_keys($calendars);
+        $query->creatorID = Auth::getAuth();
+
+        /* Perform the search */
+        $events = Kronolith::search($query);
+        $count = 0;
+        foreach ($events as $event) {
+            if (!$event->recurs()) {
+                if ($event->getCalendar() != $kronolith_driver->getCalendar()) {
+                    $kronolith_driver->open($event->getCalendar());
+                }
+                $results = $kronolith_driver->deleteEvent($event->getId(), true);
+                ++$count;
+                if (is_a($results, 'PEAR_Error')) {
+                    Horde::logMessage($results, __FILE__, __LINE__, PEAR_LOG_ERR);
+                    return $results;
+                }
+            }
+        }
+
+        $GLOBALS['notification']->push(sprintf(ngettext("Deleted %d event older than %d days.", "Deleted %d events older than %d days.", $count), $count, $GLOBALS['prefs']->getValue('purge_events_keep')));
+
+        return true;
+    }
+
+    /**
+     * Return information for the login task.
+     *
+     * @return string  Description of what the operation is going to do during
+     *                 this login.
+     */
+    public function describe()
+    {
+        return sprintf(_("All of your events older than %d days will be permanently deleted."),
+                       $GLOBALS['prefs']->getValue('purge_events_keep'));
+    }
+
+}
diff --git a/kronolith/lib/Maintenance/Task/purge_events.php b/kronolith/lib/Maintenance/Task/purge_events.php
deleted file mode 100644 (file)
index c37fc49..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-<?php
-/**
- * $Horde: kronolith/lib/Maintenance/Task/purge_events.php,v 1.5 2009/01/06 18:01:02 jan Exp $
- *
- * Maintenance module that purges old events.
- *
- * Copyright 2008-2009 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @author  Michael J. Rubinsky <mrubinsk@horde.org>
- * @package Horde_Maintenance
- */
-class Maintenance_Task_purge_events extends Maintenance_Task {
-
-    /**
-     * Purge old messages in the Trash folder.
-     *
-     * @return boolean  Whether any messages were purged from the Trash folder.
-     */
-    function doMaintenance()
-    {
-        global $prefs, $notification;
-
-        /* Get the current time minus the number of days specified in
-         * 'purge_events_keep'.  An event will be deleted if it has an end
-         * time prior to this time. */
-        $del_time = new Horde_Date($_SERVER['REQUEST_TIME']);
-        $del_time->mday -= $prefs->getValue('purge_events_keep');
-
-        /* Need to have PERMS_DELETE on a calendar to delete events from it */
-        $calendars = Kronolith::listCalendars(false, PERMS_DELETE);
-
-        /* Start building an event object to use for the search */
-        $kronolith_driver = Kronolith::getDriver();
-        $query = &$kronolith_driver->getEvent();
-        $query->start = null;
-        $query->end = $del_time;
-        $query->status = null;
-        $query->calendars = array_keys($calendars);
-        $query->creatorID = Auth::getAuth();
-
-        /* Perform the search */
-        $events = Kronolith::search($query);
-        $count = 0;
-        foreach ($events as $event) {
-            if (!$event->recurs()) {
-                if ($event->getCalendar() != $kronolith_driver->getCalendar()) {
-                    $kronolith_driver->open($event->getCalendar());
-                }
-                $results = $kronolith_driver->deleteEvent($event->getId(), true);
-                ++$count;
-                if (is_a($results, 'PEAR_Error')) {
-                    Horde::logMessage($results, __FILE__, __LINE__, PEAR_LOG_ERR);
-                    return $results;
-                }
-            }
-        }
-        $notification->push(sprintf(ngettext("Deleted %d event older than %d days.", "Deleted %d events older than %d days.", $count), $count, $prefs->getValue('purge_events_keep')));
-
-        return true;
-    }
-
-    /**
-     * Return information for the maintenance function.
-     *
-     * @return string  Description of what the operation is going to do during
-     *                 this login.
-     */
-    function describeMaintenance()
-    {
-        return sprintf(_("All of your events older than %d days will be permanently deleted."),
-                       $GLOBALS['prefs']->getValue('purge_events_keep'));
-    }
-
-}
diff --git a/kronolith/lib/Maintenance/kronolith.php b/kronolith/lib/Maintenance/kronolith.php
deleted file mode 100644 (file)
index 1c6d4ae..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-<?php
-
-require_once 'Horde/Maintenance.php';
-require_once $GLOBALS['registry']->get('fileroot', 'kronolith') . '/lib/base.php';
-
-/**
- * The Maintenance_Kronolith class defines the maintenance operations run upon
- * login to Kronolith
- *
- * Copyright 2008-2009 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @package Horde_Maintenance
- */
-class Maintenance_Kronolith extends Maintenance {
-
-    /**
-     * Hash holding maintenance preference names.
-     *
-     * @var array
-     */
-    var $maint_tasks = array(
-        'purge_events' => MAINTENANCE_MONTHLY
-    );
-
-    /**
-     * Execute all confirmed tasks.
-     *
-     * FIXME: This has to be overridden here since the parent's method will
-     * set the global last_maintenance pref...and mess up IMP's maintenance.
-     * This needs to be fixed for Horde 4.
-     *
-     * @access private
-     */
-    function _doMaintenanceTasks()
-    {
-        $tasks = $this->_tasklist->getList();
-
-        foreach ($tasks as $key => $val) {
-            if ($val['newpage']) {
-                if ($this->_tasklist->processed()) {
-                    $this->_tasklist->setNewPage($key, false);
-                }
-                break;
-            } elseif ($val['confirmed'] ||
-                      Horde_Util::getFormData($key . '_confirm')) {
-                /* Perform maintenance if confirmed. */
-                $mod = &$this->_loadModule($key);
-                $mod->doMaintenance();
-            }
-            $this->_tasklist->removeTask($key);
-        }
-
-        /* If we've successfully completed every task in the list (or skipped
-         * it), record now as the last time maintenance was run. */
-        if (!count($this->_tasklist->getList())) {
-            $GLOBALS['prefs']->setValue('last_kronolith_maintenance', time());
-        }
-    }
-
-
-
-}
index d8fb386..ca3348b 100644 (file)
@@ -59,31 +59,24 @@ Kronolith::initialize();
 
 // TODO - Maintenance operations need to be refactored to a more global
 //        operation and then wen can get rid of these hackish checks
-/* Do maintenance operations - need to check for a number of conditions to be
+/* Do login tasks - need to check for a number of conditions to be
  * sure that we aren't here due to alarm notifications (which would occur after
  * headers are sent), we aren't on any of the portal pages, and that we haven't
- * already performed maintenance.
+ * already performed login tasks.
  */
-require_once 'Horde/Maintenance.php';
 if (empty($no_maint) && Kronolith::loginTasksFlag() &&
     !strstr($_SERVER['PHP_SELF'], 'maintenance.php') &&
-    !headers_sent() && !defined('AUTH_HANDLER') &&
-    $GLOBALS['prefs']->getValue('do_maintenance')) {
+    !headers_sent() && !defined('AUTH_HANDLER')) {
     Kronolith::loginTasksFlag(2);
-    $maint = Maintenance::factory('kronolith', array('last_maintenance' => $GLOBALS['prefs']->getValue('last_kronolith_maintenance')));
-    if (!$maint) {
-        $GLOBALS['notification']->push(_("Could not execute maintenance operations."), 'horde.warning');
-    } else {
-       $maint->runMaintenance();
-    }
+
+    $tasks = &Horde_LoginTasks::singleton('kronolith', Horde_Util::addParameter(Horde::selfUrl(true, true, true), array('logintasks_done' => true)));
+    $tasks->runTasks();
+
     Kronolith::loginTasksFlag(0);
-} elseif (Horde_Util::getFormData(MAINTENANCE_DONE_PARAM) &&
+} elseif (Horde_Util::getFormData('logintasks_done') &&
           Kronolith::loginTasksFlag()) {
-    $maint = Maintenance::factory('kronolith', array('last_maintenance' => $GLOBALS['prefs']->getValue('last_kronolith_maintenance')));
-    if (!$maint) {
-        $GLOBALS['notification']->push(_("Could not execute maintenance operations."), 'horde.warning');
-    } else {
-        $maint->runMaintenance();
-    }
+    $tasks = &Horde_LoginTasks::singleton('kronolith', Horde_Util::addParameter(Horde::selfUrl(true, true, true), array('logintasks_done' => true)));
+    $tasks->runTasks();
+
     Kronolith::loginTasksFlag(0);
 }
index 0325db8..049b163 100644 (file)
@@ -178,13 +178,6 @@ function prefs_callback()
 
 }
 
-/* Get the interval variables for the prefs */
-require_once KRONOLITH_BASE . '/lib/Maintenance/kronolith.php';
-$maint = &new Maintenance_Kronolith();
-foreach (($maint->exportIntervalPrefs()) as $val) {
-    $$val = &$intervals;
-}
-
 if (!empty($GLOBALS['conf']['holidays']['enable'])) {
     if (class_exists('Date_Holidays')) {
         foreach (Date_Holidays::getInstalledDrivers() as $driver) {