Hi Viktor,

Le 21/12/2016 à 15:02, Viktor Dukhovni a écrit :
On Wed, Dec 21, 2016 at 10:42:37AM +0100, Stéphane MERLE wrote:

when I send the mail content via sendmail :

sendmail -t $nouveau_destinataire <<< $lemail
This is wrong on many levels.

     1. It revives *header* recipients, possibly creating mail
        loops and/or double deliveries.  NEVER do that.

     2. It forgets to use "-i" so that leading "." characters
        in the body are handled correctly.

     3. I has a mysterious "<<<", instead of "<".

     4. You don't mention what "$lemail" is.

The solution is to pass the original envelope
recipients to the script via a final ${recipient}
parameter to pipe(8) and extend that list by adding
another argument (one per additional recipient):

     # No need to buffer the message if you're not
     # modifying it!  Instead, just let sendmail(1)
     # below read the input stream directly.
     msg=$(mktemp /var/tmp/msg.XXXXXX) && cat > "$msg" || exit 75

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

This assumes that pipe(8) has argv set correctly:

     pipe unix ... pipe
        user=nobody null_sender= flags=
        argv=/script/path -f $sender -- $recipient

(don't remove the space between "-f" and "$sender"!)

outch : I do not have -f in the call to my script argv and I don't see much about it in the "man pipe 8" :
filterdyn unix -        n       n       -  -    pipe
flags=DRhu user=vmail argv=/usr/sbin/filter_dyn.sh ${sender} ${recipient} ${queue_id}

but the http call to my rest api is working fine with that, I am scared to kill it ...

at the top of my bash script I got :

lemail=$(cat)

so the variable $lemail  got the feed from postfix, this is why I use :

sendmail $destinataire <<< "$lemail"
(I did try with " and without).
and as the mail is not a file, I was especting not to write a temporary file as you seem to do with :

msg=$(mktemp /var/tmp/msg.XXXXXX) && cat > "$msg" || exit 75

as for :

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

will it work without the "-f" ?


Sorry to have you loose your time for me !
Stéphane





Reply via email to