Re: stripping the signature from an email

[email protected] (Dale R. Worley) Wed, 01 Jun 2016 11:22:19 -0400
Newsgroups gmane.mail.procmail
Message-ID <[email protected]>
"@lbutlr" <[email protected]> writes:
> I have the following:
>
> :0
> { 
>   MSGTEXT=`/usr/local/bin/formail -I ""`
>   LOG="1 MSGTEXT=${MSGTEXT}${NL}"
>   MSGTEXT=`echo $MSGTEXT | sed '/^-- $/,$d'`
>   LOG="${NL}2 MSGTEXT=${MSGTEXT}${NL}"
> ...
>
> Which results in:
>
> 1 MSGTEXT=
> one two three four five
> Six seven eight
>
> -- 
> It's Tchaikovsky's 'Another One Bites the Dust'," said Crowley, closing
> his eyes as they went through Slough.
>
> 2 MSGTEXT=one two three four five Six seven eight -- It's Tchaikovsky's 'Another One Bites the Dust'," said Crowley, closing his eyes as they went through Slough.
>
> Shouldn't the sed strip the signature delimiter and the signature text?
>
> I assume that the echo is condensing the MSGTEXT without passing the newlines?

When you write

>   MSGTEXT=`echo $MSGTEXT | sed '/^-- $/,$d'`

first the shell needs to construct the "echo" command.  It does that by
substituting the contents of $MSGTEXT and then processing the whitespace
into word separations.  So of MSGTEXT is "a b\nd e", the generated
command is

    echo a b d e

"echo" sees 4 arguments, and outputs them with spaces between:

    a b d e

That line is sent to "sed", etc.

The usual way to defeat this is

>   MSGTEXT=`echo "$MSGTEXT" | sed '/^-- $/,$d'`

but a better way is your second code:

>   MSGTEXT=`/usr/local/bin/formail -I "" | sed '/^-- $/,$d'`

which avoids putting the original message into MSGTEXT.

Dale