]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/MID.pm
wwwstream: flesh out clone instructions for v2
[public-inbox.git] / lib / PublicInbox / MID.pm
index 96085399b6d2f2d96ba9bef3d06376a953132953..117d3c42f987e1fc2079cbccd2025f0176194085 100644 (file)
@@ -10,7 +10,10 @@ our @EXPORT_OK = qw/mid_clean id_compress mid2path mid_mime mid_escape MID_ESC
        mids references/;
 use URI::Escape qw(uri_escape_utf8);
 use Digest::SHA qw/sha1_hex/;
-use constant MID_MAX => 40; # SHA-1 hex length
+use constant {
+       MID_MAX => 40, # SHA-1 hex length # TODO: get rid of this
+       MAX_MID_SIZE => 244, # max term size (Xapian limitation) - length('Q')
+};
 
 sub mid_clean {
        my ($mid) = @_;
@@ -47,7 +50,8 @@ sub mid2path {
        "$x2/$x38";
 }
 
-sub mid_mime ($) { $_[0]->header_obj->header_raw('Message-ID') }
+# Only for v1 code paths:
+sub mid_mime ($) { mids($_[0]->header_obj)->[0] }
 
 sub mids ($) {
        my ($hdr) = @_;
@@ -61,6 +65,12 @@ sub mids ($) {
                        push(@mids, $v);
                }
        }
+       foreach my $i (0..$#mids) {
+               next if length($mids[$i]) <= MAX_MID_SIZE;
+               warn "Message-ID: <$mids[$i]> too long, truncating\n";
+               $mids[$i] = substr($mids[$i], 0, MAX_MID_SIZE);
+       }
+
        uniq_mids(\@mids);
 }