commit 6440ea89c254d02ffd3b020f81b061be397290be from: Caleb Stein date: Wed May 6 22:33:44 2026 UTC wrap lines to 80 characters, refactor for conciseness commit - 82224691dcb4f7411d9fb2868b46b9e03af9a5b2 commit + 6440ea89c254d02ffd3b020f81b061be397290be blob - dbbf37eee4e373bfcecd6356568e75ae3a5e59ac blob + 95389304453e989ea05e94f88592135419482bd4 --- mailread.pl +++ mailread.pl @@ -4,24 +4,21 @@ use strict; use IPC::Run3; my $content = do { local $/; <> }; -my ($headers, $body) = split(/\n\n/, $content, 2); +my ($headers, $body) = $content =~ /^(.*?\n)\n(.*)$/s ? ($1, $2) : ('', $content); my $ishtml = qr/< *(html|head|body|div|table|p|span|br) *\/?>/i; run3(['lynx', '-dump', '-force_html', '-stdin'], \$body, \$body, undef) if ($body =~ $ishtml); -open(my $fh, '>', "$ENV{HOME}/.maillinks"); -my $i = 0; -$body =~ s{(https?://[^\s<>"]+)}{ - if (length($1) > 80) + +print "$headers\n"; +{ + open my $body_fh, '<', \$body or die $!; + open my $links_fh, '>', "$ENV{HOME}/.maillinks" or die $!; + my $i = 0; + while (<$body_fh>) { - print $fh "$1\n"; - "[Link #" . ++$i . "]"; + $_ =~ s{(https?://[^\s<>"]+)}{print $links_fh "$1\n"; "[Link #" . ++$i . "]";}ge; + $_ =~ s/(.{1,80})(?:\s+|$)/$1\n/g; + print; } - else - { - $1; - } -}gex; -close $fh; +} -print "$headers\n\n$body"; -