Sieve to process list mail based on list-ID

Stephan Bosch stephan at rename-it.nl
Sat Feb 17 01:23:38 EET 2018


Op 2/16/2018 om 3:36 AM schreef @lbutlr:
> Before I spend a lot of time trying to replicate a procmail script that automatically sorts list mail into mailboxes based on the List-ID header (and possibly some other data) I thought I'd check if someone had already done this for sieve.
>
> Basically, what I do now in procmail is
>
> 1. Get the listname from the List-ID header (or List-post/List-owner if no ID)
>
> 2. check against a list of list-ids and if the ID is not on the list, send it to spamc and put the message (if not spam) in the INBOX but mark it as seen, otherwise put it in Junk.
>
> 3. have some list specific rules (like rewriting reply-to, stripping subjected tags, etc.
>
> 4. Drop message in mailbox based no the ID.
>
> (so, dovecot mail goes into .dovecot/new but RandomFakelist gets scanned for spam and if it passes, marked read and put in the inbox).
>
> I've seen things like:
>
> if exists "List-Id" {
>   if header :contains "List-Id" "dovecot.dovecot.org" {
>     fileinto "dovecot";
>   } elsif header :contains "List-Id" "others-list.example.com" {
>     fileinto "other-list";
> }
>
> But I am looking for something more generic, along the lines of
>
> $myLists = {"dovecot", "postfix", "other-list")
> if header :contains "List-ID" "<([^\.])+." { $myID $1; }
> if $myList :contains $myID { 
>   if { $myID is other-list {
>      set $myID to Olist;
>      set header "reply-to" to "moderator at users+other@foo.example.net";
>   }
> fileinto $myID;
>
> } else {
>   send message to spamc and await results;
>   if spam {fileinto "Junk";} else {fileinto "INBOX";}
>
> (obviously that's not the code, but it should give an idea of the sorts of things I want to do and would rather not entirely duplicate.
>
> Obviously, I don't know if sieve does variables at all (none of the few example scripts I've looked at have them, but then again most procamil scripts don't have them either).
>
>
> Does sieve support that sort of matching?

Something like this:

##################
require "variables";
require "regex";
require "comparator-i;ascii-numeric";
require "relational";
require "editheader";
require "spamtestplus";
require "fileinto";

if header :regex "List-ID" "<([^\.])+." { set "myID" "${1}"; }

if string ["dovecot", "postfix", "other-list"] "${myID}" {
  if string "${myID}" "other-list" {
     set "myID" "Olist";
     deleteheader "reply-to";
     addheader "reply-to" "moderator at users+other@foo.example.net";
  }
  fileinto "${myID}";
  stop;
}

# The spamtest test only checks the configured spam header; it does not
# the run spam classifier!
if spamtest :percent :value "eq" :comparator "i;ascii-numeric" "100" {
  fileinto "Junk";
  stop;
}

# Implicit keep (delivery into INBOX)

##################

I didn't test this. The editheader and spamtestplus extension aren't
enabled by default and need configuration:

https://wiki2.dovecot.org/Pigeonhole/Sieve/Extensions/Editheader#Configuration
https://wiki2.dovecot.org/Pigeonhole/Sieve/Extensions/SpamtestVirustest#Configuration

This does not include the spam filter call it self like it is in your
proposed script. Dat is usually not a good idea: you should call the
spam filter from the MTA, before it gets to Dovecot. If you really want
to do it in Sieve, you need to use extprograms plugin with the
non-standard "vnd.dovecot.filter" extension:

https://wiki2.dovecot.org/Pigeonhole/Sieve/Plugins/Extprograms
https://github.com/dovecot/pigeonhole/blob/master/doc/rfc/spec-bosch-sieve-extprograms.txt

Regards,

Stephan.



More information about the dovecot mailing list