1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: class IMP_LoginTasks_Task_PurgeTrash extends Horde_LoginTasks_Task
16: {
17: 18: 19:
20: public function __construct()
21: {
22: if ($this->interval = $GLOBALS['prefs']->getValue('purge_trash_interval')) {
23: if ($GLOBALS['prefs']->isLocked('purge_trash_interval')) {
24: $this->display = Horde_LoginTasks::DISPLAY_NONE;
25: }
26: } else {
27: $this->active = false;
28: }
29: }
30:
31: 32: 33: 34: 35:
36: public function execute()
37: {
38: global $injector, $notification, $prefs;
39:
40: if (!$prefs->getValue('use_trash') ||
41: !($trash_folder = IMP_Mailbox::getPref('trash_folder')) ||
42: $trash_folder->vtrash ||
43: !$trash_folder->exists) {
44: return false;
45: }
46:
47: 48: 49:
50: $del_time = new Horde_Date(time() - ($prefs->getValue('purge_trash_keep') * 86400));
51:
52:
53: $query = new Horde_Imap_Client_Search_Query();
54: $query->dateSearch($del_time, Horde_Imap_Client_Search_Query::DATE_BEFORE);
55: $msg_ids = $trash_folder->runSearchQuery($query);
56:
57:
58: if (!$injector->getInstance('IMP_Message')->delete($msg_ids, array('nuke' => true))) {
59: return false;
60: }
61:
62: $msgcount = count($msg_ids);
63: $notification->push(sprintf(ngettext("Purging %d message from Trash folder.", "Purging %d messages from Trash folder.", $msgcount), $msgcount), 'horde.message');
64: return true;
65: }
66:
67: 68: 69: 70: 71: 72:
73: public function describe()
74: {
75: return sprintf(_("All messages in your \"%s\" folder older than %s days will be permanently deleted."),
76: IMP_Mailbox::getPref('trash_folder')->display_html,
77: $GLOBALS['prefs']->getValue('purge_trash_keep'));
78: }
79:
80: }
81: