From 615b9752c0d807e32b3f63654f9bf8144deaf420 Mon Sep 17 00:00:00 2001 From: Johannes Löthberg Date: Thu, 1 Jun 2017 19:33:29 +0200 Subject: neomutt: Fix config locations for new release MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Johannes Löthberg --- mutt/tiny.pl | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 mutt/tiny.pl (limited to 'mutt/tiny.pl') diff --git a/mutt/tiny.pl b/mutt/tiny.pl new file mode 100755 index 0000000..06b51b7 --- /dev/null +++ b/mutt/tiny.pl @@ -0,0 +1,49 @@ +#!/usr/bin/perl +################################### +# By: Ventz Petkov # +# Date: 01-05-11 # +# Last: 01-02-13 # +# Parses HTML + Long URLs in MUTT # +################################### + +use URI::Escape; +$file = $ARGV[0]; +@text = (); + +# Only shorten URLs at least this length or more +$tinyurltrigger = 40; + +# If we pass a 2nd argument, it means we want to force HTML check a 'text/plain' file +if(defined($ARGV[2])) { open(FP, $file); for() { push(@text, $_); } close(FP); } +# Otherwise, treat as HTML first +else { @text = `elinks -dump -dump-charset $ARGV[1] -default-mime-type text/html $file`; } + + +# Note: using while (instead of for) b/c for supposedly loads +# everything into memory - no reason to load large emails into memory + +while (my $line = shift @text) { + next if($line =~ /mailto:/); + if($line =~ /(\w+:\/\/\S+)/) { + my $link = $1; + chomp($link); + $size = length($link); + if($size >= $tinyurltrigger) { + eval { + my $alarm = 5; + alarm $alarm; + my $link = uri_escape($link); + $tinyurl=`wget -q -O - http://tinyurl.com/api-create.php?url=$link`; + alarm 0; + }; + + if ($@) { + $line =~ s/(\w+:\/\/\S+)/$link (wget TimeOut)/; } + else { $line =~ s/(\w+:\/\/\S+)/$tinyurl\n\t[>> $link <<]/; } + } + } + print "$line"; +} + + +exit 0; -- cgit v1.2.3-54-g00ecf