Hi, I just joined this list, and I haven't yet looked at the archives if this has come up before ...
Now for my question - I am trying to implement a display filter for my emails using Mutt's $display_filter variable (ie. the output of this script is displayed in mutt's pager). Now, I want to 'smartly' wrap all the lines longer than 70 chars, and still keep the quoting. I tried Text::Autoformat, but it makes mutt really slow, and it seems kind of overkill for what I want. I have attached my script below - please suggest a way of doing this without Text::Autoformat. <code> #!/usr/bin/perl -w # File: display_filter.pl # Last Update: Sat, 29 Dec 2001 13:28:08 +0530 # Modified By: Prahlad Vaidyanathan <[EMAIL PROTECTED]> # Usage : # set $display_filter in muttrc to this script, and make script executable # THANKS # * thomas hurst's quotefix.rb # TODO # * use g. johnson's mail-to-filter.pl to compress large to/cc headers # * better algorithm for blank-line consolidation # * line wrap at 72 chars, preserving words w/out Text::Autoformat use strict ; # use Text::Autoformat ; # Need it for word-wrapping # Change the following to suit your needs my $quote_re = "^(-->)|^([ \t]*[A-Za-z]+>)|^([ \t]*[\|%>:!]) ?" ; my $nonquote_re = "^(grub>|(https?|ftp|mailto|news|rsync|telnet|gopher):|[:;=][-+]?[\)DPdb])" ; my $bad_sig_re = "^(-{2,3}|_{30,})\$" ; # match hotmail/yahoo ads and ML footers my $flag = 0 ; # Flag for blank-line removal my $line_length = 70 ; my $line ; # Headers (use muttrc to play with these) while ( ( $line = <STDIN> ) !~ /^$/ ) { print $line ; } print "\n" ; # Strip ! ;-) while ($line = <STDIN>) { # Emacs users ... bah ! $line =~ s/>>>>> // ; # Strip if $quote_re matches, and $nonquote_re doesn't my $quote_depth = 0; while ( $line =~ $quote_re && $line !~ $nonquote_re ) { $quote_depth++; # Increment $quote_depth $line = $' ; # $line is set to everything _after_ the matched regex } # Strip trailing white-spaces $line =~ s/[\s\t]+$/\n/ ; # Fix bad sig-dashes $line =~ s/$bad_sig_re/-- /; # Remove dos line-breaks $line =~ s/ // ; # Makes block of blank lines into one if ( $line =~ /^$/ ) { $flag += 1 ; if ( $flag eq 1 ) { print "\n" ; next ; } elsif ( $flag gt 1 ) { next ; } } $flag = 0 ; # Word wrapping # $line = autoformat($line,{right =>70,all=>1}) ; # Put back the 'correct' quote-string $line = ('>' x $quote_depth) . ' ' . $line if ($quote_depth) ; # Display it print $line ; } </code> pv. -- Prahlad Vaidyanathan <[EMAIL PROTECTED]> Those who cannot remember the past are condemned to repeat it. -- George Santayana
msg15012/pgp00000.pgp
Description: PGP signature