From 96a460c2faa97e0776f563ceb81ffdded8a91913 Mon Sep 17 00:00:00 2001
From: andryyy <andre.peters@debinux.de>
Date: Wed, 28 Jul 2021 21:44:06 +0200
Subject: [PATCH] [Dovecot] Change sieve scripts for DeltaChat

---
 data/conf/dovecot/global_sieve_before | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/data/conf/dovecot/global_sieve_before b/data/conf/dovecot/global_sieve_before
index a71419d5..003fc27f 100644
--- a/data/conf/dovecot/global_sieve_before
+++ b/data/conf/dovecot/global_sieve_before
@@ -1,10 +1,10 @@
 # global_sieve_before script
 # global_sieve_before -> user sieve_before (mailcow UI) -> user sieve_after (mailcow UI) -> global_sieve_after
 
-require "fileinto";
-require "mailbox";
+require ["imap4flags", "mailbox", "fileinto"];
 
-if header :contains ["Chat-Version"] [""] {
+if allof(header :contains ["Chat-Version"] [""],
+  header :contains ["Auto-Submitted"] ["auto-replied"]) {
   if mailboxexists "DeltaChat" {
     fileinto "DeltaChat";
   } else {
@@ -12,3 +12,9 @@ if header :contains ["Chat-Version"] [""] {
   }
   stop;
 }
+
+if allof(header :contains ["Chat-Version"] [""],
+  header :contains ["Autocrypt"] [""]) {
+  setflag "\\seen";
+  stop;
+}