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

Re: Display Filters



On 2006-06-30, Jerry VB <jevb+mutt@xxxxxxxxxxxx> wrote:
> On Thu, Jun 29, 2006 at 06:58:50PM -0700, Gary Johnson wrote:
> > 
> > ----------------------------- cut here -----------------------------
> > 
> > Here's the more conservative of my "[-- .* --]" filters:
> > 
> > sed -e '
> >     /^\[-- Autoview using .* --]$/d
> >         /^^[][0-9;]*^G\[-- Autoview using .* --]$/d
> >     /^\[-- Attachment .* --]$/d
> >         /^^[][0-9;]*^G\[-- Attachment .* --]$/d
> >     /^\[-- Type: .* --]$/d
> >         /^^[][0-9;]*^G\[-- Type: .* --]$/d
> > '
> > 
> 
> Okay, I'll admit it, I can't figure out how to use this script. Gary, do I
> make an excutable script and then source it from .muttrc? I tried that using
> just the "Attachment" line, and Mutt keeps telling me there are errors in the
> script.
> 
> Here's my muttrc line:
> 
> message-hook . "source ~/.mutt/scripts/strip"
> 
> 
> Here's my script:
> 
> sed -e "/^\[-- Attachment .* --].*$/d"
> 
> 
> I named the script "strip" and put it in ~/.mutt/scripts".

That list of scripts and snippets was intended more for those who 
already knew how to use the display_filter and who were looking for 
new ways to use it.  I'll explain here more about how I control the 
display_filter setting itself.

First of all, from the mutt manual:

  6.3.35.  display_filter

    Type: path
    Default: ""

    When set, specifies a command used to filter messages.  When a
    message is viewed it is passed as standard input to
    ``$display_filter'', and the filtered message is read from the
    standard output.

To always apply your 'strip' filter, the line in your muttrc should 
be:

    set display_hook=~/.mutt/scripts/strip

or

    message-hook . "set display_hook=~/.mutt/scripts/strip"

For such a simple filter, you could also omit the script and use the 
sed command directly:

    set display_hook='sed -e "/^\[-- Attachment .* --].*$/d"'

When you start embedding such settings within hooks, however, the 
quoting can get really hairy, as in the last hook in the list below.

Here are the hooks I use for setting display_filter.

    folder-hook .                       'unhook message-hook'

    folder-hook .                       'message-hook ~A                "set 
display_filter=mail-to-filter"'
    folder-hook '!'                     'message-hook ~A                "set 
display_filter=mutt_gen_disp_filter"'
    folder-hook +project/.              'message-hook ~A                "set 
display_filter=mutt_gen_disp_filter"'
    folder-hook +wordorigins.org        'message-hook ~A                "set 
display_filter=mutt_gen_disp_filter"'
    folder-hook .                       'message-hook "~s infospark"    "set 
display_filter=mutt_infospark_filter"'

    folder-hook +Lists/.                'message-hook ~A                '\''set 
display_filter="sed  '\'\\\'\''/^.*\\[-- .* --]$/d'\'\\\'\'' | 
iso8859toascii"'\'''

I'm afraid that's going to be difficult to read in anything but a
wide terminal.

It works like this.  When mutt opens a folder, the first folder hook
clears the list of message-hooks and the second folder-hook sets the
global default display_filter.  Subsequent folder-hooks define a set
of message-hooks for that folder.  When mutt opens a message, the
global-default-display_filter message-hook fires and sets
display_filter to mail-to-filter.  Then the default display_filter
message-hook for that folder, if any, fires.  Finally, any
message-specific message-hooks defined for that folder and triggered
by that message fire.

One could argue that the message-hook for the +Lists/. folders is
unnecessary since all messages in that folder use the same
display_filter.  However, these aren't the only folder- and
message-hooks I use and I like keeping the structure consistent.

What it means is this.  With rare exception, I want to use the
mail-to-filter to compact the To: and Cc: lists in all messages.
For my spoolfile ($MAIL) and +project/. folders, I want to use the
mutt_gen_disp_filter, which contains a pipeline of filters
(including mail-to-filter) to clean up the display of messages from
internal and random external sources.  For some reason I decided I
wanted to use it also for reading my archive of newsletters from
wordorigins.org.  I want to use the ANSI color highlighting provided
by mutt_infospark_filter to read the infospark newsletter in
whatever folder I find it.  The +Lists directory contains the
folders for all the mailing lists to which I subscribe.  The members
of those lists generally use well-behaved MUAs and they never
include long distribution lists, so I just use a minimal cleanup of
the display.  ('iso8859toascii' is my 'demoronizer' equivalent.)

Hope that clarifies things.

Regards,
Gary

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