Subject: A little sieve help

From: Patrick Baldwin <[email-masked]>
Date: Wed, 10 Dec 2008 17:31:36 -0500

Hi, I'm in the process of moving my mail to a new server, which will be 
using sieve
instead of procmail.  I've run into some difficulty, and this list was 
the only one I could
find mentioned in conjunction with sieve; if this is an inappropriate 
venue for my questions,
my apologies.

First I tried the conversion script mentioned in:

http://dovecot.org/list/dovecot/2007-March/020895.html

But that didn't produce any output.

I'm trying to turn this procmail script into a sieve script (alterations 
from real
script in <>):

:0
* ^TO_(online)
| /usr/local/bin/dmail +online

:0
* ^TO_(support|internal)
| /usr/local/bin/dmail +Support

:0
* ^From:.ship@.*(<company-name>\.com)
| /usr/local/bin/dmail +SHIPMENTS

:0c
* !^FROM_DAEMON
* !^FROM_MAILER
* !^X-Loop: to_gmail
| (formail -i"Cc:" -I"To: <user name>@gmail.com" \
               -A"X-Loop: to_gmail" \
  ) | $SENDMAIL -t

:0
| /usr/local/bin/dmail

In sieve, I was thinking something like:

require ["fileinto","regex","envelope"];

if address :is "To" "online" {
  fileinto "online";
} elsif address :is "To" "Support" { 
  fileinto "Support";

if address :is "From" "<ship address>" {
  fileinto "SHIPMENTS";
}

redirect "<user name>@gmail.com";
keep;

stop;

...but I'm really not sure.  I also haven't figured out how to have sieve
insert a header to avoid mail loops like I did with procmail.

Any help much appreciated.

Regards,

-- 
Patrick Baldwin
Systems Administrator
Studsvik Scandpower
617-965-7455

---

From: Aaron Stone <[email-masked]>
Date: Wed, 10 Dec 2008 17:53:30 -0800

This mailing list mostly works on Sieve as a standard, but a few user
questions now and then is good -- someone is using this stuff! ;-)

On Wed, 2008-12-10 at 17:31 -0500, Patrick Baldwin wrote:

[snip procmail script]

}
> if address :is "From" "<ship address>" {

:matches might be what you want, rather than :is.

> redirect "<user name>@gmail.com";

Stop is not needed at the end of the script, but doesn't hurt.

> insert a header to avoid mail loops like I did with procmail.

libsieve doesn't support the editheader extension yet, RFC 5293. It's on
my todo list...

Aaron

---

From: Patrick Baldwin <[email-masked]>
Date: Thu, 11 Dec 2008 13:50:20 -0500

Aaron Stone wrote:
> This mailing list mostly works on Sieve as a standard, 

Is there another list that would be better for user questions?

> but a few user

That's the plan.

> :matches might be what you want, rather than :is.

Sure was, thanks.

> libsieve doesn't support the editheader extension yet, RFC 5293. It's on

Is there some other way I should be trying to use sieve to prevent a 
possible mail loop?

Regards,

-- 
Patrick Baldwin
Systems Administrator
Studsvik Scandpower
617-965-7455

---

From: Ned Freed <[email-masked]>
Date: Thu, 11 Dec 2008 11:53:09 -0800 (PST)

> Is there some other way I should be trying to use sieve to prevent a

First of all, sieve implementations are required to check for redirect loops
and break them if necessary. This means that accidental redirection loops
should be a nonissue - if they are an issue something is broken in your Sieve
implementation.

This leaves two other cases: intentional loops, such as when want both A and B
to get a copy of every message no matter where it was originally sent, and
bounce loops.

Adding headers and checking for them later does break loops in this case, but
unless you're able to add the header on both A and B it won't break the loop
until one duplicate is received. You're much better off finding a header or
some other telltake that's added naturally by either side and checking for it
in the other side. Received: fields are often a useful place to look for such
telltales.

Bounce loops are a nastier bit of business. A true bounce loop should not be
able to form because of the requirement on redirect that it not change
empty envelope from addresses. But this means that a bounce will be redirected
and then dropped by the other end, which breaks the loop but adds overhead
you'd probably like to avoid.

The other problem with bounce loops is that not all MTAs or filtering
mechanisms are standards compliant, and you may find cases where envelope from
addresses get filled in by forwarders (bad) or bounces are sent to header From:
fields (also bad). Again, if your Sieve implementation does any of these
things, it's broken.

Probably the most effective way to deal with them is to simply not forward
messages with an empty envelope address, e.g.

    if not envelope :is "from" "" { redirect "a@b"; }

But that will prevent forwarding of all bounces, which may not be what you
want. If that's unworkable, you're back to looking for telltales the other
system inserts into the DSNs it generates. Find one of those, test for it,
and if it is present don't redirect the message.

				Ned