Hello, I'm trying to do a simple thing using imapsieve, I want messages to be marked as read when moved to certain folders (Trash, Archive, Spam).
All the set up to run the imapsieve script works perfectly, but I'm having trouble to make changes effective. As the RFC says, IMAP messages are immutable, but it's not clear to me reading the specs if this applies to IMAP flags too, as one can really change flags in IMAP without having to create a new (modified) message, I guess this is an exception?
3.8. The "setflag", "deleteflag", and "removeflag" Actions
Implementations of IMAP events in Sieve MUST also support the imap4flags extension [RFC5232], and the actions associated with it are all applicable to any case that falls under IMAP events in Sieve.
It is worth noting also that the "hasflag" test that is defined in the imap4flags extension might be particularly useful in scripts triggered by flag changes ("hasflag" will see the new, changed flags). The flag changes behave as though a client had made the change.
As explained above, in order to avoid script loops, flag changes that are made as a result of a script that was itself invoked because of flag changes SHOULD NOT result in another script invocation. In any case, implementations MUST take steps to avoid such loops.
https://tools.ietf.org/html/rfc6785
Should changing flags just work for imapsieve? I even tried to use fileinto to explicitly save a new message (as far as I understand if I use fileinto the implicit keep should be cancelled, so the original message should be flagged as \Deleted (this is another hint that changing flags in immutable messages should be fine), and a new message should be created with the changed flags. But this is not happening, after moving the message I see unseen message still not flagged with \Seen.
This is my imapsieve script:
require ["variables", "imap4flags", "fileinto", "vnd.dovecot.imapsieve", "vnd.dovecot.environment", "vnd.dovecot.execute", "vnd.dovecot.debug"];
if header :matches "Subject" "*" { set "subject" "${1}"; } if header :matches "From" "*" { set "from" "${1}"; } if environment :matches "imap.mailbox" "*" { set "dst" "${1}"; }
debug_log "IMAPSIEVE TEST ---------------------"; debug_log "subject:${subject}"; debug_log "from:${from}"; debug_log "dst:${dst}"; debug_log "END IMAPSIEVE TEST -----------------";
if string :is "${dst}" ["Archive", "Trash", "Spam", "Sent"] { debug_log "Moved to ${dst}, marking as read: '${subject}' <${from>"; setflag "\\Seen"; fileinto "${dst}"; }
This is the log:
Aug 16 10:31:51 alerce dovecot: imap(luca): Debug: Archive: Mailbox opened because: UID MOVE
Aug 16 10:31:51 alerce dovecot: imap(luca): Debug: Mailbox INBOX: Opened mail UID=13304 because: copying
Aug 16 10:31:51 alerce dovecot: imap(luca): Debug: imapsieve: mailbox Archive: MOVE event
Aug 16 10:31:51 alerce dovecot: imap(luca): Debug: imapsieve: Matched static mailbox rule [1]
Aug 16 10:31:51 alerce dovecot: imap(luca): Debug: sieve: file storage: Using Sieve script path: /home/luca/sieve/imapsieve.sieve
Aug 16 10:31:51 alerce dovecot: imap(luca): Debug: sieve: file script: Opened script imapsieve' from
/home/luca/sieve/imapsieve.sieve'
Aug 16 10:31:51 alerce dovecot: imap(luca): Debug: sieve: Opening script 1 of 1 from /home/luca/sieve/imapsieve.sieve' Aug 16 10:31:51 alerce dovecot: imap(luca): Debug: sieve: Loading script /home/luca/sieve/imapsieve.sieve Aug 16 10:31:51 alerce dovecot: imap(luca): Debug: sieve: Script binary /home/luca/sieve/imapsieve.svbin successfully loaded Aug 16 10:31:51 alerce dovecot: imap(luca): Debug: sieve: binary save: not saving binary /home/luca/sieve/imapsieve.svbin, because it is already stored Aug 16 10:31:51 alerce dovecot: imap(luca): Debug: sieve: Executing script from
/home/luca/sieve/imapsieve.svbin'
Aug 16 10:31:51 alerce dovecot: imap(luca): sieve: imapsieve: line 11: DEBUG: IMAPSIEVE TEST ---------------------
Aug 16 10:31:51 alerce dovecot: imap(luca): sieve: imapsieve: line 12: DEBUG: subject:Ihr DHL Paket wurde zugestellt.
Aug 16 10:31:51 alerce dovecot: imap(luca): sieve: imapsieve: line 13: DEBUG: from:DHL Paket noreply@dhl.de
Aug 16 10:31:51 alerce dovecot: imap(luca): sieve: imapsieve: line 16: DEBUG: dst:Archive
Aug 16 10:31:51 alerce dovecot: imap(luca): sieve: imapsieve: line 17: DEBUG: END IMAPSIEVE TEST -----------------
Aug 16 10:31:51 alerce dovecot: imap(luca): sieve: imapsieve: line 23: DEBUG: Moved to Archive, marking as read: 'Ihr DHL Paket wurde zugestellt.'
The last line looks weird, it seems like the message is not being copied, right? I tried adding a stop; too, as suggested in this thread https://www.dovecot.org/list/dovecot/2017-April/107658.html, but the effect is the same, the message in Archive is still not flagged as \Seen.
So the main question here is if changing IMAP flags in imapsieve scripts shouldn't just work, without even having to use fileinto, and if not, why isn't even using fileinto working?
PS: Please Cc me, I'm not in the list.
Thanks!
-- Leandro Lucarella (Luca) https://llucax.com