#!/usr/bin/perl -w use strict; use warnings; use HTML::Entities; sub sanitize { # no name? $_[0] ||= "anonymous"; # add missing protocol in $url if ($_[1] && $_[1] !~ /^\w+:/) { $_[1] = "http://" . $_[1] } # add missing protocol in link in $body $_[2] =~ s{\[(.*?)\]}{ my $x = $1; if ($1 !~ /^\w+:/) { if ($1 =~ /\@/) { "[mailto:$x|$x]"; } else { "[http://$x]" } } else { "[$x]" } }gex; # don't let people put in html $_[2] = HTML::Entities::encode($_[2]); } my $body = "Mail me at [bugs\@microsoft.com]."; my $url; my $name; sanitize("", $url, $body); print $body, "\n";