1: <?php
2: /**
3: * Copyright 2006-2014 Horde LLC (http://www.horde.org/)
4: *
5: * See the enclosed file COPYING for license information (GPL). If you
6: * did not receive this file, see http://www.horde.org/licenses/gpl.
7: *
8: * @category Horde
9: * @copyright 2006-2014 Horde LLC
10: * @license http://www.horde.org/licenses/gpl GPL
11: * @package IMP
12: */
13:
14: /**
15: * Login tasks module that purges old messages in the Spam mailbox.
16: *
17: * @author Matt Selsky <selsky@columbia.edu>
18: * @author Michael Slusarz <slusarz@horde.org>
19: * @category Horde
20: * @copyright 2006-2014 Horde LLC
21: * @license http://www.horde.org/licenses/gpl GPL
22: * @package IMP
23: */
24: class IMP_LoginTasks_Task_PurgeSpam extends Horde_LoginTasks_Task
25: {
26: /**
27: * Constructor.
28: */
29: public function __construct()
30: {
31: global $prefs;
32:
33: if (($this->interval = $prefs->getValue('purge_spam_interval')) &&
34: $this->_spamMbox()) {
35: if ($prefs->isLocked('purge_spam_interval')) {
36: $this->display = Horde_LoginTasks::DISPLAY_NONE;
37: }
38: } else {
39: $this->active = false;
40: }
41: }
42:
43: /**
44: * Purge old messages in the Spam mailbox.
45: *
46: * @return boolean Whether any messages were purged from the mailbox.
47: */
48: public function execute()
49: {
50: if (!($spam = $this->_spamMbox())) {
51: return false;
52: }
53:
54: /* Get the current UNIX timestamp minus the number of days
55: specified in 'purge_spam_keep'. If a message has a
56: timestamp prior to this value, it will be deleted. */
57: $del_time = new Horde_Date(time() - ($GLOBALS['prefs']->getValue('purge_spam_keep') * 86400));
58:
59: /* Get the list of messages older than 'purge_spam_keep' days. */
60: $query = new Horde_Imap_Client_Search_Query();
61: $query->dateSearch($del_time, Horde_Imap_Client_Search_Query::DATE_BEFORE);
62: $msg_ids = $spam->runSearchQuery($query);
63:
64: /* Go through the message list and delete the messages. */
65: if ($GLOBALS['injector']->getInstance('IMP_Message')->delete($msg_ids, array('nuke' => true))) {
66: $msgcount = count($msg_ids);
67: $GLOBALS['notification']->push(sprintf(ngettext("Purging %d message from Spam mailbox.", "Purging %d messages from Spam mailbox.", $msgcount), $msgcount), 'horde.message');
68: return true;
69: }
70:
71: return false;
72: }
73:
74: /**
75: * Return information for the login task.
76: *
77: * @return string Description of what the operation is going to do during
78: * this login.
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_SPAM)->display_html,
84: $GLOBALS['prefs']->getValue('purge_spam_keep'));
85: }
86:
87: /**
88: * Return the spam mailbox.
89: *
90: * @return IMP_Mailbox The spam mailbox, if it exists. Otherwise, false.
91: */
92: protected function _spamMbox()
93: {
94: return (($spam = IMP_Mailbox::getPref(IMP_Mailbox::MBOX_SPAM)) && $spam->exists)
95: ? $spam
96: : false;
97: }
98:
99: }
100: