Hi,
I'm finding myself regularly moving messages to the wrong folder in my MUA. Most of the time this is easily corrected, but sometimes this is a bit harder. Imagine selecting all messages in the 'Trash' or 'Junk' folder, and moving them in the 'Archive' folder (by clicking on the MUA's 'Archive' button in stead of the 'Delete' button).
I'm looking into blocking this server-side using an IMAPSieve script. So far I've been able to log relevant details of such a message move, but I don't how I can abort the message move altogether. I'm now using the following config, which result in log messages like:
dovecot: imap(tom@example.org)<540588><TmDbwVATNOoqEDeBFZcAASOvWpPsXcmR>: sieve: DEBUG: move-to-archive: Message archived: mailbox-from=INBOX mailbox-to=Archives.2023 message-id=<648ab0b4-8439-4b2d-8e53-b97e700ff9d0@mail.example.org> subject='Testing IMAPSieve'
File: dovecot.conf
protocol imap { mail_plugins = $mail_plugins imap_sieve }
plugin { sieve_plugins = sieve_imapsieve sieve_implicit_extensions = +vnd.dovecot.debug
# Find out how to block messages from being from 'Trash' to 'Archive' folder imapsieve_mailbox1_name = Archives.* #imapsieve_mailbox1_from = INBOX imapsieve_mailbox1_before = file:/etc/dovecot/sieve-scripts/move-to-archive.sieve }
File: move-to-archive.sieve
require "environment"; require "variables"; require "vnd.dovecot.debug"; require "vnd.dovecot.imapsieve";
if header :matches "Message-ID" "*" { set "message_id" "${1}"; } else { set "message_id" "UNKNOWN"; }
if header :matches "Subject" "*" { set "subject" "${1}"; } else { set "subject" "UNKNOWN"; }
if environment :matches "vnd.dovecot.mailbox-from" "*" { set "mailbox_from" "${1}"; } else { set "mailbox_from" "UNKNOWN"; }
if environment :matches "vnd.dovecot.mailbox-to" "*" { set "mailbox_to" "${1}"; } else { set "mailbox_to" "UNKNOWN"; }
debug_log "move-to-archive: Message archived: mailbox-from=${mailbox_from} mailbox-to=${mailbox_to} message-id=${message_id} subject='${subject}'";
I tried the "reject" sieve command but that only works in the context of delivery. Is there a way to abort the actual move, and return an error to the MUA? Or am I on the wrong track altogether, and is there a better approach?
NB: While doing research I found that not all environment variables in RFC 6785 (https://www.rfc-editor.org/rfc/rfc6785.html#section-4) are implemented in Pigeonhole? I tried to access the 'imap.cause' and 'imap.mailbox' variables but they were empty, only the variables from RFC 5183 seem to be available. This is inline with the docs at https://github.com/dovecot/pigeonhole/blob/main/README, but not with https://github.com/dovecot/pigeonhole/blob/main/doc/plugins/imapsieve.txt and https://doc.dovecot.org/configuration_manual/sieve/plugins/imapsieve/, which both seems to imply that RFC 6785 is implemented?
Kind regards,
Tom