For anyone still following, a complete script below my signature.  No
need for temporary files, let sendmail(1) read the input and handle the
exit code.  Relies on bash support for arrays and POSIX "[[ ... ]]"
expressions, including pattern matching when the right argument of "="
or "==" is an unquoted literal string with shell globbing
metacharactesr.  The pattern is automatically anchored (must match the
whole left string, not just a substring).

-- 
    Viktor.  🇺🇦 Слава Україні!

#!/bin/bash

PATH=/usr/sbin:/usr/bin:/sbin:/bin

# At least one two arguments assumed, since guaranteed by pipe(8).
#
from="$1"; shift
cmd=( /usr/sbin/sendmail -G -i -f "$from" -- )
replace=( "[email protected]" )

for rcpt in "$@"
do
    if [[ "$from" = *@source.example &&
          "$rcpt" = *@destination.example ]]
    then
        cmd=( "${cmd[@]}" "${replace[@]}" )
        replace=() # Add replacement just once
    else
        cmd=( "${cmd[@]}" "$rcpt" )
    fi
done
exec "${cmd[@]}"
_______________________________________________
Postfix-users mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to