Articles January 6, 2008 at 9:56 pm

Using avelsieve to edit Sieve filters in SquirrelMail on 10.5

Leopard Server has all of the pieces installed for sieve filters for server-side mail filtering, but if you want to use the SquirrelMail filter interface to allow users to add filters, then you have to do a little work.  We've provided a pkg to install the avelsieve package that allows you to install it the plugin to SquirrelMail, but it is a bit incompatible with 10.5 Server.  

Read on to see how to resolve it….

If you have gotten used to using server side mail filters using Sieve and squirrelmail, you'll probably notice that existing rules work fine in Leopard Server, but if you create a new rule you'll get the dreaded "Did not specify legal script data length" when trying to save the new rule. This is due to a change in PHP5 in how curly brackets are quoted in PHP scripts. But fear not. There are 2 solutions:

  1. Use the existing avelsieve package provide here on AFP548, and make a slight modifications to it to fix the quoting incompatibility.
  2. Use the more full featured dev release of avelsieve (v. 1.9.7 at the writing of this). 

Both work fine.  I like the cleaner interface to 1.9.7 in SquirrelMail, but it is a dev release, so caution is advised.  I'll provide instructions on how to get both working.

Option 1: Use the existing avelsieve.pkg:

If you already have it installed due to a server upgrade, skip steps 1-3, and just edit the sieve-php.lib.php file in step 4.

1.  Download the avelsieve package here and install on the server.  It dumps its files in /usr/share/squirrelmail/plugins, which is sym linked by /etc/squirrelmail/plugins -> /usr/share/squirrelmail/plugins. 

2.   Activate the plugins via the config.pl script in /etc/squirrelmail/config:

<span class="Apple-style-span">s</span>udo perl&nbsp;/etc/squirrelmail/config/conf.pl<br />

Choose option (8) for Plugins

select "avelsieve".

This adds the correct configuration line to  /etc/squirrelmail/config.php.

3.  Set the correct authentication type.  Edit /etc/squirrelmail/plugins/avelsieve/config.php and change:

<span class="Apple-style-span">&#36;</span>preferred_mech = &quot;PLAIN&quot;;<br />

 to

<span class="Apple-style-span">&nbsp;</span>&#36;preferred_mech = &quot;CRAM-MD5&quot;;<br />

If you are using PLAIN or LOGIN, set it to that, but most likely it will be CRAM-MD5. 

4.  Edit the /etc/squirrelmail/plugins/avelsieve/lib/sieve-php.lib.php file. Find the line:

    fputs($this->fp, "PUTSCRIPT \"$scriptname\" \{$len+}\r\n"); 

 

and change it to :

 

    fputs($this->fp, "PUTSCRIPT \"$scriptname\"".' {'."$len+".'}'."\r\n");

 
The issue is the quoting of the curly bracket.  The output of this iine is supposed to be something like:
PUTSCRIPT "PHPSCRIPT" {503+}  but instead comes out as:
 
PUTSCRIPT "PHPSCRIPT" \{503+}

 
 The changes above simply concatenating the curly brackets instead of escaping them.  From what I can see in the PHP bug database, this is expected behavior.  
 
 Head over to http://<your domain>/webmail, sign in, and you should now be able to add filters again.

 Option 2: Use the dev version:

1.  Go to http://email.uoa.gr/projects/squirrelmail/avelsieve_download.php and download the latest dev version.  As of this writing, it is version 1.9.7. Hopefully it will soon be 2.0 and part of the stable release.

2.  If you currently have avelsieve installed in, move it out of the way:

<span class="Apple-style-span">s</span>udo mv /usr/share/squirrelmail/plugins/avelsieve /usr/share/squirrelmail/plugins/avelsieve.old<br />

3.  copy avelsieve-1.9.7.tar.gz to /usr/share/squirrelmail/plugins and unzip and untar it.  You should now have a new avelsieve folder in /usr/share/squirrelmail/plugins.

4. Change the owner to www:staff and permissions to something sane like 744. 

4. The config file is in a bit of a different location, and is a different format than the prior version of avelsieve.  Copy /etc/squirrelmail/plugins/avelsieve/config/config_sample.php to /etc/squirrelmail/plugins/avelsieve/config/config.php. 

5.  Edit this  config.php and change the authenication type to :

<span class="Apple-style-span">&nbsp;</span>&#36;sieve_preferred_sasl_mech = &#39;CRAM-MD5&#39;;<br />

Head over to http://<your domain>/webmail, sign in, and you should now see the new interface and be able to add filters.

Timothy Perfitt

Timothy Perfitt is currently the head of Twocanoes Software, Inc, creator of iOS and Mac apps for the IT market. Prior to Twocanoes Software, he survived the collapse of the dot com era by jumping from Coolboard.com to Apple, Inc in 2001. He worked on the initial certification training materials for Mac OS X, worked in Education Sales, and then finished his time at Apple in 2012 working with Fortune 500 customers to integrate Macs and iOS devices into complex environments. He is a returned Peace Corps volunteer, serving in the Solomon Islands as a math and science teacher from 1991 to 1993.

More Posts - Website

Follow Me:
Twitter

No Comments

  • The path in step 3 is wrong. It should be “/etc/squirrelmail/plugins/avelsieve/config/config.php”

    • Oups – my mistake, I was not looking at the right solution (I was looking in the “package solution” when I was actually using the “Developer solution”. My bad…

    • Thanks for the info on making this work. I used the stable avelsieve release and was able to get it working using your guide but I found a couple of “gotchas” on my completely factory Xserve running 10.5.6, maybe these are normal maybe they only applied to me:

      • The port for Sieve, 2000, is set up for a different service named “callback”. I had to edit the /etc/services file to change the entry for that port.
      • The /usr/sieve directory didn’t exist on my system. So it had to be created and the correct ownership + permissions applied. I used this as a guide (updating it for 10.5): http://discussions.apple.com/thread.jspa?messageID=660097&#660097

      Thanks again for the step describing how to fix the “curly quotes” issue as I would have beat my head against my desk for some time trying to figure out the error message.


      You want to do what with my server?!

  • I’ve followed the steps outlined above and also firehaus’ fine pointers regarding the Apple Discussion page. I created the new directory, gave it the permissions went to the /etc/services and edited the port information for port 2000. $preferred_mech has been set to both “PLAIN” and CRAM-MD5 (not at the same time).

    However, I am still not able to telnet into port 2000, and clicking on “filters” in SquirrelMail gives me the following error: Warning: fsockopen() [function.fsockopen]: unable to connect to localhost:2000 (Connection refused) in /usr/share/squirrelmail/plugins/avelsieve/lib/sieve-php.lib.php on line 366

    Am I missing something in the steps?

    • I managed to fix it by changing $preferred_mech to “CRAM-MD5” after setting both TCP and UDP ports 2000 to “sieve”.

    • I too am having enormous trouble getting avelsieve script working with SquirrelMail on Mac OS 10.5 Server. It is too much trouble to get out-of-office type service. Kerio looks so much more appealing.

Leave a reply

You must be logged in to post a comment.