]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/MID.pm
mid: truncate excessively long MIDs early
[public-inbox.git] / lib / PublicInbox / MID.pm
index 96085399b6d2f2d96ba9bef3d06376a953132953..422902f53bed43ab31fff3d93e817adf3d94f441 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) = @_;
@@ -61,6 +64,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);
 }