On 24 Sep 2020, at 22:07, Sami Ketola <sami.ketola@dovecot.fi> wrote:

I think this should be

require ["environment"];

instead.

I eventually stumbled on a syntax that worked. Putting all of this in one place:

- You need to turn on the sieve_extprograms plugin:

  sieve_plugins = sieve_extprograms

- Then you need to enable vnd.dovecot.environment:

  sieve_global_extensions = +vnd.dovecot.environment

- Then you need to pull the extra fields you want out of the userdb, and those fields must be prefixed with “sieve_env_”, like this example for LDAP:

  user_attrs = mailMessageStore=home=%$,=sieve_env_mail_auto_reply_mode=%{ldap:mailAutoReplyMode},=sieve_env_mail_auto_reply_text=%{ldap:mailAutoReplyText}

- Then you need to add a requirement on “vnd.dovecot.environment” to the sieve script.

- Then, to access the variables in the sieve script, you need to drop the “sieve_env_” part, and add the prefix “env.vnd.dovecot.config.”. There are various docs floating around that reference the above variable without the leading “env.” - this must be there too.

- The resulting sieve looks like this:

require ["fileinto", "mailbox"];
require ["vacation", "variables"];
require ["vnd.dovecot.environment"];

# fileinto: for putting mail into a imap folder
# mailbox: for creating imap folder if not exists
#
if header :contains "X-Spam-Flag" "YES" {
    # move mail into folder Junk, create folder if not exists
    fileinto :create "Junk";
    stop;
}

if string :matches "${env.vnd.dovecot.config.mail_auto_reply_mode}" "reply" {
    if header :matches "subject" "*" {
        vacation :subject "AutoReply: ${1}"
            "${env.vnd.dovecot.config.mail_auto_reply_text}";
    }
}

- The output of sieve-test looks like this. The handle is weird, but I’m assuming there is method in the madness somehow:

sieve-test(root): Debug: sieve: Pigeonhole version 0.5.8 (b7b03ba2) initializing
sieve-test(root): Debug: sieve: include: sieve_global is not set; it is currently not possible to include `:global' scripts.
sieve-test(root): Debug: sieve: Sieve Extprograms plugin for Pigeonhole version 0.5.8 (b7b03ba2) loaded
debug: file storage: Using Sieve script path: /var/lib/dovecot-sieve/default.sieve.
debug: file script: Opened script `default' from `/var/lib/dovecot-sieve/default.sieve'.
debug: Script binary /var/lib/dovecot-sieve/default.svbin successfully loaded.
debug: binary save: not saving binary /var/lib/dovecot-sieve/default.svbin, because it is already stored.

Performed actions:

 * send vacation message:
    => seconds : 604800
    => subject : AutoReply: Test1
    => handle  : ${env.vnd.dovecot.config.mail_auto_reply_text}AutoReply: ${1}<default-from><NO-MIME>

START MESSAGE
I am truly away...
END MESSAGE

Implicit keep:

 * store message in folder: INBOX

sieve-test(root): Info: final result: success

Regards,
Graham