Sieve, multiple addresses, and variables
Stephan Bosch
stephan at rename-it.nl
Wed Apr 8 00:43:51 UTC 2015
On 4/7/2015 10:48 PM, Andrew Sullivan wrote:
> Hi,
>
> I have another sieve question, this time about setting variables.
>
> I join a lot of mailing lists at ietf.org. I thought it'd be handy to
> filter these all into a common folder and then into individual
> folders, without having to configure each mailing list independently.
>
> So wrote this (this is just a part, obviously):
>
> require ["envelope", "variables", "date", "fileinto", "mailbox" ];
> if address :is :domain "to" "ietf.org" {
> if address :matches :localpart "to" "*" {set "lopart" "${1}";}
> }
> elsif address :is :domain "cc" "ietf.org" {
> if address :matches :localpart "cc" "*" {set "lopart" "${1}";}
> }
> else {set "lopart" "generic-list-box";}
> fileinto :create "ietf.${lopart}-in";
> stop;
> }
This script doesn't compile, due to mismatching '}', but I get the idea.
> Now, this works, unless someone sends a To: line like this:
>
> To: ajs at crankycanuck.ca, listname at ietf.org
>
> The problem in that case is that you _do_ get a match, but the bit "if
> address :matches :localpart "to" "*" {set "lopart" "${1}";}" ends up
> putting this in a mailbox ietf.ajs-in, when what is the mailbox
> ietf.listname-in.
>
> I thought that
>
> allof(if address :matches :localpart "to" "*",
> address :matches :localpart "to" "*")
> {set "lopart" "${1}";},
>
> would solve this, but it doesn't seem to. The localpart matching
> catches the ajs at crankycanuck.ca address anyway, which surprised me.
This is a bit of a limitation of Sieve. These tests always yield the
first matching address (part) and there is no way to link the tests
based on which address matched previously (logic connectives have no
effect on that either).
In the spirit of your original script, the following would work:
require ["envelope", "variables", "date", "fileinto", "mailbox"];
if address :matches ["to","cc"] "*@ietf.org" {
set "lopart" "${1}";
} else {
set "lopart" "generic-list-box";
}
fileinto :create "ietf.${lopart}-in";
However, since this concerns mailing lists, there is a better, more
reliable way using the List-Id header that the IETF also uses for its
mailing lists:
require ["envelope", "variables", "date", "fileinto", "mailbox"];
if header :matches "list-id" "*<*.ietf.org>*" {
set "listbox" "ietf.${2}-in";
} else {
set "listbox" "generic-list-box";
}
fileinto :create "${listbox}";
Regards,
Stephan.
More information about the dovecot
mailing list