[imp] whitelist patch...
Amith Varghese
amith at xalan.com
Tue Feb 25 13:59:38 PST 2003
Here is a patch against CVS HEAD that integrates whitelist functionality within
IMP using Sam (SpamAssassin Module). The patch uses the registry->hasMethod
calls to determine whether or not to show the link within IMP. Please let me
know if there are any questions.
Thanks
Amith
-------------- next part --------------
Index: imp/lib/constants.php
===================================================================
RCS file: /repository/imp/lib/constants.php,v
retrieving revision 1.26
diff -u -r1.26 constants.php
--- imp/lib/constants.php 22 Feb 2003 01:35:49 -0000 1.26
+++ imp/lib/constants.php 25 Feb 2003 18:12:22 -0000
@@ -85,6 +85,7 @@
/** @const SMIME_SIGNENC Send Message - S/MIME Sign/Enc*/ define('SMIME_SIGNENC', 176);
/** @const IMP_ACL_SET Set IMAP access control list */ define('IMP_ACL_SET', 177);
/** @const IMP_ACL_EDIT Edit an access control list */ define('IMP_ACL_EDIT', 178);
+/** @const IMP_WHITELIST Whitelist e-mail */ define('IMP_WHITELIST', 179);
// IMAP Flags
/** @const IMP_ALL Match all IMAP flags. */ define('IMP_ALL', 0);
Index: imp/lib/IMP.php
===================================================================
RCS file: /repository/imp/lib/IMP.php,v
retrieving revision 1.367
diff -u -r1.367 IMP.php
--- imp/lib/IMP.php 17 Feb 2003 02:36:05 -0000 1.367
+++ imp/lib/IMP.php 25 Feb 2003 18:12:44 -0000
@@ -348,6 +348,36 @@
}
/**
+ * Adds the From address from the message(s) to the whitelist and
+ * redirects to the whitelist page.
+ *
+ * @access public
+ *
+ * @param array $indices An array of message indices to whitelist.
+ */
+ function whitelistMessage($indices)
+ {
+ global $prefs, $notification, $registry;
+ require_once IMP_BASE . '/lib/Headers.php';
+
+ /* Get the list of from addresses. */
+ $addr = array();
+ foreach ($indices as $msgnum) {
+ $imp_headers = new IMP_Headers($msgnum);
+ $from = $imp_headers->getFromAddress();
+ $notification->push(sprintf(_("The address %s has been added to your whitelist."), $from));
+ $addr[] = $from;
+ }
+
+ $registry->call('mail/whitelistFrom', array($addr));
+
+ /* Redirect to filter management page. */
+ header('Location: ' . Horde::url($registry->link('mail/showWhitelist'),
+true));
+ exit;
+ }
+
+ /**
* Set the plain-text label that is displayed for the current
* mailbox, replacing SEARCH_MBOX with an appropriate string and
* removing namespace and folder prefix information from what is
Index: imp/templates/message/navbar.inc
===================================================================
RCS file: /repository/imp/templates/message/navbar.inc,v
retrieving revision 2.96
diff -u -r2.96 navbar.inc
--- imp/templates/message/navbar.inc 13 Feb 2003 21:21:40 -0000 2.96
+++ imp/templates/message/navbar.inc 25 Feb 2003 18:13:22 -0000
@@ -17,6 +17,9 @@
| <?php echo Horde::widget(IMP::composeLink(array(), array('actionID' => REDIRECT_COMPOSE, 'index' => $index, 'array_index' => $array_index)), _("Redirect"), 'widget', '', '', _("Redirect"), 2) ?>
<?php if (($conf['prefs']['driver'] != '') && ($conf['prefs']['driver'] != 'none') && !$prefs->isLocked('filters')): ?>
| <?php echo Horde::widget(Horde::addParameter($self_link, 'actionID', IMP_BLACKLIST), _("Blacklist"), 'widget', '', '', _("Blacklist"), 2) ?>
+<?php if($show_whitelist_link): ?>
+ | <?php echo Horde::widget(Horde::addParameter($self_link, 'actionID', IMP_WHITELIST), _("Whitelist"), 'widget', '', '', _("Whitelist"), 2) ?>
+<?php endif; ?>
<?php endif; ?>
<?php if (isset($source_link)): ?>
| <?php echo $source_link . ' ' ?>
Index: config/registry.php.dist
===================================================================
RCS file: /repository/horde/config/registry.php.dist,v
retrieving revision 1.143
diff -u -r1.143 registry.php.dist
--- config/registry.php.dist 22 Feb 2003 16:37:22 -0000 1.143
+++ config/registry.php.dist 25 Feb 2003 18:14:30 -0000
@@ -90,7 +90,7 @@
'status' => 'active',
// Uncomment this line if you want Sam to handle the blacklist
// filter instead of IMP:
- // 'provides' => array('mail/blacklistFrom', 'mail/showBlacklist'),
+ // 'provides' => array('mail/blacklistFrom', 'mail/showBlacklist','mail/whitelistFrom','mail/showWhitelist'),
'menu_parent' => 'mail'
);
Index: sam/lib/api.php
===================================================================
RCS file: /repository/sam/lib/api.php,v
retrieving revision 1.1
diff -u -r1.1 api.php
--- sam/lib/api.php 15 Oct 2002 16:08:44 -0000 1.1
+++ sam/lib/api.php 25 Feb 2003 18:15:09 -0000
@@ -17,6 +17,15 @@
'link' => '%application%/blacklist.php'
);
+$_services['whitelistFrom'] = array(
+ 'args' => array('addresses'),
+ 'type' => 'boolean'
+);
+
+$_services['showWhitelist'] = array(
+ 'link' => '%application%/whitelist.php'
+);
+
function _sam_blacklistFrom($addresses)
{
@@ -43,6 +52,36 @@
}
$sam->setListOption('blacklist_from', implode(' ', $blacklist_from));
+ $sam->store();
+
+ return true;
+}
+
+function _sam_whitelistFrom($addresses)
+{
+ require_once dirname(__FILE__) . '/../lib/base.php';
+
+ global $sam;
+ $sam->retrieve();
+
+ $whitelist_from = $sam->getListOption('whitelist_from');
+ $whitelist_from = preg_split('|\s|', trim($whitelist_from));
+
+ if (is_array($addresses)) {
+ foreach ($addresses as $address) {
+ if (in_array($address, $whitelist_from)) {
+ return PEAR::raiseError(sprintf(_("%s is already in your whitelist filter.")));
+ }
+ $whitelist_from[] = $address;
+ }
+ } else {
+ if (in_array($addresses, $whitelist_from)) {
+ return PEAR::raiseError(sprintf(_("%s is already in your whitelist filter.")));
+ }
+ $whitelist_from[] = $addresses;
+ }
+
+ $sam->setListOption('whitelist_from', implode(' ', $whitelist_from));
$sam->store();
return true;
Index: imp/message.php
===================================================================
RCS file: /repository/imp/message.php,v
retrieving revision 2.456
diff -u -r2.456 message.php
--- imp/message.php 7 Feb 2003 21:01:38 -0000 2.456
+++ imp/message.php 25 Feb 2003 18:49:29 -0000
@@ -64,7 +64,9 @@
case IMP_BLACKLIST:
IMP::blacklistMessage(array($imp_mailbox->getIndex()));
break;
-
+case IMP_WHITELIST:
+ IMP::whitelistMessage(array($imp_mailbox->getIndex()));
+ break;
case PRINT_MESSAGE:
$printer_friendly = true;
break;
@@ -448,6 +450,14 @@
if ($conf['spam']['reporting']) {
$spam_link = Horde::addParameter($self_link, 'actionID', SPAM_REPORT);
$spam_link = Horde::addParameter($spam_link, 'identity', $identity);
+}
+
+/* Show the whitelist link if we have whitelist functionality enabled */
+if ($registry->hasMethod('mail/whitelistFrom') &&
+ $registry->hasMethod('mail/showWhitelist')) {
+ $show_whitelist_link = true;
+} else {
+ $show_whitelist_link = false;
}
/* Determine if we need to show the Reply to All link. */
More information about the imp
mailing list