\documentclass{article}
\usepackage{ulem}
\usepackage{graphicx}
\usepackage{hyperref}
\pagestyle{headings}
\begin{document}
\subsection{How to create default filtering rules for Ingo when using dovecot with sieve}
There are situations when you want to 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 <a href="http://workaround.org/ispmail/lenny/server-side-sieve-filtering">dovecot / sieve</a> 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 \texttt{ingo/config/prefs.php}. In this file the default rules are defined. We like to create a rule that moved spam to folder \textit{spam}. So we need to modify \textbf{\$\_prefs['rules']} and \textbf{\$\_prefs['spam']}. For me the two arrays look like this:

<pre><code class="language-php">
\$\_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'
);
</code></pre>
I think this is self explaining. The \textbf{\$\_prefs['rules']} defines that there is a rule and \textbf{\$\_prefs['spam']} configures this rule (with spamlevel 6, move to folder spam). I just like to take a look on the \textbf{value} elements. <a href="http://lists.horde.org/archives/ingo/Week-of-Mon-20051031/000954.html">Kevin M. Myer</a> has explained how to get the content of this array elements.

\begin{itemize}
\item create a fresh user account in you horde installation


\item log on using this account and create the rules that you want to have as you default fules and save them


\item 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 \texttt{pref\_name} \textit{spam} and \textit{rules} of the \texttt{pref\_scope} \textit{ingo}


\item copy the content of \texttt{pref\_value} into you value elements of the spam and rules array in ingo/config/prefs.php


\end{itemize}
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

<pre><code class="language-sieve">
require "fileinto";
\# Spamfilter
if header :comparator "i;ascii-casemap" :contains "X-Spam-Level" "******"  \{
    fileinto "spam";
    stop;
\}
</code></pre>
\end{document}
