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 <your.name+ooor@example.com>"
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\+ooor@example.com>/ BCC your.name@example.com
It may be possible to use backreferences to write a general rule like From: [^<]*<([^\+]+)\+ooor@example.com>/ BCC $1@example.com
, 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" "your.name+ooor@example.com",
envelope :is :all "to" "your.name@example.com" ) {
fileinto "Sent";
}
This Sieve rule will move messages addressed to you and originating from your.name+ooor@example.com to your Sent
folder.