0

I have an SMTP + IMAP server on linux and use sieve filtering to provide some useful features.

One such feature is out-of-office replies, provided by the following script:

require ["fileinto", "vacation", "variables"];

# ignore spam
if header :contains "X-Spam-Flag" "YES" {
  fileinto "Junk E-mail";
  stop;
}

vacation
  :days 1
  :subject "Out of office"
  :addresses ["..."]
"contact x, y, or z instead.";

However, I don't like the fact that the auto-replies are transparent to the user; there is no way for a user to definitively answer the question "did X receive a reply?". I would also prefer users, on principle, to be able to see every email that is sent from their address.

For this reason, I would like to store all out-of-office replies in the users sent folder. This way, users can easily review the automatic replies that have been sent.

Does anyone know how this could be achieved?

3
  • And you believe users will check their sent mail folder for this? Good luck with that.
    – Sven
    Apr 29, 2019 at 12:49
  • @Sven It's a small office, so training behaviour isn't such a problem. Besides, i think it's a fair principle that sent mail should include automatic replies from that address.
    – user233054
    Apr 29, 2019 at 12:54
  • @Sven I modified the question to better explain my motivation.
    – user233054
    Apr 29, 2019 at 13:08

1 Answer 1

0

There is no straightforward way to achieve your objective because Sieve scripts are run on the incoming mail only. Outgoing messages are processed by Postfix/Exim/Sendmail or whatever mail transfer agent you are using and therefore Sieve does not get involved. For incoming messages, RFC 5230 expressly prohibits using vacation together with Sieve's "fileinto" action: see section 4.7 of RFC 5230.

So, for Sieve to get involved (1) you must send a copy of your outgoing vacation message to yourself, and (2) you must provide a way for Sieve to identify your vacation auto-reply so that it can move the incoming auto-reply message to your Sent folder.

One possible way to make it happen is through the use of the "plus-aliasing" mechanism in Postfix. This way, you can send vacation auto-replies from the "plus-alias" address and thus identify them for both Postfix and Dovecot/Sieve.

In your Sieve script, make sure that vacation auto-replies are sent from your "plus-alias" address:

vacation
  :from "Your Name <[email protected]>"

Add the following to /etc/postfix/main.cf:

recipient_delimiter = +
header_checks = pcre:/etc/postfix/header_checks.pcre

In /etc/postfix/header_checks.pcre, identify your outgoing vacation messages and add a rule to copy such messages to yourself:

/^From: [^<]*<your.name\[email protected]>/  BCC [email protected]

It may be possible to use backreferences to write a general rule like From: [^<]*<([^\+]+)\[email protected]>/ BCC [email protected], but I have not tried it and cannot say whether this works or not.

Make sure that you have recipient_delimiter = + in /etc/dovecot/conf.d/90-sieve.conf (or whatever other file you are using to configure Sieve).

Finally, add the following rule to the top of your Sieve vacation script:

require ["vacation", "variables", "date", "relational", "fileinto", "envelope"];
if allof ( address :is :all "from" "[email protected]",
           envelope :is :all "to" "[email protected]" ) {
  fileinto "Sent";
}

This Sieve rule will move messages addressed to you and originating from [email protected] to your Sent folder.

You must log in to answer this question.