From 9041b136ba7a106ed5ff33da4b6ae28c2a0f4333 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 16 Aug 2015 08:53:41 +0000 Subject: view: deduplicate common code for loading search results More to come later. --- lib/PublicInbox/MID.pm | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'lib/PublicInbox/MID.pm') diff --git a/lib/PublicInbox/MID.pm b/lib/PublicInbox/MID.pm index e5a30a1b..d097011b 100644 --- a/lib/PublicInbox/MID.pm +++ b/lib/PublicInbox/MID.pm @@ -4,7 +4,7 @@ package PublicInbox::MID; use strict; use warnings; use base qw/Exporter/; -our @EXPORT_OK = qw/mid_clean mid_compressed/; +our @EXPORT_OK = qw/mid_clean mid_compressed mid2path/; use Digest::SHA qw/sha1_hex/; use constant MID_MAX => 40; # SHA-1 hex length @@ -24,4 +24,16 @@ sub mid_compressed { sha1_hex($mid); } +sub mid2path { + my ($mid) = @_; + my ($x2, $x38) = ($mid =~ /\A([a-f0-9]{2})([a-f0-9]{38})\z/); + + unless (defined $x38) { + # compatibility with old links (or short Message-IDs :) + $mid = sha1_hex($mid); + ($x2, $x38) = ($mid =~ /\A([a-f0-9]{2})([a-f0-9]{38})\z/); + } + "$x2/$x38"; +} + 1; -- cgit v1.2.3-24-ge0c7