]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/SearchIdx.pm
searchidx: use cached local $@ copy
[public-inbox.git] / lib / PublicInbox / SearchIdx.pm
index 87ee0d46406ef688aa215356143923a82ddd9b14..fd0d320e8685fe34c37b5f07162d3e81da2f0c06 100644 (file)
@@ -10,7 +10,7 @@ package PublicInbox::SearchIdx;
 use strict;
 use warnings;
 use Fcntl qw(:flock :DEFAULT);
-use Email::MIME;
+use PublicInbox::MIME;
 use Email::MIME::ContentType;
 $Email::MIME::ContentType::STRICT_PARAMS = 0;
 use base qw(PublicInbox::Search);
@@ -291,13 +291,12 @@ sub link_message {
        my $mid = $smsg->mid;
        my $mime = $smsg->{mime};
        my $hdr = $mime->header_obj;
-       my $refs = $hdr->header_raw('References');
-       my @refs = $refs ? ($refs =~ /<([^>]+)>/g) : ();
-       my $irt = $hdr->header_raw('In-Reply-To');
-       if (defined $irt) {
-               $irt = mid_clean($irt);
-               $irt = undef if $mid eq $irt;
-       }
+
+       # last References should be IRT, but some mail clients do things
+       # out of order, so trust IRT over References iff IRT exists
+       my @refs = ($hdr->header_raw('References'),
+                       $hdr->header_raw('In-Reply-To'));
+       @refs = ((join(' ', @refs)) =~ /<([^>]+)>/g);
 
        my $tid;
        if (@refs) {
@@ -305,15 +304,6 @@ sub link_message {
                my @orig_refs = @refs;
                @refs = ();
 
-               if (defined $irt) {
-                       # to check MAX_MID_SIZE
-                       push @orig_refs, $irt;
-
-                       # below, we will ensure IRT (if specified)
-                       # is the last References
-                       $uniq{$irt} = 1;
-               }
-
                # prevent circular references via References: here:
                foreach my $ref (@orig_refs) {
                        if (length($ref) > MAX_MID_SIZE) {
@@ -325,10 +315,6 @@ sub link_message {
                }
        }
 
-       # last References should be IRT, but some mail clients do things
-       # out of order, so trust IRT over References iff IRT exists
-       push @refs, $irt if defined $irt;
-
        if (@refs) {
                $smsg->{references} = '<'.join('> <', @refs).'>';
 
@@ -344,7 +330,7 @@ sub link_message {
                        merge_threads($self, $tid, $ptid);
                }
        } else {
-               $tid = $self->next_thread_id;
+               $tid = defined $old_tid ? $old_tid : $self->next_thread_id;
        }
        $doc->add_term(xpfx('thread') . $tid);
 }
@@ -400,7 +386,7 @@ sub do_cat_mail {
                my $str = $git->cat_file($blob, $sizeref);
                # fixup bugs from import:
                $$str =~ s/\A[\r\n]*From [^\r\n]*\r?\n//s;
-               Email::MIME->new($str);
+               PublicInbox::MIME->new($str);
        };
        $@ ? undef : $mime;
 }
@@ -634,7 +620,7 @@ sub with_umask {
        my $rv = eval { $cb->() };
        my $err = $@;
        umask $old;
-       die $err if $@;
+       die $err if $err;
        $rv;
 }