Op 19/09/2018 om 15:07 schreef Adam Raszkiewicz:

I'm trying to get blow Sieve filter to work

require ["fileinto", "imap4flags", "mailbox", "body", "envelope", "vnd.dovecot.pipe", "variables", "vnd.dovecot.execute"];

 

if envelope :matches "To" "*@*" {

  set "recipient" "${0}";

  set "user" "${1}";

  set "recip_domain" "${2}";

}

 

if envelope :matches "From" "*" {

  set "sender" "${0}";

}

 

#Check if recipient is valid user

if execute :output "valid_user" "user-verification" "${recipient}" {

    if string :matches "${valid_user}" "True" {

      if body :raw :contains ["message/notification"] {

        setflag "\\Seen";

        fileinto :create "Notifications";

        stop;

      }

    }

}

 

Where user-verification is an extprogram which calls API and verify user based on email address then returns boolean (as an output to the console).

Everything works fine when I will remove if string :matches "${valid_user}" "True"statement other way it looks like is not recognizing valid_uservariable.

When I pipe valid_user to some script just to capture value for that variable it throws an error:

 

error: specified :args item `True?' is invalid.

 

Why question mark was added to the variable in this case?


I am not sure what you're doing, but this works here:

# user-verification shell script:
#!/bin/bash

echo -n "False"

# sieve script:
require ["fileinto", "imap4flags", "mailbox", "body", "envelope", "vnd.dovecot.pipe", "variables", "vnd.dovecot.execute", "vnd.dovecot.debug"];

if envelope :matches "To" "*" {
  set "recipient" "${0}";
}
if envelope :localpart :matches "To" "*" {
  set "user" "${1}";
}
if envelope :domain :matches "To" "*" {
  set "recip_domain" "${1}";
}

if envelope :matches "From" "*" {
  set "sender" "${0}";
}

#Check if recipient is valid user

if execute :output "valid_user" "user-verification" "${recipient}" {
    if string :matches "${valid_user}" "True" {
        debug_log "TRUE";
    } else {
        debug_log "FALSE";
    }
}

This logs the following in the user log:

frop: line 22: info: DEBUG: TRUE.

If I change the script to print something else, it correctly logs "FALSE".

Did you perhaps forget "-n" for the echo command? In that case "True" is followed by a newline, which Sieve happily reads and includes in the variable value.

Regards,

Stephan.