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?
On 16.02.2018 04:36, @lbutlr wrote:> 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?Hi! you can use regular expressions with sieve, see https://wiki2.dovecot.org/Pigeonhole/Sieve/Examples Aki
On 2018-02-16 (00:18 MST), Aki Tuomi <aki.tuomi at dovecot.fi> wrote:> > On 16.02.2018 04:36, @lbutlr wrote: >> >> 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;> you can use regular expressions with sieve, see > https://wiki2.dovecot.org/Pigeonhole/Sieve/ExamplesThanks. While that shows MATCHING with regex, it doesn't;t show capturing regex matches into variables for reuse. But I'll explore more.
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.
On Feb 16, 2018, at 16:23, Stephan Bosch <stephan at rename-it.nl> wrote:> 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:Thanks for this. I generally exclude my list email from SpamAssassin checks since lists get very little spam. -- My main job is trying to come up with new and innovative and effective ways to reject even more mail. I'm up to about 97% now.
Maybe Matching Threads
- Sieve to process list mail based on list-ID
- Sieve to process list mail based on list-ID
- When the subject portion of an e-mail contains a control character, dovecot.sieve terminates unexpectatedly.
- Released Pigeonhole v0.4.3 for Dovecot v2.2.13.
- Released Pigeonhole v0.4.3 for Dovecot v2.2.13.