[ Index ] |
|
Code source de IMP H3 (4.1.5) |
1 <?php 2 /** 3 * The IMP_Filter:: class contains all functions related to handling 4 * filtering messages in IMP. 5 * 6 * For full use, the following Horde API calls should be defined 7 * (These API methods are not defined in IMP): 8 * mail/applyFilters 9 * mail/canApplyFilters 10 * mail/showFilters 11 * mail/blacklistFrom 12 * mail/showBlacklist 13 * mail/whitelistFrom 14 * mail/showWhitelist 15 * 16 * $Horde: imp/lib/Filter.php,v 1.56.10.11 2007/03/02 20:50:47 slusarz Exp $ 17 * 18 * Copyright 2002-2007 Michael Slusarz <slusarz@bigworm.colorado.edu> 19 * 20 * See the enclosed file COPYING for license information (GPL). If you 21 * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. 22 * 23 * @author Michael Slusarz <slusarz@bigworm.colorado.edu> 24 * @since IMP 4.0 25 * @package IMP 26 */ 27 class IMP_Filter { 28 29 /** 30 * Returns a reference to the global IMP_Filter object, only creating it 31 * if it doesn't already exist. This ensures that only one IMP_Filter 32 * instance is instantiated for any given session. 33 * 34 * This method must be invoked as:<code> 35 * $imp_filter = &IMP_Filter::singleton(); 36 * </code> 37 * 38 * @return IMP_Filter The IMP_Filter instance. 39 */ 40 function &singleton() 41 { 42 static $filter; 43 44 if (!isset($filter)) { 45 $filter = new IMP_Filter(); 46 } 47 48 return $filter; 49 } 50 51 /** 52 * Runs the filters if they are able to be applied manually. 53 * 54 * @param string $mbox The mailbox to apply the filters to. 55 */ 56 function filter($mbox) 57 { 58 if ($_SESSION['imp']['filteravail']) { 59 if (isset($GLOBALS['imp_search']) && 60 $GLOBALS['imp_search']->isSearchMbox($mbox)) { 61 $mbox_list = $GLOBALS['imp_search']->getSearchFolders($mbox); 62 } else { 63 $mbox_list = array($mbox); 64 } 65 $imp_imap = &IMP_IMAP::singleton(); 66 67 foreach ($mbox_list as $val) { 68 $imp_imap->changeMbox($val); 69 $params = array('imap' => $GLOBALS['imp']['stream'], 'mailbox' => IMP::serverString($val)); 70 $GLOBALS['registry']->call('mail/applyFilters', array($params)); 71 } 72 } 73 } 74 75 /** 76 * Adds the From address from the message(s) to the blacklist. 77 * 78 * @param array $indices See IMP::parseIndicesList(). 79 */ 80 function blacklistMessage($indices) 81 { 82 $this->_processBWlist($indices, _("your blacklist"), 'blacklistFrom', 'showBlacklist'); 83 } 84 85 /** 86 * Adds the From address from the message(s) to the whitelist. 87 * 88 * @param array $indices See IMP::parseIndicesList(). 89 */ 90 function whitelistMessage($indices) 91 { 92 $this->_processBWlist($indices, _("your whitelist"), 'whitelistFrom', 'showWhitelist'); 93 } 94 95 /** 96 * Internal function to handle adding addresses to [black|white]list. 97 * 98 * @access private 99 * 100 * @param array $indices See IMP::parseIndicesList(). 101 * @param string $descrip The textual description to use. 102 * @param string $reg1 The name of the mail/ registry call to use for 103 * adding the addresses. 104 * @param string $reg2 The name of the mail/ registry call to use for 105 * linking to the filter management page. 106 */ 107 function _processBWlist($indices, $descrip, $reg1, $reg2) 108 { 109 if (!($msgList = IMP::parseIndicesList($indices))) { 110 return false; 111 } 112 113 require_once IMP_BASE . '/lib/IMAP.php'; 114 require_once IMP_BASE . '/lib/MIME/Headers.php'; 115 $imp_imap = &IMP_IMAP::singleton(); 116 117 /* Get the list of from addresses. */ 118 $addr = array(); 119 foreach ($msgList as $folder => $msgIndices) { 120 /* Switch folders, if necessary (only valid for IMAP). */ 121 $imp_imap->changeMbox($folder); 122 123 foreach ($msgIndices as $msg) { 124 $imp_headers = &new IMP_Headers($msg); 125 $from = $imp_headers->getFromAddress(); 126 $addr[] = $from; 127 } 128 } 129 130 $GLOBALS['registry']->call('mail/' . $reg1, array($addr)); 131 132 /* Add link to filter management page. */ 133 if ($GLOBALS['registry']->hasMethod('mail/' . $reg2)) { 134 $manage_link = Horde::link(Horde::url($GLOBALS['registry']->link('mail/' . $reg2)), sprintf(_("Filters: %s management page"), $descrip)) . _("HERE") . '</a>'; 135 $GLOBALS['notification']->push(sprintf(_("Click %s to go to %s management page."), $manage_link, $descrip), 'horde.message', array('content.raw')); 136 } 137 } 138 139 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Nov 29 12:30:07 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |