Adding mailview

This commit is contained in:
MaffC 2013-02-04 03:04:05 +00:00
parent 0b30a0e469
commit 104331e409
2 changed files with 37 additions and 0 deletions

36
mailview.pl Normal file
View File

@ -0,0 +1,36 @@
#!/usr/bin/env perl
# mailview.pl
# This should be added to your ~/.mailcap as: text/html; mailview.pl; copiousoutput
#Encoding stuff
use encoding 'UTF-8';
binmode STDIN, ":utf8";
binmode STDOUT, ":utf8";
#Libraries/modules. This is basically the dependencies list.
use Encode;
use HTML::FormatText::WithLinks;
#Main source
#Disable STDERR - This is done so that the bottom of displayed mails isn't perl errors about invalid unicode chars
open STDERR, ">/dev/null";
#Instantiate parser, set it up to output parsed data as "blah blah (http://link-that-blah-was-an-href-for/)"
my $parser = HTML::FormatText::WithLinks->new(
before_link => '',
after_link => ' (%l)',
footnote => ''
);
#Read data in from mutt (stdin)
my $upmail;
while (<STDIN>) {
last if /^END$/;
$upmail .= $_;
}
#Parse HTML into plaintext
my $pmail;
$pmail = $parser->parse($upmail);
#Decode UTF8 so that you don't end up with stuff like a\200\223
$pmail = decode_utf8($pmail);
$pmail =~ s/\\xA0/ /g;
#Output back into mutt
print $pmail;

View File

@ -12,3 +12,4 @@ Scripts
This readme contains an up to date list of all scripts in the repo + their descriptions:
- nscheck: Bash - DNS diagnosis script
- mailview: Perl - Script to parse HTML email and format it in a text-reader-friendly way.