6.0.0-git
2018-12-17
Last Modified 2009-09-18 by Guest

How to create default filtering rules for Ingo when using dovecot with sieve

There are situations when you want so ship a set of new rules for your users. This document aims to tell you how to do this.

I've set up a Debian Lenny system with dovecot / sieve and decided to use horde & ingo to manage my filtering rules. I took advantage of the sieve_global_path option of dovecot to create a global filtering rule. In my case it took care on spam. This rule did what it was supposed to do. But only until the user created his own rules. If the user has it's own filter, the global one is ignored and the user starts to wonder by spam is now delivered to his INBOX.

So what is the task? Define a default rule for ingo that is activated when the user creates his own filtering rules. Together with the global rule in dovecot it will make sure the user is not confused.

First we like to open the file ingo/config/prefs.php. In this file the default rules are defined. We like to create a rule that moved spam to folder spam. So we need to modify $_prefs['rules'] and $_prefs['spam']. For me the two arrays look like this:

$_prefs['rules'] = array(
    'value' => 'a:1:{i:0;a:8:{s:4:"name";s:11:"Spam Filter";s:7:"combine";i:1;s:10:"conditions";a:0:{}s:6:"action";i:14;s:12:"action-value";s:0:"";s:4:"stop";b:1;s:5:"flags";i:0;s:7:"disable";b:0;}}',
    'locked' => false,
    'shared' => false,
    'type' => 'implicit'
);

$_prefs['spam'] = array(
    'value' => 'a:2:{s:6:"folder";s:4:"spam";s:5:"level";s:1:"6";}',
    'locked' => false,
    'shared' => false,
    'type' => 'implicit'
);

I think this is self explaining. The $_prefs['rules'] defines that there is a rule and $_prefs['spam'] configures this rule (with spamlevel 6, move to folder spam). I just like to take a look on the value elements. Kevin M. Myer has explained how to get the content of this array elements.

  1. create a fresh user account in you horde installation
  2. log on using this account and create the rules that you want to have as you default fules and save them
  3. go to you horde preferences backend (or what ever backend you use to save you rules) and find the info preferences that match this user; for me this were the pref_name spam and rules of the pref_scope ingo
  4. copy the content of pref_value into you value elements of the spam and rules array in ingo/config/prefs.php

To test this I deleted all user data ( Horde -> Administration -> Users ) of this testuser and logged on again. I now saw the fules that I just defined in the prefs.php file.

So we have made the hardest part. This rules inside ingo are only used by sieve if ingo does actually create a script. Until then the global sieve file is used. To have exactly the same behaviour, I copied the sieve script that ingo created into the global sieve rule file

require "fileinto";
# Spamfilter
if header :comparator "i;ascii-casemap" :contains "X-Spam-Level" "******"  {
    fileinto "spam";
    stop;
}