<<< Date Index >>>     <<< Thread Index >>>

Re: How do I filter a message?



On 2005-03-29, Toby <tobia.conforto@xxxxxxxx> wrote:
> Dear Mutt users,
> 
>       I cannot find a way to filter a message through an external
> program when I press a macro key on it in the index view (or such.)
> I might want to filter the Subject line or another header through sed,
> or possibly pass the message to a script for complex operations.
> 
> I found the shell-escape (§ 6.4.1) and pipe-message (§ 6.4.2) commands
> in the documentation, but none of them seems to do what I need.
> 
> shell-escape apparently doesn't have a way to pass information about the
> currently selected message to the spawned program.
> 
> pipe-message on the other hand doesn't seem to be made for filtering
> messages, because it doesn't expect a filtered message in return to
> replace the original message with.

The only way I know of to do this is to edit the message.  Here's an 
example from my muttrc:

    macro index ,E      ':set editor=mutt_expires_editor<Return><edit>:set 
editor=vim<Return>' "set Expires: header"
    macro pager ,E      ':set editor=mutt_expires_editor<Return><edit>:set 
editor=vim<Return><next-entry><clear-flag>N' "set Expires: header"

This doesn't behave exactly as a pipe, since the editor program must 
edit the file it's given as an argument rather than filtering stdin 
to stdout, but wrapping your filter program in a script can take 
care of that.  For example, from the 'mutt_expires_editor' script:

    formail -i "Expires: $rfc822_date" < $1 > $tmp_file
    mv $tmp_file $1

HTH,
Gary

-- 
Gary Johnson                               | Agilent Technologies
garyjohn@xxxxxxxxxxxxxxx                   | Wireless Division
http://www.spocom.com/users/gjohnson/mutt/ | Spokane, Washington, USA