emailsieve-language

Filtering mail through Sieve/Pigeonhole function


Trying to filter mails through a Sieve function.

I would like to fetch an e-mail address indicated inside the body of the message, and not in the header. This address is (like the one in the header) after a From: field. After that, a copy of the email should be sent to this address. Messages filtered must also have Returned mail inside their subject.

This is my code, but not working...

        require ["body","copy","variables"];

        if header :contains "Subject" "Returned mail"
            {
            if body :content "text" :matches "From: *"
                {
                redirect :copy "${1}";
                }
            }

Can you please help me to fix that code ? Thank's !!


Solution

  • Switch back to good old procmail

    Procmail does support matching within the message body like this:

    :0H
    * ^Subject: .*Returned mail
    {
     :0B
     * ^From: \/.+@.+
     {
      ADDR=$MATCH
      :0 c
      * ADDR ?? ^[a-z0-9_-+.]+@[a-z0-9-+.]+$
      | $ADDR
     }
    }
    

    This covers everything after, in the line beginning with "From: ", in the message body.

    :0B means the next matching has to be done on the message body

    \/ in the expression starts the record to $MATCH (build-in variable)

    The match is stored in the Procmail variable $ADDR wich then is permanently accessible within the furturer procmail script execution. In the subblock it delivers (:0 carbon copys) the message to the newly matched destination address. But note that at this point it is not safely checked if it really is an email address. This leaves also maybe a vulnurability for a remote code execution.

    There MUST BE also any X-Loop protection techniq applied manually wich is not covered by this example