Solved: Sieve: reject certain mime-types and notify recipient

Ralf Becker rb at egroupware.org
Tue Jan 15 19:51:31 EET 2019


I case someone is interesed too, why it was not working:

Am 14.01.19 um 20:22 schrieb Ralf Becker:
> I have to reject office files for a certain domain plus notifying the
> original recipient about the rejection too.
>
> require ["fileinto","reject","body","enotify","variables"];
>
> if allof (address :contains ["To","TO","Cc","CC"] "@example.org", body
> :content  "application/msword" :contains "") {
>         set "to" "${1}";


The set does not work in allof with an other condition, so I use now:

if address :contains ["To","TO","Cc","CC"] "@example.org" {
    set "to" "${1}";
}


>         # :matches is used to get the value of the Subject header
>         if header :matches "Subject" "*" {
>                 set "subject" "${1}";
>         }
>         # :matches is used to get the value of the From header
>         if header :matches "From" "*" {
>                 set "from" "${1}";
>         }
>         notify :message "Rejected Office Datei ${from}: ${subject}" "${to}";


The notify needs as argument "mailto:${to}".


>         reject text:
> Aus Sicherheitsgründen nehmen wir keine Office Dateien mehr an. Bitte
> senden Sie uns ein PDF.
> .
> ;
> }
>
> A manual sievec call gives not error and if I remove everything but the
> reject line it works.
>
> Any ideas?


I used the sieve-test binary to figure out why it was not working.

My full script for checking mime-types as well as extensions and also
notifying the orginal recipient is now the following:

require [ "foreverypart", "mime",
"fileinto","reject","body","enotify","variables"];

if address :contains ["To","TO","Cc","CC"] "@example.org" {
        # :matches is used to get value of to, subject and from
        if address :matches ["To","TO","Cc","CC"] "*" {
                set "to" "${1}";
        }
        if header :matches "Subject" "*" {
                set "subject" "${1}";
        }
        if header :matches "From" "*" {
                set "from" "${1}";
        }

        # reject based on mime-type
        if allof(body :content  "application/msword" :contains "",
                 body :content  "application/msexcel" :contains "") {
                # send notification to original recipient
                notify :message "Rejected Office Datei von ${from}:
${subject}" "mailto:${to}";
                # send rejection message to sender
                reject text:
Aus Sicherheitsgründen nehmen wir keine Office Dateien mehr an. Bitte
senden Sie uns ein PDF.
--
Ralf Becker
EGroupware GmbH
.
;
                stop;
        }
        # reject based on extension of attachment
        foreverypart
        {
                if header :mime :param "filename" :matches
["Content-Type", "Content-Disposition"]
                        ["*.doc","*.xsl"]
                {
                        # send notification to original recipient
                        notify :message "Rejected
Dateierweiterung/Fileextension ${from}: ${subject}" "mailto:${to}";
                        # send rejection message to sender
                        reject text:
Aus Sicherheitsgründen nehmen wir kein Office Dateien mehr an. Bitte
senden Sie uns ein PDF.
--
Ralf Becker
EGroupware GmbH
.
;
                        stop;
                }
        }
}

Ralf

-- 
Ralf Becker
EGroupware GmbH [www.egroupware.org]
Handelsregister HRB Kaiserslautern 3587
Geschäftsführer Birgit und Ralf Becker
Leibnizstr. 17, 67663 Kaiserslautern, Germany
Telefon +49 631 31657-0

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: OpenPGP digital signature
URL: <https://dovecot.org/pipermail/dovecot/attachments/20190115/bf4ed708/attachment.sig>


More information about the dovecot mailing list