Joachim Breitner

Goodbye procmail, Hello Sieve

Published 2010-10-09 in sections English, Digital World.

After having switched from Courier to Dovecot half a year ago I thought it was finally time to look into Sieve. For many years now I have maintained a procmail script to filter my incoming e-mail into  numerous subfolders. Two features are important to me: For mailing lists, folders are created automatically based on the list names, with some adjustments for certain domains, such as putting all Debian lists into a folder of their own. And my procmail script was parsing the a dump of my evolution address book to put mail from people I know in a special folder. I did not know that at the first point is actually possible in Sieve but it is, using the variables extensions. And then the second was not hard to fix either, using this small and crude bash script, which creates a Sieve script recognizing these addresses, which is called from my main Sieve script:

#!/bin/bash
(
echo 'require ["fileinto"];'
echo 'if address ["From"] ['
/usr/lib/evolution/*/evolution-addressbook-export |
 perl -n -e 'print "\"$1\",\n" if /.*:(.*@[a-z0-9.]*)\s*$/'
 echo '"Justadummy"'
echo '  ] {'
echo ' fileinto "INBOX.Bekannte"; '
echo ' }'
) > /tmp/bekannte
sieve-connect --user mail@joachim-breitner.de \
    --server 10.254.1.101 --port 2000 --notlsverify \
    --localsieve /tmp/bekannte --remotesieve bekannte  \
    --upload

I set up ManageSieve to be able to upload the scripts using sieve-connect. And finally I am able to do something that I have missed in all the years: Using the imap4flag extension, I can mark some mail automatically as read. This is useful for mail that is actually generated by me using program besides my e-mail client, such as bug reports sent by reportbug or patches submitted using darcs. I might even enable this feature for mailing list mails that I have sent.

Comments

Hello Joachim.
Like you, I am planning a switch from procmail to Sieve. I have built scripts that I use from procmail, some for info processing, some to modify the email.

In your blog entry from saturday, october 9. 2010 : "Goodbye procmail, Hello Sieve" you listed a small bash script that does some cool Meta-programming and remote-procedure call that self-modifies your Sieve configuration.

My scripts are simple in comparison, but I am missing/cannot find how to write a Sieve script that invokes an external tool, (bash script or any command line tool) on an email.

Could you please post or email how you invoke a bash script, or any external tool, from a sieve script? (Or a pointer to anything that shows how its done? )

My thanks for taking the time to read this.
Jeff Kinz.
#1 Jeff kinz (Homepage) am 2011-08-21
Dear Jeff,

for security reasons, Sieve does not allow calling external tools at all.

My script is not run from a sieve script but rather manually. It _generates_ a sieve script and uploads it to the server, but it is not self-modifying.

Greetings,
Joachim
#2 Joachim Breitner (Homepage) am 2011-08-22
Ah, I may see where your confusion stems from. The script that “is called from my main Sieve script.” refers to the generated Sieve script (using the include command), _not_ the listed bash snippet.
#3 Joachim Breitner (Homepage) am 2011-08-22

Have something to say? You can post a comment by sending an e-Mail to me at <mail@joachim-breitner.de>, and I will include it here.