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