about summary refs log tree commit homepage
path: root/lib/PublicInbox/MID.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-08-16 08:53:41 +0000
committerEric Wong <e@80x24.org>2015-08-16 08:53:41 +0000
commit9041b136ba7a106ed5ff33da4b6ae28c2a0f4333 (patch)
tree4a0e87909bdbffe1e6a8b84c3e2273797e0db0fd /lib/PublicInbox/MID.pm
parent5daa5a6a3da3e944c7757b8f3aebedef602f21a4 (diff)
downloadpublic-inbox-9041b136ba7a106ed5ff33da4b6ae28c2a0f4333.tar.gz
More to come later.
Diffstat (limited to 'lib/PublicInbox/MID.pm')
-rw-r--r--lib/PublicInbox/MID.pm14
1 files changed, 13 insertions, 1 deletions
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;