#!/usr/bin/perl -w use strict; use warnings; use HTML::Entities; sub sanitize { my($name, $url, $body) = @_; # no name? $name ||= "anonymous"; # add missing protocol in $url if ($url && $url !~ /^\w+:/) { $url = "http://" . $url } # add missing protocol in link in $body $body =~ 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 $body = HTML::Entities::encode($body); # Return modified body. return $body; } my $body = "Mail me at [bugs\@microsoft.com]."; my $url; my $name; $body = sanitize("", $url, $body); print $body, "\n";