0

My email provider has support for the sieve language (RFC 5228) in advanced mode email filters, but states they "cannot provide additional support on this subject". I'd want to use sieve to improve my current email redirection strategy.

What would be a minimal sieve script such that when an email is somewhat sent to [email protected], which is an alias of my main email account [email protected], it's made a copy to [email protected] (preferably: except if it's detectable from the headers that [email protected] is already an addressee).

I can do almost that with their web-based (non-sieve) rule maker, by testing if the To: or Cc: field is (or contains) [email protected]. However it's not robust. In particular it fails if the email is sent Bcc: [email protected] (which is not among the fields I can specify) or via a redirection to [email protected] (and I don't even know which field I could test for that).

Also, if the email is sent To: [email protected] and Cc: [email protected], I'm afraid the later would receive the email twice.


Update: as suggested in a helpful comment, experiments shows that in what I get thru IMAP in the inbox for [email protected] for something sent to it's alias as Bcc: [email protected] (or even Bcc: [email protected] redirecting to [email protected]), something has helpfully added (on the second line)

Delivered-To: [email protected]

So, assuming that a sieve script runs after that header is generated (I have no idea if that's the case), it may be that I need a minimal sieve script such that when Delivered-To: is [email protected] the email gets copied to [email protected] (preferably: only when neither To: nor Cc: includes [email protected])

I'm a seasoned programmer and postmaster, thus I see possible pitfalls in "includes". It should not be in the sense of string inclusion, should at least be case insensitive, and apply only to the email address without name. I'd like this (my first sieve script) to be as canonical as possible.

4
  • 1
    You might investigate the other headers of your mail messages. My mailserver for example sets an X-Original-To: header with the original e-mail recipient that was used in the SMTP (envelope) RCPT TO command when delivering the e-mail message to the SMTP server. That is the original recipient before expanding any local aliases and would be [email protected] even when that address is on the BCC: list and not included in the addresses of the message headers. My mailserver sets a second header Delivered-To: that is the recipient after expanding all local aliases and forwards.
    – HBruijn
    Nov 30 at 15:19
  • In your example that would be X-Original-To: [email protected] Delivered-To: [email protected]
    – HBruijn
    Nov 30 at 15:25
  • 1
    "Also, if the email is sent to both [email protected] and [email protected], I'm afraid the later would receive the email twice." That is impossible to prevent when both are Bcc and may not even be something you really need to worry about otherwise either. When I sent myself messages with one alias on the To, another one the CC and a third on the Bcc line my mail server receives and stores three separate messages, that in my e-mail client will be displayed as only one single message.
    – HBruijn
    Nov 30 at 15:31
  • Other mail servers may set different headers though. That would take some testing if there is a viable approach there
    – HBruijn
    Nov 30 at 15:51

1 Answer 1

0

I seem to get about the desired effect with the following. But I welcome correction, simplification or improvement!

if allof (
  header :is "Delivered-To" "[email protected]",
  not address :is :all "to" "[email protected]",
  not address :is :all "cc" "[email protected]"
  ) {
  redirect "[email protected]";
  keep;
}
1
  • Will accept the answer only after more tests.
    – fgrieu
    Nov 30 at 18:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .