diff --git a/mailview.pl b/mailview.pl new file mode 100644 index 0000000..739b7f5 --- /dev/null +++ b/mailview.pl @@ -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 () { + 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; diff --git a/readme.md b/readme.md index 3a7af1a..8b2ede0 100644 --- a/readme.md +++ b/readme.md @@ -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.