IMAP flags not carried through in user Sieve script
Flags set in the per-account Sieve script are lost when using fileinto in a user Sieve script.
Example:
# Account script
require ["imap4flags"];
setflag "\\Flagged";
# User script
require ["imap4flags", "fileinto"];
fileinto "Junk";
# the email ends up in Junk without any flags
This is sort of correct, as the RFC 5232 (Imap4flags) says:
[the internal variable] has the empty value when the script starts
However, this is a bummer because it would be useful to propagate information to the user script with flags. It could be used, for example, to filter spam for the whole account and have each user file flagged emails into their spam folder (working around the inability to use "fileinto" in the account-wide script).
It's also a bit inconsistent in that if you don't use fileinto in the user script and instead lean on the implicit keep, the flag set in the per-account script is retained, even though:
The value of the internal variable also applies to the implicit keep.
(RFC 5232, section 3)
Which suggests that in the following example, the value of the internal variable is "\\Flagged", not the empty value:
# Account script
require ["imap4flags"];
setflag "\\Flagged";
# User script
stop;
# the email ends up in INBOX with the "\\Flagged" flag
But a test for hasflag :contains "\\Flagged" fails.
I suggest initializing the user script's internal variable with the IMAP flags set in the account script, which will be correct under RFC 5232 when no flags were set, and incorrect but less surprising when there were.
Alternatively, the passed-down flags could be made available in a variable, possibly using a custom extension and namespace as described in RFC 5229 (Variables), section 3.
They're supposed to flow from the account to the imap script (as if the account script were a prefix to the user script), so it's a bug that they don't. I will investigate.