1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17: 18: 19: 20: 21: 22: 23:
24: class IMP_LoginTasks_Task_PurgeSentmail extends Horde_LoginTasks_Task
25: {
26: 27: 28:
29: public function __construct()
30: {
31: global $prefs;
32:
33: if (($this->interval = $prefs->getValue('purge_sentmail_interval')) &&
34: $this->_getMboxes()) {
35: if ($prefs->isLocked('purge_sentmail_interval')) {
36: $this->display = Horde_LoginTasks::DISPLAY_NONE;
37: }
38: } else {
39: $this->active = false;
40: }
41: }
42:
43: 44: 45: 46: 47:
48: public function execute()
49: {
50: global $injector, $prefs, $notification;
51:
52: $imp_message = $injector->getInstance('IMP_Message');
53:
54: 55: 56:
57: $del_time = new Horde_Date(time() - ($prefs->getValue('purge_sentmail_keep') * 86400));
58:
59: foreach ($this->_getMboxes() as $mbox) {
60: 61:
62: $query = new Horde_Imap_Client_Search_Query();
63: $query->dateSearch($del_time, Horde_Imap_Client_Search_Query::DATE_BEFORE);
64: $msg_ids = $mbox->runSearchQuery($query);
65:
66:
67: if ($imp_message->delete($msg_ids, array('nuke' => true))) {
68: $msgcount = count($msg_ids);
69: if ($msgcount == 1) {
70: $notification->push(sprintf(_("Purging 1 message from sent-mail mailbox %s."), $mbox->display), 'horde.message');
71: } else {
72: $notification->push(sprintf(_("Purging %d messages from sent-mail mailbox."), $msgcount, $mbox->display), 'horde.message');
73: }
74: }
75: }
76:
77: return true;
78: }
79:
80: 81: 82: 83: 84: 85:
86: public function describe()
87: {
88: $mbox_list = array();
89: foreach ($this->_getMboxes() as $val) {
90: $mbox_list[] = $val->display_html;
91: }
92:
93: return sprintf(
94: ngettext(
95: "All messages in the mailbox \"%s\" older than %s days will be permanently deleted.",
96: "All messages in the mailboxes \"%s\" older than %s days will be permanently deleted.",
97: count($mbox_list)),
98: implode(', ', $mbox_list),
99: $GLOBALS['prefs']->getValue('purge_sentmail_keep'));
100: }
101:
102: 103: 104: 105: 106:
107: protected function _getMboxes()
108: {
109: global $injector;
110:
111: $sent = array();
112:
113: foreach ($injector->getInstance('IMP_Identity')->getAllSentmail() as $val) {
114: if ($val->exists) {
115: $sent[] = $val;
116: }
117: }
118:
119: return $sent;
120: }
121:
122: }
123: