1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
<?php
/**
* The IMP_Filter:: class contains all functions related to handling
* filtering messages in IMP.
*
* For full use, the following Horde API calls should be defined
* (These API methods are not defined in IMP):
* mail/applyFilters
* mail/canApplyFilters
* mail/showFilters
* mail/blacklistFrom
* mail/showBlacklist
* mail/whitelistFrom
* mail/showWhitelist
*
* $Horde: imp/lib/Filter.php,v 1.56.10.15 2008/03/10 17:13:07 slusarz Exp $
*
* Copyright 2002-2008 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 IMP
*/
class IMP_Filter {
/**
* Runs the filters if they are able to be applied manually.
*
* @param string $mbox The mailbox to apply the filters to.
*/
function filter($mbox)
{
if ($_SESSION['imp']['filteravail']) {
if (isset($GLOBALS['imp_search']) &&
$GLOBALS['imp_search']->isSearchMbox($mbox)) {
$mbox_list = $GLOBALS['imp_search']->getSearchFolders($mbox);
} else {
$mbox_list = array($mbox);
}
$imp_imap = &IMP_IMAP::singleton();
foreach ($mbox_list as $val) {
$imp_imap->changeMbox($val);
$params = array('imap' => $imp_imap->stream(), 'mailbox' => IMP::serverString($val));
$GLOBALS['registry']->call('mail/applyFilters', array($params));
}
}
}
/**
* Adds the From address from the message(s) to the blacklist and deletes
* the message(s).
*
* @param array $indices See IMP::parseIndicesList().
* @param boolean $show_link Show link to the blacklist management in the
* notification message?
*
* @return boolean True if the messages(s) were delete.
*/
function blacklistMessage($indices, $show_link = true)
{
$this->_processBWlist($indices, _("your blacklist"), 'blacklistFrom', 'showBlacklist', $show_link);
require_once IMP_BASE . '/lib/Message.php';
$imp_message = &IMP_Message::singleton();
$msg_count = $imp_message->delete($indices);
if ($msg_count) {
if ($msg_count == 1) {
$GLOBALS['notification']->push(_("The message has been deleted."), 'horde.message');
} else {
$GLOBALS['notification']->push(_("The messages have been deleted."), 'horde.message');
}
return true;
}
return false;
}
/**
* Adds the From address from the message(s) to the whitelist.
*
* @param array $indices See IMP::parseIndicesList().
* @param boolean $show_link Show link to the whitelist management in the
* notification message?
*/
function whitelistMessage($indices, $show_link = true)
{
$this->_processBWlist($indices, _("your whitelist"), 'whitelistFrom', 'showWhitelist', $show_link);
}
/**
* Internal function to handle adding addresses to [black|white]list.
*
* @access private
*
* @param array $indices See IMP::parseIndicesList().
* @param string $descrip The textual description to use.
* @param string $reg1 The name of the mail/ registry call to use for
* adding the addresses.
* @param string $reg2 The name of the mail/ registry call to use for
* linking to the filter management page.
* @param boolean link Show link to the whitelist management in the
* notification message?
*/
function _processBWlist($indices, $descrip, $reg1, $reg2, $link)
{
if (!($msgList = IMP::parseIndicesList($indices))) {
return false;
}
require_once IMP_BASE . '/lib/IMAP/MessageCache.php';
$msg_cache = &IMP_MessageCache::singleton();
/* Get the list of from addresses. */
$addr = array();
foreach ($msgList as $folder => $msgIndices) {
$ob = $msg_cache->retrieve($folder, $msgIndices, 32);
foreach ($msgIndices as $msg) {
$addr[] = $ob[$msg]->header->getFromAddress();
}
}
$GLOBALS['registry']->call('mail/' . $reg1, array($addr));
/* Add link to filter management page. */
if ($link && $GLOBALS['registry']->hasMethod('mail/' . $reg2)) {
$manage_link = Horde::link(Horde::url($GLOBALS['registry']->link('mail/' . $reg2)), sprintf(_("Filters: %s management page"), $descrip)) . _("HERE") . '</a>';
$GLOBALS['notification']->push(sprintf(_("Click %s to go to %s management page."), $manage_link, $descrip), 'horde.message', array('content.raw'));
}
}
}
|