Discussion:
sieve: is it possible to filter ALL mailing lists (with header List-Id) to their folders with ONE rule?
Lev Serebryakov
2014-09-12 18:25:19 UTC
Permalink
Hello, Dovecot.


Is it possible to write one rule in sieve, which will:

(1) Trigger on any message with "List-Id" header

AND

(2) Put this message to folder with name build from content of "List-Id"
header, in such way, that message with List-Id

List-Id: This is decription of list <list-name.host.org>

will be put into folder "org.host.list-name" where "." is namespace
separator (so, such folders will be shown as hierarchy in mail client)?

I don't want to write ~50 rules by hands and add new ones from time to
time.

I'm speaking about dovecot/pigeonhole sieve implementation, of course. All
examples on net shows only manual one-rule-per-list approach :(
--
// Black Lion AKA Lev Serebryakov <lev at serebryakov.spb.ru>
A. Schulze
2014-09-12 18:37:51 UTC
Permalink
Post by Lev Serebryakov
List-Id: This is decription of list <list-name.host.org>
will be put into folder "org.host.list-name" where "." is namespace
separator (so, such folders will be shown as hierarchy in mail client)?
:-)
had the same idea while writing my sieve file ...

Another idea would be a key -> value map
key : list-id
value: foldername

Andreas
Dominik Breu
2014-09-12 19:40:25 UTC
Permalink
Hello list,

just a quick guess from my side:

if header :matches "List-ID" "<*.*.*>" {
fileinto "INBOX.${3}.${2}.${1}"; stop;
}

this should do the trick

-dominik
Post by A. Schulze
Post by Lev Serebryakov
List-Id: This is decription of list <list-name.host.org>
will be put into folder "org.host.list-name" where "." is namespace
separator (so, such folders will be shown as hierarchy in mail client)?
:-)
had the same idea while writing my sieve file ...
Another idea would be a key -> value map
key : list-id
value: foldername
Andreas
Lev Serebryakov
2014-09-12 19:48:48 UTC
Permalink
On 09/12/2014 23:40, Dominik Breu wrote:

Looks like it should work, only should be tinkered for different
number of parts in ID. But it is better than full-manual :)

Thank you.
if header :matches "List-ID" "<*.*.*>" { fileinto
"INBOX.${3}.${2}.${1}"; stop; }
this should do the trick
-dominik
Post by Lev Serebryakov
List-Id: This is decription of list <list-name.host.org>
will be put into folder "org.host.list-name" where "." is
namespace separator (so, such folders will be shown as
hierarchy in mail client)?
:-) had the same idea while writing my sieve file ...
foldername
Andreas
Robert Schetterer
2014-09-13 05:58:19 UTC
Permalink
Post by Dominik Breu
Hello list,
if header :matches "List-ID" "<*.*.*>" {
fileinto "INBOX.${3}.${2}.${1}"; stop;
}
this should do the trick
-dominik
nice
i think ,you might need listescape plugin for folders with dots, depend
to your namespace setup
Post by Dominik Breu
Post by A. Schulze
Post by Lev Serebryakov
List-Id: This is decription of list <list-name.host.org>
will be put into folder "org.host.list-name" where "." is namespace
separator (so, such folders will be shown as hierarchy in mail client)?
:-)
had the same idea while writing my sieve file ...
Another idea would be a key -> value map
key : list-id
value: foldername
Andreas
Best Regards
MfG Robert Schetterer
--
[*] sys4 AG

http://sys4.de, +49 (89) 30 90 46 64
Franziskanerstra?e 15, 81669 M?nchen

Sitz der Gesellschaft: M?nchen, Amtsgericht M?nchen: HRB 199263
Vorstand: Patrick Ben Koetter, Marc Schiffbauer
Aufsichtsratsvorsitzender: Florian Kirstein
Darac Marjal
2014-09-15 09:12:11 UTC
Permalink
Post by Lev Serebryakov
Hello, Dovecot.
(1) Trigger on any message with "List-Id" header
AND
(2) Put this message to folder with name build from content of "List-Id"
header, in such way, that message with List-Id
List-Id: This is decription of list <list-name.host.org>
will be put into folder "org.host.list-name" where "." is namespace
separator (so, such folders will be shown as hierarchy in mail client)?
I don't want to write ~50 rules by hands and add new ones from time to
time.
I'm speaking about dovecot/pigeonhole sieve implementation, of course. All
examples on net shows only manual one-rule-per-list approach :(
Not one rule, but I use the following script to filter mailing lists
into folders. It handles most mailing list types and, for consistency,
the folder name is case-folded to title case.

##
require [ "regex", "variables", "fileinto", "envelope", "mailbox", "imap4flags" ];

# Mailinglist Killfile
if anyof (header :contains "from" "unwanted at example.com",
header :contains "from" "spammer at example.net",
header :contains "from" "troll at example.org"){
discard;
stop;
}

if anyof (header :contains "x-spam-flag" "yes",
allof (header :regex "X-DSPAM-Result" "^(Spam|Virus|Bl[ao]cklisted)$",
not header :contains "X-DSPAM-Reclassified" "Innocent")){
# Spam goes into the spam folder
setflag "\\Seen";
fileinto :create "spam";
stop;
}

# split out the various list forms
# Mailman & other lists using list-id
if exists "list-id" {
if header :regex "list-id" "<([a-z_0-9-]+)[.@]" {
set :lower "listname" "${1}";
fileinto :create "${listname}";
} else {
if header :regex "list-id" "^\\s*<?([a-z_0-9-]+)[.@]" {
set :lower "listname" "${1}";
fileinto :create "${listname}";
} else {
keep;
}
}
stop;}
# Listar and mailman like
elsif exists "x-list-id" {
if header :regex "x-list-id" "<([a-z_0-9-]+)\\\\." {
set :lower "listname" "${1}";
fileinto :create "${listname}";
} else {
keep;
}
stop;}
# Ezmlm
elsif exists "mailing-list" {
if header :regex "mailing-list" "([a-z_0-9-]+)@" {
set :lower "listname" "${1}";
fileinto :create "${listname}";
} else {
keep;
}
stop;}
# York lists service
elsif exists "x-mailing-list" {
if header :regex "x-mailing-list" "^\\s*([a-z_0-9-]+)@?" {
set :lower "listname" "${1}";
fileinto :create "${listname}";
} else {
keep;
}
stop;}
# Smartlist
elsif exists "x-loop" {
if header :regex "x-loop" "^\\s*(a-z_0-9-]+)@?" {
set :lower "listname" "${1}";
fileinto :create "${listname}";
} else {
keep;
}
stop;}
# poorly identified
elsif envelope :contains "from" "owner-" {
if envelope :regex "from" "owner-([a-z_0-9-]+)-outgoing@" {
set :lower "listname" "${1}";
fileinto :create "${listname}";
} elsif envelope :regex "from" "owner-([a-z_0-9-]+)@" {
set :lower "listname" "${1}";
fileinto :create "${listname}";
} elsif header :regex "Sender" "owner-([a-z_0-9-]+)@" {
set :lower "listname" "${1}";
fileinto :create "${listname}";
} else {
keep;
}
stop;}
# other poorly identified
elsif envelope :contains "from" "-request" {
if envelope :regex "from" "([a-z_0-9-]+)-request@" {
set :lower "listname" "${1}";
fileinto :create "${listname}";
} else {
keep;
}
stop;
}

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://dovecot.org/pipermail/dovecot/attachments/20140915/1265369b/attachment-0001.sig>
Loading...