Skip to content

Commit

Permalink
[mms] Rule code has been separated from the storage backend drivers.
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Feb 24, 2015
1 parent 28e4921 commit 7416f09
Show file tree
Hide file tree
Showing 78 changed files with 3,831 additions and 3,325 deletions.
27 changes: 8 additions & 19 deletions ingo/bin/ingo-convert-prefs-to-sql
Expand Up @@ -35,17 +35,9 @@ Horde_Registry::appInit('ingo', array('cli' => true));
if ($conf['storage']['driver'] != 'sql') {
$cli->fatal('You need to configure an SQL storage backend in Ingo\'s configuration', __FILE__, __LINE__);
}
$prefs_storage = $injector->getInstance('Ingo_Factory_Storage')->create('Prefs');
$p_storage = $injector->getInstance('Ingo_Factory_Storage')->create('Prefs');
$sql_storage = $injector->getInstance('Ingo_Factory_Storage')->create('Sql');

/* Rules to convert. */
$rules = array(Ingo_Storage::ACTION_FILTERS,
Ingo_Storage::ACTION_BLACKLIST,
Ingo_Storage::ACTION_WHITELIST,
Ingo_Storage::ACTION_VACATION,
Ingo_Storage::ACTION_FORWARD,
Ingo_Storage::ACTION_SPAM);

/* Update each user. */
while (!feof(STDIN)) {
$user = fgets(STDIN);
Expand All @@ -60,17 +52,14 @@ while (!feof(STDIN)) {
$registry->setAuth($user, array());
$session->set('ingo', 'current_share', ':' . $user);

foreach ($rules as $rule) {
$filter = $prefs_storage->retrieve($rule);
if ($rule == Ingo_Storage::ACTION_FILTERS) {
$new_filter = $sql_storage->retrieve(Ingo_Storage::ACTION_FILTERS, true);
foreach ($filter->getFilterList() as $rule) {
$new_filter->addRule($rule);
echo '.';
}
}
foreach ($p_storage as $val) {
$val->uid = ($val instanceof Ingo_System_Rule)
? $sql_storage->getSystemRule(get_class($val))
: '';

try {
$sql_storage->store($filter);
$sql_storage->updateRule($val);
echo '.';
} catch (Horde_Exception $e) {
$cli->writeln();
$cli->message($e->getMessage(), 'cli.error');
Expand Down
10 changes: 4 additions & 6 deletions ingo/bin/ingo-postfix-policyd
Expand Up @@ -153,17 +153,15 @@ function smtpd_access_policy($query)

$ingo_storage = $GLOBALS['injector']->getInstance('Ingo_Factory_Storage')->create();

try {
$whitelists[$user] = $ingo_storage->retrieve(Ingo_Storage::ACTION_WHITELIST)->getWhitelist();
} catch (Ingo_Exception $e) {}
$whitelists[$user] = $ingo_storage->getSystemRule('Ingo_Rule_System_Whitelist')->addresses;

try {
$bl = $ingo_storage->retrieve(Ingo_Storage::ACTION_BLACKLIST);
if (!$bl->getBlacklistFolder()) {
$bl = $ingo_storage->getSystemRule('Ingo_Rule_System_Blacklist');
if (!strlen($bl->mailbox)) {
// We will only reject email at delivery time if the user
// wants blacklisted mail deleted completely, not filed
// into a separate folder.
$blacklists[$user] = $bl->getBlacklist();
$blacklists[$user] = $bl->addresses;
}
} catch (Ingo_Exception $e) {}
}
Expand Down
44 changes: 22 additions & 22 deletions ingo/config/fields.php
Expand Up @@ -18,9 +18,9 @@
* MANDATORY:
* 'label' => (string) The gettext label for the entry.
* 'type' => (integer) The type of test. Either:
* Ingo_Storage::TYPE_HEADER -- Header test
* Ingo_Storage::TYPE_SIZE -- Message size test
* Ingo_Storage::TYPE_BODY -- Body test
* Ingo_Rule_User::TEST_HEADER -- Header test
* Ingo_Rule_User::TEST_SIZE -- Message size test
* Ingo_Rule_User::TEST_BODY -- Body test
* OPTIONAL:
* 'tests' => (array) Force these tests to be used only.
* If not set, will use the fields generally
Expand All @@ -30,80 +30,80 @@
$ingo_fields = array(
'To' => array(
'label' => _("To"),
'type' => Ingo_Storage::TYPE_HEADER
'type' => Ingo_Rule_User::TEST_HEADER
),
'Subject' => array(
'label' => _("Subject"),
'type' => Ingo_Storage::TYPE_HEADER
'type' => Ingo_Rule_User::TEST_HEADER
),
'Sender' => array(
'label' => _("Sender"),
'type' => Ingo_Storage::TYPE_HEADER
'type' => Ingo_Rule_User::TEST_HEADER
),
'From' => array(
'label' => _("From"),
'type' => Ingo_Storage::TYPE_HEADER
'type' => Ingo_Rule_User::TEST_HEADER
),
'Cc' => array(
'label' => _("Cc"),
'type' => Ingo_Storage::TYPE_HEADER
'type' => Ingo_Rule_User::TEST_HEADER
),
'Bcc' => array(
'label' => _("Bcc"),
'type' => Ingo_Storage::TYPE_HEADER
'type' => Ingo_Rule_User::TEST_HEADER
),
'Resent-from' => array(
'label' => _("Resent-From"),
'type' => Ingo_Storage::TYPE_HEADER
'type' => Ingo_Rule_User::TEST_HEADER
),
'Resent-to' => array(
'label' => _("Resent-To"),
'type' => Ingo_Storage::TYPE_HEADER
'type' => Ingo_Rule_User::TEST_HEADER
),
'List-Id' => array(
'label' => _("List-ID"),
'type' => Ingo_Storage::TYPE_HEADER
'type' => Ingo_Rule_User::TEST_HEADER
),
'Received' => array(
'label' => _("Received"),
'type' => Ingo_Storage::TYPE_HEADER
'type' => Ingo_Rule_User::TEST_HEADER
),
'X-Spam-Level' => array(
'label' => _("X-Spam-Level"),
'type' => Ingo_Storage::TYPE_HEADER
'type' => Ingo_Rule_User::TEST_HEADER
),
'X-Spam-Score' => array(
'label' => _("X-Spam-Score"),
'type' => Ingo_Storage::TYPE_HEADER
'type' => Ingo_Rule_User::TEST_HEADER
),
'X-Spam-Status' => array(
'label' => _("X-Spam-Status"),
'type' => Ingo_Storage::TYPE_HEADER
'type' => Ingo_Rule_User::TEST_HEADER
),
'X-Priority' => array(
'label' => _("X-Priority"),
'type' => Ingo_Storage::TYPE_HEADER
'type' => Ingo_Rule_User::TEST_HEADER
),
'To,Cc,Bcc,Resent-to' => array(
'label' => _("Destination (To, Cc, Bcc, etc.)"),
'type' => Ingo_Storage::TYPE_HEADER
'type' => Ingo_Rule_User::TEST_HEADER
),
'From,Sender,Reply-to,Resent-from' => array(
'label' => _("Source (From, Reply-to, etc.)"),
'type' => Ingo_Storage::TYPE_HEADER
'type' => Ingo_Rule_User::TEST_HEADER
),
'To,Cc,Bcc,Resent-to,From,Sender,Reply-to,Resent-from' => array(
'label' => _("Participant (From, To, etc.)"),
'type' => Ingo_Storage::TYPE_HEADER
'type' => Ingo_Rule_User::TEST_HEADER
),
'Size' => array(
'label' => _("Size"),
'type' => Ingo_Storage::TYPE_SIZE,
'type' => Ingo_Rule_User::TEST_SIZE,
'tests' => array('greater than', 'less than')
),
'Body' => array(
'label' => _("Body"),
'type' => Ingo_Storage::TYPE_BODY,
'type' => Ingo_Rule_User::TEST_BODY,
'tests' => array(
'contains', 'not contain', 'is', 'not is', 'begins with',
'not begins with', 'ends with', 'not ends with', 'regex',
Expand Down
26 changes: 6 additions & 20 deletions ingo/config/prefs.php
Expand Up @@ -59,50 +59,36 @@
// The following preference are only used if using the 'prefs' storage driver.

// Filter rules.
$_prefs['rules'] = array(
'value' => 'a:5:{i:0;a:2:{s:4:"name";s:9:"Whitelist";s:6:"action";i:' . Ingo_Storage::ACTION_WHITELIST . ';}i:1;a:2:{s:4:"name";s:9:"Blacklist";s:6:"action";i:' . Ingo_Storage::ACTION_BLACKLIST . ';}i:2;a:3:{s:4:"name";s:11:"Spam Filter";s:6:"action";i:' . Ingo_Storage::ACTION_SPAM . ';s:7:"disable";b:1;}i:3;a:3:{s:4:"name";s:7:"Forward";s:6:"action";i:' . Ingo_Storage::ACTION_FORWARD . ';s:7:"disable";b:1;}i:4;a:3:{s:4:"name";s:8:"Vacation";s:6:"action";i:' . Ingo_Storage::ACTION_VACATION . ';s:7:"disable";b:1;}}',
'locked' => false,
'type' => 'implicit'
);
$_prefs['rules'] = array();

// Blacklist.
$_prefs['blacklist'] = array(
'value' => 'a:2:{s:1:"a";a:0:{}s:1:"f";s:0:"";}',
// Lock this preference to disable blacklists.
'locked' => false,
'type' => 'implicit'
'locked' => false
);

// Whitelist.
$_prefs['whitelist'] = array(
'value' => 'a:0:{}',
// Lock this preference to disable whitelists.
'locked' => false,
'type' => 'implicit'
'locked' => false
);

// Vacation notices.
$_prefs['vacation'] = array(
'value' => 'a:8:{s:9:"addresses";a:0:{}s:4:"days";i:7;s:8:"excludes";a:0:{}s:10:"ignorelist";b:1;s:6:"reason";s:0:"";s:7:"subject";s:0:"";s:5:"start";i:0;s:3:"end";i:0;}',
// Lock this preference to disable vacation notices.
'locked' => false,
'type' => 'implicit'
'locked' => false
);

// Forwarding.
$_prefs['forward'] = array(
'value' => 'a:2:{s:1:"a";a:0:{}s:1:"k";i:0;}',
// Lock this preference to disable forwarding.
'locked' => false,
'type' => 'implicit'
'locked' => false
);

// Spam rule.
$_prefs['spam'] = array(
'value' => 'a:2:{s:6:"folder";N;s:5:"level";i:5;}',
// Lock this preference to disable the spam rule.
'locked' => false,
'type' => 'implicit'
'locked' => false
);

// End preferences storage driver entries
1 change: 1 addition & 0 deletions ingo/docs/CHANGES
Expand Up @@ -2,6 +2,7 @@
v3.3.0-git
----------

[mms] Rule code has been separated from the storage backend drivers.
[jan] Use Horde\ManageSieve instead of Net_Sieve.
[mms] Rearrange the default order of filter rules.

Expand Down
1 change: 1 addition & 0 deletions ingo/js/filters.js
Expand Up @@ -49,6 +49,7 @@ var IngoFilters = {
}
);
},
format: /^[^_\-](?:[A-Za-z0-9]*)[_](.*)$/,
tag: 'div'
});
}
Expand Down
2 changes: 1 addition & 1 deletion ingo/js/smartmobile.js
Expand Up @@ -39,7 +39,7 @@ var IngoMobile = {
HordeMobile.doAction(
'smartmobileRule',
{
rule: purl.params.rulenum
rule: purl.params.uid
},
IngoMobile.ruleLoaded
);
Expand Down
7 changes: 2 additions & 5 deletions ingo/lib/Ajax/Application/Filters.php
Expand Up @@ -26,7 +26,7 @@ class Ingo_Ajax_Application_Filters extends Horde_Core_Ajax_Application_Handler
* AJAX action: Re-sort the filters list.
*
* Variables used:
* - sort: (string) JSON serialized sort list of rule IDs.
* - sort: (string) JSON serialized sort list of rule UIDs.
*
* @return boolean True on success.
*/
Expand All @@ -40,12 +40,9 @@ public function reSortFilters()
}

$storage = $injector->getInstance('Ingo_Factory_Storage')->create();
$filters = $storage->retrieve(Ingo_Storage::ACTION_FILTERS);

try {
$filters->sort(json_decode($this->vars->sort));
$storage->store($filters);

$storage->sort(json_decode($this->vars->sort));
$notification->push(_("Rule sort saved successfully."), 'horde.success');
} catch (Ingo_Exception $e) {
$notification->push(_("Rule sort not saved."), 'horde.error');
Expand Down
12 changes: 6 additions & 6 deletions ingo/lib/Ajax/Application/Smartmobile.php
Expand Up @@ -19,13 +19,14 @@
* @license http://www.horde.org/licenses/apache ASL
* @package Ingo
*/
class Ingo_Ajax_Application_Smartmobile extends Horde_Core_Ajax_Application_Handler
class Ingo_Ajax_Application_Smartmobile
extends Horde_Core_Ajax_Application_Handler
{
/**
* AJAX action: Get rule data.
*
* Variables used:
* - rule: (integer) Rule number of the rule
* - rule: (integer) Rule UID.
*
* @return object An object with the following properties:
* - descrip: (string) Rule description.
Expand All @@ -45,15 +46,14 @@ public function smartmobileRule()
$out->error = 1;
} else {
$storage = $injector->getInstance('Ingo_Factory_Storage')->create();
$rule = $storage->retrieve(Ingo_Storage::ACTION_FILTERS)
->getRule($this->vars->rule);
$rule = $storage->getRuleByUid($this->vars->rule);

if (!$rule) {
$notification->push(_("Rule not found."), 'horde.error');
$out->error = 1;
} else {
$out->descrip = trim($storage->ruleDescription($rule));
$out->label = $rule['name'];
$out->descrip = $rule->description();
$out->label = $rule->name;
}
}

Expand Down

0 comments on commit 7416f09

Please sign in to comment.