Skip to content

Commit

Permalink
[jan] Add verify_forward_addresses() hook.
Browse files Browse the repository at this point in the history
  • Loading branch information
yunosh committed Jan 29, 2020
1 parent ad24579 commit 2919686
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
39 changes: 38 additions & 1 deletion config/hooks.php.dist
Expand Up @@ -20,7 +20,7 @@ class Ingo_Hooks
* @param string $driver The driver name (array key from backends.php).
*
* @return mixed If non-array, uses Horde authentication credentials
(DEFAULT). Otherwise, an array with the following keys
* (DEFAULT). Otherwise, an array with the following keys
* (non-existent keys will use default values):
* - euser: (string; SIEVE ONLY) For the sieve driver, the effective
* user to use (authorization ID).
Expand Down Expand Up @@ -69,6 +69,43 @@ class Ingo_Hooks
// return is_array($value) && count($value)
// ? $value
// : array($user . '@example.com', $user . '@foobar.com');
// }

/**
* Verifies and modifies the list for addresses that the user wants to
* forward his messages to.
*
* @param Horde_Mail_Rfc822_List $addresses The forward destinations.
*
* @throws Ingo_Exception if an address is rejected.
* @return Horde_Mail_Rfc822_List The modified destinations.
*/
// public function verify_forward_addresses($addresses)
// {
// // Example #1: Correcting a common typo.
// foreach ($addresses as $address) {
// if ($address->mailbox == 'johny') {
// $address->mailbox = 'johnny';
// }
// }
//
// // Example #2: Deny domains not matching a whitelist.
// $whitelist = array(
// 'example.com',
// 'example.net',
// 'mycompany.com'
// );
// foreach ($addresses as $address) {
// if (!in_array($address->host, $whitelist)) {
// throw new Ingo_Exception(sprintf(
// '%s does not contain a valid domain. Allowed domains: %s',
// $address,
// implode(', ', $whitelist)
// ));
// }
// }
//
// return $addresses;
// }

}
1 change: 1 addition & 0 deletions doc/changelog.yml
Expand Up @@ -9,6 +9,7 @@
identifier: ASL
uri: http://www.horde.org/licenses/apache
notes: |
[jan] Add verify_forward_addresses() hook.
[jan] Add support for boolean spam headers (Adam James <adam.james@transitiv.co.uk>).
[jan] Allow to specify time limits for vacation messages if supported.
[jan] Allow to set vaction with only start or end date, if supported.
Expand Down
7 changes: 7 additions & 0 deletions lib/Basic/Forward.php
Expand Up @@ -49,6 +49,13 @@ protected function _init()
$forward->keep = ($this->vars->keep_copy == 'on');

try {
try {
$forward->addressList = $injector->getInstance('Horde_Core_Hooks')
->callHook('verify_forward_addresses', 'ingo', array($forward->addressList));
$this->vars->addresses = implode("\n", $forward->addresses);
} catch (Horde_Exception_HookNotSet $e) {
}

if ($this->vars->submitbutton == _("Save and Enable")) {
$forward->disable = true;
$notify = _("Rule Enabled");
Expand Down
13 changes: 11 additions & 2 deletions lib/Rule/Addresses.php
Expand Up @@ -20,8 +20,9 @@
* @license http://www.horde.org/licenses/apache ASL
* @package Ingo
*
* @property-read array $addresses The list of addresses.
* @property-write mixed $addresses The list of addresses (array or string).
* @property-read string[] $addresses The list of addresses.
* @property-read Horde_Mail_Rfc822_List $addressList The list of addresses.
* @property-write string[]|string $addresses A list of addresses.
*/
class Ingo_Rule_Addresses
extends Ingo_Rule
Expand Down Expand Up @@ -55,6 +56,8 @@ public function __get($name)
switch ($name) {
case 'addresses':
return $this->_addr->bare_addresses;
case 'addressList':
return $this->_addr;
}
}

Expand All @@ -69,6 +72,12 @@ public function __set($name, $data)
is_array($data) ? $data : preg_split("/\s+/", $data)
);
break;
case 'addressList':
if (!($data instanceof Horde_Mail_Rfc822_List)) {
throw new InvalidArgumentException('Value for addressList is not a Horde_Mail_Rfc822_List object');
}
$this->_addr = $data;
break;
}
}

Expand Down

0 comments on commit 2919686

Please sign in to comment.