Hi Wietse,

Le 21/12/2016 à 16:46, Wietse Venema a écrit :
St?phane MERLE:
at the top of my bash script I got :

lemail=$(cat)
Aaeeiigghh. Why not let the sendmail command read stdin.

see more explanations below

sendmail -i "$@" "$additional_recipient" < "$msg"

will it work without the "-f" ?
If you invoke the script via

     pipe ... argv=/path/to/script -f ${sender} -- ${recipient}

Then the -f will already be part of the "$@", therefore

     sendmail -i "$@" "$additional_recipient"

would be sufficient to process the message from STDIN.
No tempfile needed. No need to store the message into a variable.

If you determine $additional_recipient based on the content of
the message, you need to be very careful so as not to open up
a gaping security hole.

no the recipient is not part of the message but depend of it as it could be for 2 differents services.

seems that I am not explaining enough ...

after

lemail=$(cat)

I do filtering

if [[
        $(echo "$lemail" | grep -Ei "(operation numero|indice de 
frequence|signaletique)" | wc -l) -ne 0
]]
then
        atraiter
fi


and

atraiter()
{
        echo "[$queue_id] appel api"
echo "curl -s -X POST -F \"queue_id=$queue_id\" -F \"sujet=$lesujet\" -F \"mailfrom=$lefrom\" -F \"mailto=$leto\" -F \"replyto=$lereplyto\" -F \"body=lemail\" \"$API_PATH\"" curl -s -X POST -F "queue_id=$queue_id" -F "sujet=$lesujet" -F "mailfrom=$lefrom" -F "mailto=$leto" -F "replyto=$lereplyto" -F "body=$lemail" "$API_PATH"
        if [ "0" -ne "$?" ]
        then
            echo "[$queue_id] ERREUR CURL : $?"
            return 75
        fi
        echo
        echo "[$queue_id] CURL OK"
        return 0
}

so I send the mail to my http api.

some other filter trigger the renvoi function

if [[
    $( echo "$leto" | grep -Ei "^To:.*(contact@)" | wc -l ) -ne 0
]]
then

        renvoi "$CRM"
        exit $?
fi

with :

renvoi()
{
        local destinataire=$1
lemailnouveau=$( sed 's/\ To:\ [^ ]*/\ To:\ '$destinataire'\ /' <<< $lemail )
        sendmail $destinataire <<<"$lemailnouveau"
        return $?
}


so I do need to process some filtering before pushing it to my rest api OR forwarding it to one or the other email address

I hope that it's understandable and apologize if not, my english is better spoken ...

Stéphane



        Wietse



Reply via email to