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

Re: Truncating over-long headers?



2004-08-20T17:51:33 Nicolas Rachinsky:
> * Bennett Todd <bet@xxxxxxxxx> [2004-08-20 17:44 +0000]:
> > Is there any way to put a cap on how much of some headers gets
> > displayed? We've got some ... clever people where I work, who are
> 
> Yes. Some lines of perl and $display_filter should do it.

Thank you, sir!

The "h" toggle doesn't display the unmunged headers as I'd
fantasized, but that's certainly reasonable, and |less is not
particularly painful; if it were, in fact, I imagine I could get
that behavior by learning about mutt macros:-).

In case anybody else should care to have over-long headers chomped
in mutt's view, I attach the happily trivial perl script to do the
deed.

-Bennett
#!/usr/bin/perl -w
use strict;

=head1 NAME

  mutt_display_filter --- Bennett's header chomper

=head1 SYNOPSIS

  mutt_display_filter --width=95 --height=4 --tabs=8

=head1 DESCRIPTION

mutt_display_filter reads a message (RFC 822, w/ optional From_
line) on stdin, and writes it to stdout. Headers are truncated; any
text line in any header that exceeds width=95 chars is truncated and
"..." appended; any header containing more than height=4 lines is
truncated and "..." is the fifth, final line. Tabs are every tabs=8
columns for purposes of width computation.

=cut

use Getopt::Long;
my $width = 95;
my $height = 4;
my $tabs = 8;
my $syntax = "syntax: mutt_display_filter [--width=$width] [--height=$height] 
[--tabs=$tabs]\n";
GetOptions("width=s" => \$width, "height=s" => \$height, "tabs=i" => \$tabs) or 
die $syntax;
die $syntax if @ARGV;

use Text::Tabs;
$tabstop = $tabs;

my @current;
while (<>) {
    if (length == 1) {
        print @current, $_, <>;
        exit 0;
    }
    if (/^\S/) {
        print @current;
        @current = ();
    }
    push @current, "\t...\n" if @current == $height;
    next if @current > $height;
    chomp;
    ($_) = expand($_);
    substr($_, $width) = "..." if length > $width;
    push @current, map { "$_\n" } unexpand($_);
}

Attachment: pgpFLDGNKBtSo.pgp
Description: PGP signature