]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Hval.pm
mid: mid_compressed => mid_compress
[public-inbox.git] / lib / PublicInbox / Hval.pm
index 9be163aa70c13b39eb19c326458886ef1a9f75c8..21efe40ef87771668b204836076e438886f1fb0f 100644 (file)
@@ -8,6 +8,7 @@ use warnings;
 use fields qw(raw href);
 use Encode qw(find_encoding);
 use URI::Escape qw(uri_escape_utf8);
+use PublicInbox::MID qw/mid_clean mid_compress/;
 
 my $enc_ascii = find_encoding('us-ascii');
 
@@ -25,16 +26,8 @@ sub new {
 
 sub new_msgid {
        my ($class, $msgid) = @_;
-       $msgid =~ s/\A\s*<?//;
-       $msgid =~ s/>?\s*\z//;
-
-       if (length($msgid) <= 40) {
-               $class->new($msgid);
-       } else {
-               require Digest::SHA;
-               my $hex = Digest::SHA::sha1_hex($msgid);
-               $class->new($msgid, $hex);
-       }
+       $msgid = mid_clean($msgid);
+       $class->new($msgid, mid_compress($msgid));
 }
 
 sub new_oneline {
@@ -55,6 +48,7 @@ my %xhtml_map = (
 
 sub ascii_html {
        my ($s) = @_;
+       $s =~ s/\r\n/\n/sg; # fixup bad line endings
        $s =~ s/([<>&'"])/$xhtml_map{$1}/ge;
        $enc_ascii->encode($s, Encode::HTMLCREF);
 }