> On Dec 22, 2016, at 3:51 AM, Stéphane MERLE <stephane.me...@distrigame.com> 
> wrote:
> 
> First, I save the message in the file descriptor 3
> 
>    msg=$(mktemp /tmp/msg.XXXXXX) || exit 75
>    cat > $msg || { rm $msg; exit 75; }
>    exec 3< $msg || { rm $msg; exit 75; }
>    rm $msg
> 
> then I use it by rewinding it :
> 
>       perl -e 'open IN, "<&", 3; seek(IN, 0, 0);'

I meant to use "sysseek" there, not "seek" by the way, though
in practice it seems that "seek" has the same effect, the former
is more correct.

> 
> is there a way to rewind without using perl ?

If you need to avoid tools like Perl that expose system call
interfaces, just go with the "trap" approach and don't "pre-unlink"
the message file.

        msg=$(mktemp /tmp/msg.XXXXXX)
        trap "rm -f $msg" EXIT
        trap "rm -f $msg; exit 75" HUP INT TERM
        cat > $msg

        ...
        if grep "..." $msg >/dev/null; then
            set -- "$@" "$additional_recipient"
        fi
        ...

        # Final command.  Shell will remove the temp file and exit with
        # Sendmail's exit code.
        /usr/sbin/sendmail "$@"

-- 
        Viktor.

Reply via email to