diff --git a/lib/Service/OutOfOffice/OutOfOfficeParser.php b/lib/Service/OutOfOffice/OutOfOfficeParser.php index 9148e1a179..cf202261c1 100644 --- a/lib/Service/OutOfOffice/OutOfOfficeParser.php +++ b/lib/Service/OutOfOffice/OutOfOfficeParser.php @@ -115,11 +115,13 @@ public function buildSieveScript( $formattedStart = $this->formatDateForSieve($state->getStart()); if ($state->getEnd() !== null) { $formattedEnd = $this->formatDateForSieve($state->getEnd()); - $condition = "allof(currentdate :value \"ge\" \"iso8601\" \"$formattedStart\", currentdate :value \"le\" \"iso8601\" \"$formattedEnd\")"; + $vacationCondition = "allof(currentdate :value \"ge\" \"iso8601\" \"$formattedStart\", currentdate :value \"le\" \"iso8601\" \"$formattedEnd\")"; } else { - $condition = "currentdate :value \"ge\" \"iso8601\" \"$formattedStart\""; + $vacationCondition = "currentdate :value \"ge\" \"iso8601\" \"$formattedStart\""; } + $automaticMailCondition = 'anyof(exists "List-Id", exists "List-Unsubscribe")'; + $escapedSubject = SieveUtils::escapeString($state->getSubject()); $vacation = [ 'vacation', @@ -166,8 +168,10 @@ public function buildSieveScript( $vacationSection = array_merge($vacationSection, $subjectSection); } $vacationSection = array_merge($vacationSection, [ - "if $condition {", - "\t$vacationCommand;", + "if $vacationCondition {", + "\tif not $automaticMailCondition {", + "\t\t$vacationCommand;", + "\t}", '}', self::SEPARATOR, ]); diff --git a/tests/data/mail-filter/parser3.sieve b/tests/data/mail-filter/parser3.sieve index 2d4aa8cfcf..72436eaf43 100644 --- a/tests/data/mail-filter/parser3.sieve +++ b/tests/data/mail-filter/parser3.sieve @@ -16,6 +16,8 @@ if allof( ### Nextcloud Mail: Vacation Responder ### DON'T EDIT ### # DATA: {"version":1,"enabled":true,"start":"2022-09-02T00:00:00+01:00","end":"2022-09-08T23:59:00+01:00","subject":"On vacation","message":"I'm on vacation."} if allof(currentdate :value "ge" "iso8601" "2022-09-01T23:00:00Z", currentdate :value "le" "iso8601" "2022-09-08T22:59:00Z") { - vacation :days 4 :subject "On vacation" :addresses ["Test Test ", "Test Alias "] "I'm on vacation."; + if not anyof(exists "List-Id", exists "List-Unsubscribe") { + vacation :days 4 :subject "On vacation" :addresses ["Test Test ", "Test Alias "] "I'm on vacation."; + } } ### Nextcloud Mail: Vacation Responder ### DON'T EDIT ### diff --git a/tests/data/mail-filter/parser3_untouched.sieve b/tests/data/mail-filter/parser3_untouched.sieve index 2d4aa8cfcf..72436eaf43 100644 --- a/tests/data/mail-filter/parser3_untouched.sieve +++ b/tests/data/mail-filter/parser3_untouched.sieve @@ -16,6 +16,8 @@ if allof( ### Nextcloud Mail: Vacation Responder ### DON'T EDIT ### # DATA: {"version":1,"enabled":true,"start":"2022-09-02T00:00:00+01:00","end":"2022-09-08T23:59:00+01:00","subject":"On vacation","message":"I'm on vacation."} if allof(currentdate :value "ge" "iso8601" "2022-09-01T23:00:00Z", currentdate :value "le" "iso8601" "2022-09-08T22:59:00Z") { - vacation :days 4 :subject "On vacation" :addresses ["Test Test ", "Test Alias "] "I'm on vacation."; + if not anyof(exists "List-Id", exists "List-Unsubscribe") { + vacation :days 4 :subject "On vacation" :addresses ["Test Test ", "Test Alias "] "I'm on vacation."; + } } ### Nextcloud Mail: Vacation Responder ### DON'T EDIT ### diff --git a/tests/data/mail-filter/parser4.sieve b/tests/data/mail-filter/parser4.sieve index 9a55e7cdd7..27089ec26b 100644 --- a/tests/data/mail-filter/parser4.sieve +++ b/tests/data/mail-filter/parser4.sieve @@ -26,6 +26,8 @@ if address :is :all "From" ["marketing@mail.internal"] { ### Nextcloud Mail: Vacation Responder ### DON'T EDIT ### # DATA: {"version":1,"enabled":true,"start":"2024-10-08T22:00:00+00:00","subject":"Thanks for your message!","message":"I'm not here, please try again later.\u00a0"} if currentdate :value "ge" "iso8601" "2024-10-08T22:00:00Z" { - vacation :days 4 :subject "Thanks for your message!" :addresses ["alice@mail.internal"] "I'm not here, please try again later. "; + if not anyof(exists "List-Id", exists "List-Unsubscribe") { + vacation :days 4 :subject "Thanks for your message!" :addresses ["alice@mail.internal"] "I'm not here, please try again later. "; + } } ### Nextcloud Mail: Vacation Responder ### DON'T EDIT ### diff --git a/tests/data/mail-filter/parser4_untouched.sieve b/tests/data/mail-filter/parser4_untouched.sieve index 7bb0f893c5..1e7ad1e131 100644 --- a/tests/data/mail-filter/parser4_untouched.sieve +++ b/tests/data/mail-filter/parser4_untouched.sieve @@ -16,6 +16,8 @@ if allof( ### Nextcloud Mail: Vacation Responder ### DON'T EDIT ### # DATA: {"version":1,"enabled":true,"start":"2024-10-08T22:00:00+00:00","subject":"Thanks for your message!","message":"I'm not here, please try again later.\u00a0"} if currentdate :value "ge" "iso8601" "2024-10-08T22:00:00Z" { - vacation :days 4 :subject "Thanks for your message!" :addresses ["alice@mail.internal"] "I'm not here, please try again later. "; + if not anyof(exists "List-Id", exists "List-Unsubscribe") { + vacation :days 4 :subject "Thanks for your message!" :addresses ["alice@mail.internal"] "I'm not here, please try again later. "; + } } ### Nextcloud Mail: Vacation Responder ### DON'T EDIT ### diff --git a/tests/data/mail-filter/service1.sieve b/tests/data/mail-filter/service1.sieve index 7bb0f893c5..1e7ad1e131 100644 --- a/tests/data/mail-filter/service1.sieve +++ b/tests/data/mail-filter/service1.sieve @@ -16,6 +16,8 @@ if allof( ### Nextcloud Mail: Vacation Responder ### DON'T EDIT ### # DATA: {"version":1,"enabled":true,"start":"2024-10-08T22:00:00+00:00","subject":"Thanks for your message!","message":"I'm not here, please try again later.\u00a0"} if currentdate :value "ge" "iso8601" "2024-10-08T22:00:00Z" { - vacation :days 4 :subject "Thanks for your message!" :addresses ["alice@mail.internal"] "I'm not here, please try again later. "; + if not anyof(exists "List-Id", exists "List-Unsubscribe") { + vacation :days 4 :subject "Thanks for your message!" :addresses ["alice@mail.internal"] "I'm not here, please try again later. "; + } } ### Nextcloud Mail: Vacation Responder ### DON'T EDIT ### diff --git a/tests/data/mail-filter/service1_new.sieve b/tests/data/mail-filter/service1_new.sieve index 9a55e7cdd7..27089ec26b 100644 --- a/tests/data/mail-filter/service1_new.sieve +++ b/tests/data/mail-filter/service1_new.sieve @@ -26,6 +26,8 @@ if address :is :all "From" ["marketing@mail.internal"] { ### Nextcloud Mail: Vacation Responder ### DON'T EDIT ### # DATA: {"version":1,"enabled":true,"start":"2024-10-08T22:00:00+00:00","subject":"Thanks for your message!","message":"I'm not here, please try again later.\u00a0"} if currentdate :value "ge" "iso8601" "2024-10-08T22:00:00Z" { - vacation :days 4 :subject "Thanks for your message!" :addresses ["alice@mail.internal"] "I'm not here, please try again later. "; + if not anyof(exists "List-Id", exists "List-Unsubscribe") { + vacation :days 4 :subject "Thanks for your message!" :addresses ["alice@mail.internal"] "I'm not here, please try again later. "; + } } ### Nextcloud Mail: Vacation Responder ### DON'T EDIT ### diff --git a/tests/data/mail-filter/service2.sieve b/tests/data/mail-filter/service2.sieve index d605d1e4ea..cd2153b7ee 100644 --- a/tests/data/mail-filter/service2.sieve +++ b/tests/data/mail-filter/service2.sieve @@ -30,6 +30,8 @@ if header :contains "Subject" ["World"] { ### Nextcloud Mail: Vacation Responder ### DON'T EDIT ### # DATA: {"version":1,"enabled":true,"start":"2024-10-08T22:00:00+00:00","subject":"Thanks for your message!","message":"I'm not here, please try again later.\u00a0"} if currentdate :value "ge" "iso8601" "2024-10-08T22:00:00Z" { - vacation :days 4 :subject "Thanks for your message!" :addresses ["alice@mail.internal"] "I'm not here, please try again later. "; + if not anyof(exists "List-Id", exists "List-Unsubscribe") { + vacation :days 4 :subject "Thanks for your message!" :addresses ["alice@mail.internal"] "I'm not here, please try again later. "; + } } ### Nextcloud Mail: Vacation Responder ### DON'T EDIT ### diff --git a/tests/data/mail-filter/service2_new.sieve b/tests/data/mail-filter/service2_new.sieve index 3b9e21eee8..348af990f7 100644 --- a/tests/data/mail-filter/service2_new.sieve +++ b/tests/data/mail-filter/service2_new.sieve @@ -26,6 +26,8 @@ if header :contains "Subject" ["Hello"] { ### Nextcloud Mail: Vacation Responder ### DON'T EDIT ### # DATA: {"version":1,"enabled":true,"start":"2024-10-08T22:00:00+00:00","subject":"Thanks for your message!","message":"I'm not here, please try again later.\u00a0"} if currentdate :value "ge" "iso8601" "2024-10-08T22:00:00Z" { - vacation :days 4 :subject "Thanks for your message!" :addresses ["alice@mail.internal"] "I'm not here, please try again later. "; + if not anyof(exists "List-Id", exists "List-Unsubscribe") { + vacation :days 4 :subject "Thanks for your message!" :addresses ["alice@mail.internal"] "I'm not here, please try again later. "; + } } ### Nextcloud Mail: Vacation Responder ### DON'T EDIT ### diff --git a/tests/data/sieve-vacation-on-no-end-date.sieve b/tests/data/sieve-vacation-on-no-end-date.sieve index 5c43426474..ceb93e983f 100644 --- a/tests/data/sieve-vacation-on-no-end-date.sieve +++ b/tests/data/sieve-vacation-on-no-end-date.sieve @@ -13,6 +13,8 @@ if address "From" "marketing@company.org" { ### Nextcloud Mail: Vacation Responder ### DON'T EDIT ### # DATA: {"version":1,"enabled":true,"start":"2022-09-02T00:00:00+01:00","subject":"On vacation","message":"I'm on vacation."} if currentdate :value "ge" "iso8601" "2022-09-01T23:00:00Z" { - vacation :days 4 :subject "On vacation" :addresses ["Test Test ", "Test Alias "] "I'm on vacation."; + if not anyof(exists "List-Id", exists "List-Unsubscribe") { + vacation :days 4 :subject "On vacation" :addresses ["Test Test ", "Test Alias "] "I'm on vacation."; + } } ### Nextcloud Mail: Vacation Responder ### DON'T EDIT ### \ No newline at end of file diff --git a/tests/data/sieve-vacation-on-no-tz.sieve b/tests/data/sieve-vacation-on-no-tz.sieve index e5e47f5d65..a35b43cf8c 100644 --- a/tests/data/sieve-vacation-on-no-tz.sieve +++ b/tests/data/sieve-vacation-on-no-tz.sieve @@ -13,6 +13,8 @@ if address "From" "marketing@company.org" { ### Nextcloud Mail: Vacation Responder ### DON'T EDIT ### # DATA: {"version":1,"enabled":true,"start":"2022-09-02","end":"2022-09-08","subject":"On vacation","message":"I'm on vacation."} if allof(currentdate :value "ge" "iso8601" "2022-09-01", currentdate :value "le" "iso8601" "2022-09-08") { - vacation :days 4 :subject "On vacation" :addresses ["Test Test ", "Test Alias "] "I'm on vacation."; + if not anyof(exists "List-Id", exists "List-Unsubscribe") { + vacation :days 4 :subject "On vacation" :addresses ["Test Test ", "Test Alias "] "I'm on vacation."; + } } ### Nextcloud Mail: Vacation Responder ### DON'T EDIT ### \ No newline at end of file diff --git a/tests/data/sieve-vacation-on-special-chars-message.sieve b/tests/data/sieve-vacation-on-special-chars-message.sieve index 8131e1a3b4..455b6d1264 100644 --- a/tests/data/sieve-vacation-on-special-chars-message.sieve +++ b/tests/data/sieve-vacation-on-special-chars-message.sieve @@ -13,8 +13,10 @@ if address "From" "marketing@company.org" { ### Nextcloud Mail: Vacation Responder ### DON'T EDIT ### # DATA: {"version":1,"enabled":true,"start":"2022-09-02T00:00:00+01:00","subject":"On vacation","message":"I'm on vacation.\r\n\"Hello, World!\"\r\n\\ escaped backslash"} if currentdate :value "ge" "iso8601" "2022-09-01T23:00:00Z" { - vacation :days 4 :subject "On vacation" :addresses ["Test Test ", "Test Alias "] "I'm on vacation. + if not anyof(exists "List-Id", exists "List-Unsubscribe") { + vacation :days 4 :subject "On vacation" :addresses ["Test Test ", "Test Alias "] "I'm on vacation. \"Hello, World!\" \\ escaped backslash"; + } } ### Nextcloud Mail: Vacation Responder ### DON'T EDIT ### \ No newline at end of file diff --git a/tests/data/sieve-vacation-on-special-chars-subject.sieve b/tests/data/sieve-vacation-on-special-chars-subject.sieve index 61791bbbbf..686948c51d 100644 --- a/tests/data/sieve-vacation-on-special-chars-subject.sieve +++ b/tests/data/sieve-vacation-on-special-chars-subject.sieve @@ -13,6 +13,8 @@ if address "From" "marketing@company.org" { ### Nextcloud Mail: Vacation Responder ### DON'T EDIT ### # DATA: {"version":1,"enabled":true,"start":"2022-09-02T00:00:00+01:00","subject":"On vacation, \"Hello, World!\", \\ escaped backslash","message":"I'm on vacation."} if currentdate :value "ge" "iso8601" "2022-09-01T23:00:00Z" { - vacation :days 4 :subject "On vacation, \"Hello, World!\", \\ escaped backslash" :addresses ["Test Test ", "Test Alias "] "I'm on vacation."; + if not anyof(exists "List-Id", exists "List-Unsubscribe") { + vacation :days 4 :subject "On vacation, \"Hello, World!\", \\ escaped backslash" :addresses ["Test Test ", "Test Alias "] "I'm on vacation."; + } } ### Nextcloud Mail: Vacation Responder ### DON'T EDIT ### \ No newline at end of file diff --git a/tests/data/sieve-vacation-on-subject-placeholder.sieve b/tests/data/sieve-vacation-on-subject-placeholder.sieve index 66b33b72bd..938ce0ee3b 100644 --- a/tests/data/sieve-vacation-on-subject-placeholder.sieve +++ b/tests/data/sieve-vacation-on-subject-placeholder.sieve @@ -18,6 +18,8 @@ if header :matches "subject" "*" { set "subject" "${1}"; } if allof(currentdate :value "ge" "iso8601" "2022-09-01T23:00:00Z", currentdate :value "le" "iso8601" "2022-09-08T22:59:00Z") { - vacation :days 4 :subject "Re: ${subject}" :addresses ["Test Test ", "Test Alias "] "I'm on vacation."; + if not anyof(exists "List-Id", exists "List-Unsubscribe") { + vacation :days 4 :subject "Re: ${subject}" :addresses ["Test Test ", "Test Alias "] "I'm on vacation."; + } } ### Nextcloud Mail: Vacation Responder ### DON'T EDIT ### \ No newline at end of file diff --git a/tests/data/sieve-vacation-on.sieve b/tests/data/sieve-vacation-on.sieve index 55e8adde36..fe17540616 100644 --- a/tests/data/sieve-vacation-on.sieve +++ b/tests/data/sieve-vacation-on.sieve @@ -13,6 +13,8 @@ if address "From" "marketing@company.org" { ### Nextcloud Mail: Vacation Responder ### DON'T EDIT ### # DATA: {"version":1,"enabled":true,"start":"2022-09-02T00:00:00+01:00","end":"2022-09-08T23:59:00+01:00","subject":"On vacation","message":"I'm on vacation."} if allof(currentdate :value "ge" "iso8601" "2022-09-01T23:00:00Z", currentdate :value "le" "iso8601" "2022-09-08T22:59:00Z") { - vacation :days 4 :subject "On vacation" :addresses ["Test Test ", "Test Alias "] "I'm on vacation."; + if not anyof(exists "List-Id", exists "List-Unsubscribe") { + vacation :days 4 :subject "On vacation" :addresses ["Test Test ", "Test Alias "] "I'm on vacation."; + } } ### Nextcloud Mail: Vacation Responder ### DON'T EDIT ### \ No newline at end of file