mailcow / mailcow-dockerized

mailcow: dockerized - 🐮 + 🐋 = 💕
https://mailcow.email
GNU General Public License v3.0
8.34k stars 1.13k forks source link

Notify error in sieve #5246

Closed baimard closed 11 months ago

baimard commented 1 year ago

Contribution guidelines

I've found a bug and checked that ...

Description

On mailbox filter configuration. I try to add à new filter with a notify command https://www.rfc-editor.org/rfc/rfc5435.html#page-3

But mailcow sail that the command not exist.

Logs:

mailcowdockerized-php-fpm-mailcow-1    | 172.22.1.13 -  24/May/2023:23:47:01 +0200 "GET /inc/ajax/sieve_validation.php" 200
mailcowdockerized-nginx-mailcow-1      | 192.168.4.10 - - [24/May/2023:23:47:01 +0200] "GET /inc/ajax/sieve_validation.php?script=if%20anyof%20(header%20%3Acontains%20%22to%22%20%22test%40test.fr%22%2C%20header%20%3Acontains%20%22cc%22%20%22test%40test.fr%22%2C%20header%20%3Acontains%20%22received%22%20%22for%20%3Ctest%40test.fr%3E%22)%0A%7B%0A%20%20%20%20%20%20%20%20fileinto%20%22Public.famille%22%3B%0A%7D HTTP/2.0" 200 76 "https://mail.cybercorp.fr/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
mailcowdockerized-watchdog-mailcow-1   | Wed May 24 23:47:03 CEST 2023 Olefy health level: 100% (5/5), health trend: 0
mailcowdockerized-solr-mailcow-1       | 2023-05-24 21:47:04.350 INFO  (commitScheduler-13-thread-1) [   ] o.a.s.u.DirectUpdateHandler2 start commit{,optimize=false,openSearcher=false,waitSearcher=true,expungeDeletes=false,softCommit=false,prepareCommit=false}
mailcowdockerized-solr-mailcow-1       | 2023-05-24 21:47:04.350 INFO  (commitScheduler-13-thread-1) [   ] o.a.s.u.SolrIndexWriter Calling setCommitData with IW:org.apache.solr.update.SolrIndexWriter@6f04a8f6 commitCommandVersion:0

Steps to reproduce:

Mailcow as admin
go to email configuraitn
go to filter
try to add this :

if anyof (header :contains "to" "test@test.fr", header :contains "cc" "test@test.fr", header :contains "received" "for <test@test.fr>")
{
            notify :importance "1" :message "Nouveau mail dans famille!" "mailto:anothertestmail@test.fr";

}

test is not my real domain, please provide your


### Which branch are you using?

master

### Operating System:

Ubuntu 22.04

### Server/VM specifications:

1cpu 1Go ram

### Is Apparmor, SELinux or similar active?

no

### Virtualization technology:

proxmox <3

### Docker version:

Docker version 23.0.6, build ef23cbc

### docker-compose version or docker compose version:

Docker Compose version v2.17.3

### mailcow version:

2023-04b

### Reverse proxy:

natif mailcow (hop nginx ?)

### Logs of git diff:

```plain text
diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md
old mode 100644
new mode 100755
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
old mode 100644
new mode 100755
diff --git a/LICENSE b/LICENSE
old mode 100644
new mode 100755
diff --git a/README.md b/README.md
old mode 100644
new mode 100755
diff --git a/SECURITY.md b/SECURITY.md
old mode 100644

Logs of iptables -L -vn:

no iptables

Logs of ip6tables -L -vn:

no v6ip

Logs of iptables -L -vn -t nat:

No

Logs of ip6tables -L -vn -t nat:

No

DNS check:

No
tomudding commented 1 year ago

Mailcow does not support the syntax of enotify nor does it have a module enotify. It does provide notify as a module instead (don't forget to import the module, that part appears to be missing from your code) and the syntax for the notify command in that module can be found at https://github.com/mailcow/mailcow-dockerized/blob/master/data/web/inc/lib/sieve/extensions/notify.xml and it looks like:

notify [:method "method"] [:id "message-id"] [:(low|normal|high)] [:message "message"]

So an example would be:

require ["notify"]

notify :low :message "Some message!";
baimard commented 1 year ago

If I want to notify on an email on an other domain ?

Look that don't do the trick :(

tomudding commented 1 year ago

If I want to notify on an email on an other domain ?

Look that don't do the trick :(

I believe you have to use the :method parameter for that, which in the case of Mailcow actually requires the :method part. I have not tested it, but I think it will look like this:

require ["notify"]

notify :low :message "Some message!" :method "mailto:example@example.com";
baimard commented 1 year ago

This syntax looks good :

require "notify";
notify :normal :message "test" :method "mailto:testd@test.world";

But dovecot logs : image

Any idea ?

tomudding commented 1 year ago

I found the RFC draft on which the Mailcow notify is still based, see this. Based on that the syntax would be:

require "notify";

notify :normal :message "test" :method "mailto" :options "testd@test.world";

The problem here is that according to the spec within Mailcow, which I linked earlier, the :options argument is not valid. So you will get a validation error when you try to use the example given above. There is no way around that without modifying part of Mailcow.

The Mailcow team can fix this by adding the :options argument to the definition of notify or actually upgrading the sieve modules and commands (then you would be able to use enotify with the modern notify syntax as defined in RFC 5435).

Personally, the latter option would be the best solution but seeing that almost all of the sieve modules have not been touched in 6 years (and notify was deprecated in favour of enotify at least 13 years ago) that is going to take some time.

tomudding commented 1 year ago

I think the following modification would be required in the notify definition:

<parameter type="tag" name="options" occurrence="optional" regex="options">
     <parameter type="stringlist" name="option strings" />
</parameter>

However, I am currently unable to test this.

baimard commented 1 year ago

I'm gone test, thank you for your very good answer.

baimard commented 1 year ago

that work i'm gone do a pull request, thank you.

Finaly in data/web/inc/lib/sieve/extensions/notify.xml :

<?xml version='1.0' standalone='yes'?>

<extension name="notify">

    <command name="notify">
        <parameter type="tag" name="method" regex="method" occurrence="optional">
            <parameter type="string" name="method-name" />
        </parameter>

        <parameter type="tag" name="id" regex="id" occurrence="optional">
            <parameter type="string" name="message-id" />
        </parameter>

        <parameter type="tag" name="priority" regex="(low|normal|high)" occurrence="optional" />

        <parameter type="tag" name="message" regex="message" occurrence="optional">
            <parameter type="string" name="message-text" />
        </parameter>

        <parameter type="tag" name="options" regex="options" occurrence="optional">
            <parameter type="stringlist" name="option-strings" />
        </parameter>
    </command>

    <command name="denotify">
        <parameter type="matchtype" occurrence="optional">
            <parameter type="string" name="message-id" />
        </parameter>

        <parameter type="tag" name="priority" regex="(low|normal|high)" occurrence="optional" />
    </command>

</extension>

for notification : go to filter in admin panel

require "notify";
notify :normal :message "test" :method "mailto" :options ["test@test.world"];
milkmaker commented 12 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.