Sieve, multiple addresses, and variables
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;
}
Now, this works, unless someone sends a To: line like this:
To: ajs@crankycanuck.ca, listname@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@crankycanuck.ca address anyway, which surprised me.
Am I dim, am I not understanding something about how to do this, or is this really impossible?
Thanks,
A
-- Andrew Sullivan ajs@crankycanuck.ca
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@crankycanuck.ca, listname@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@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.
On Wed, Apr 08, 2015 at 02:43:51AM +0200, Stephan Bosch wrote:
This script doesn't compile, due to mismatching '}', but I get the idea.
Doh! Yes, obviously, I copied it from something longer in order to get an isolated example, but should have checked. Thanks.
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).
Got it. Thanks.
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:
That was what I originally wanted to do, but of course that doesn't work when someone does reply-all, I sent the mail, and the list is configured to suppress duplicates. I could turn off duplicate suppression, I suppose, except that the version of pigeonhole in Ubuntu 14.04 LTS doesn't have the duplicate extension (so I guess it's slightly older; dovecot --version says 2.2.9).
The more I think about this (or actually, live with it), however, the less satisfactory the generic answer is anyway, since people often copy more than one list and I discover I have an opinion about which one ought to be "primary". So I think I'll have to go back to a rule per list.
Thanks very much for your help, because this is at least allowing me to learn.
Best regards,
A
-- Andrew Sullivan ajs@crankycanuck.ca
participants (2)
-
Andrew Sullivan
-
Stephan Bosch