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_compressed 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
22 my ($mid, $force) = @_;
24 # XXX dirty hack! FIXME!
25 # Some HTTP servers (apache2 2.2.22-13+deb7u5 on my system)
26 # apparently do not handle "%25" in the URL path component correctly.
27 # I'm not yet sure if it's something weird with my rewrite rules
28 # or what; will need to debug...
29 return sha1_hex($mid) if (index($mid, '%') >= 0);
31 return $mid if (!$force && length($mid) <= MID_MAX);
37 my ($x2, $x38) = ($mid =~ /\A([a-f0-9]{2})([a-f0-9]{38})\z/);
39 unless (defined $x38) {
40 # compatibility with old links (or short Message-IDs :)
41 $mid = sha1_hex($mid);
42 ($x2, $x38) = ($mid =~ /\A([a-f0-9]{2})([a-f0-9]{38})\z/);