1 # Copyright (C) 2015, all contributors <meta@public-inbox.org>
2 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
3 package PublicInbox::MID;
7 our @EXPORT_OK = qw/mid_clean mid_compress mid2path/;
8 use Digest::SHA qw/sha1_hex/;
9 use constant MID_MAX => 40; # SHA-1 hex length
13 defined($mid) or die "no Message-ID";
14 # MDA->precheck did more checking for us
15 if ($mid =~ /<([^>]+)>/) {
23 my ($mid, $force) = @_;
25 # XXX dirty hack! FIXME!
26 # Some HTTP servers (apache2 2.2.22-13+deb7u5 on my system)
27 # apparently do not handle "%25" in the URL path component correctly.
28 # I'm not yet sure if it's something weird with my rewrite rules
29 # or what; will need to debug...
30 return sha1_hex($mid) if (index($mid, '%') >= 0);
32 return $mid if (!$force && length($mid) <= MID_MAX);
38 my ($x2, $x38) = ($mid =~ /\A([a-f0-9]{2})([a-f0-9]{38})\z/);
40 unless (defined $x38) {
41 # compatibility with old links (or short Message-IDs :)
42 $mid = sha1_hex(mid_clean($mid));
43 ($x2, $x38) = ($mid =~ /\A([a-f0-9]{2})([a-f0-9]{38})\z/);