]> Sergey Matveev's repositories - public-inbox.git/commitdiff
smsg: make parse_references an object method
authorEric Wong <e@80x24.org>
Sun, 24 Jan 2021 11:46:54 +0000 (04:46 -0700)
committerEric Wong <e@80x24.org>
Sun, 24 Jan 2021 19:46:08 +0000 (15:46 -0400)
Having parse_references in OverIdx was awkward and Smsg is
a better place for it.

lib/PublicInbox/LeiXSearch.pm
lib/PublicInbox/OverIdx.pm
lib/PublicInbox/SearchIdx.pm
lib/PublicInbox/Smsg.pm

index afd2fc24793328fc63e23e523320791d145afaf9..fb608d00611455237a68b726becd6a76f4073da4 100644 (file)
@@ -169,7 +169,7 @@ sub each_eml { # callback for MboxReader->mboxrd
        my ($eml, $self, $lei, $each_smsg) = @_;
        my $smsg = bless {}, 'PublicInbox::Smsg';
        $smsg->populate($eml);
-       PublicInbox::OverIdx::parse_references($smsg, $eml, mids($eml));
+       $smsg->parse_references($eml, mids($eml));
        $smsg->{$_} //= '' for qw(from to cc ds subject references mid);
        delete @$smsg{qw(From Subject -ds -ts)};
        if (my $startq = delete($self->{5})) { wait_startq($startq) }
@@ -381,7 +381,6 @@ sub ipc_atfork_prepare {
        my ($self) = @_;
        if (exists $self->{remotes}) {
                require PublicInbox::MboxReader;
-               require PublicInbox::OverIdx; # parse_references
                require IO::Uncompress::Gunzip;
        }
        # FDS: (0: done_wr, 1: stdout|mbox, 2: stderr,
index e606dcf564bfb8e59bf517558002a8b005579769..985c5473e7c7cf491386de5fdf07164de982db54 100644 (file)
@@ -243,26 +243,6 @@ sub link_refs {
        $tid;
 }
 
-sub parse_references ($$$) {
-       my ($smsg, $hdr, $mids) = @_;
-       my $refs = references($hdr);
-       push(@$refs, @$mids) if scalar(@$mids) > 1;
-       return $refs if scalar(@$refs) == 0;
-
-       # prevent circular references here:
-       my %seen = ( $smsg->{mid} => 1 );
-       my @keep;
-       foreach my $ref (@$refs) {
-               if (length($ref) > PublicInbox::MID::MAX_MID_SIZE) {
-                       warn "References: <$ref> too long, ignoring\n";
-                       next;
-               }
-               push(@keep, $ref) unless $seen{$ref}++;
-       }
-       $smsg->{references} = '<'.join('> <', @keep).'>' if @keep;
-       \@keep;
-}
-
 # normalize subjects so they are suitable as pathnames for URLs
 # XXX: consider for removal
 sub subject_path ($) {
@@ -283,7 +263,7 @@ sub add_overview {
        my ($self, $eml, $smsg) = @_;
        $smsg->{lines} = $eml->body_raw =~ tr!\n!\n!;
        my $mids = mids_for_index($eml);
-       my $refs = parse_references($smsg, $eml, $mids);
+       my $refs = $smsg->parse_references($eml, $mids);
        $mids->[0] //= $smsg->{mid} //= $eml->{-lei_fake_mid};
        $smsg->{mid} //= '';
        my $subj = $smsg->{subject};
index 7f7b980d96a1efb665db1ebcc8f5c9935cdc0caa..826302dec1270ca498e455239beabe39260b9ba5 100644 (file)
@@ -380,7 +380,7 @@ sub eml2doc ($$$;$) {
        if (!$self->{-skip_docdata}) {
                # WWW doesn't need {to} or {cc}, only NNTP
                $smsg->{to} = $smsg->{cc} = '';
-               PublicInbox::OverIdx::parse_references($smsg, $eml, $mids);
+               $smsg->parse_references($eml, $mids);
                my $data = $smsg->to_doc_data;
                $doc->set_data($data);
        }
index c6ff7f52b0ac90a2aad2326f80c4b862b4cc982b..2b72e8b5ae804e283cbd4711f2a001261da9355c 100644 (file)
@@ -12,7 +12,7 @@ use strict;
 use warnings;
 use base qw(Exporter);
 our @EXPORT_OK = qw(subject_normalized);
-use PublicInbox::MID qw(mids);
+use PublicInbox::MID qw(mids references);
 use PublicInbox::Address;
 use PublicInbox::MsgTime qw(msg_timestamp msg_datestamp);
 
@@ -69,6 +69,26 @@ sub psgi_cull ($) {
        $self;
 }
 
+sub parse_references ($$$) {
+       my ($smsg, $hdr, $mids) = @_;
+       my $refs = references($hdr);
+       push(@$refs, @$mids) if scalar(@$mids) > 1;
+       return $refs if scalar(@$refs) == 0;
+
+       # prevent circular references here:
+       my %seen = ( $smsg->{mid} => 1 );
+       my @keep;
+       foreach my $ref (@$refs) {
+               if (length($ref) > PublicInbox::MID::MAX_MID_SIZE) {
+                       warn "References: <$ref> too long, ignoring\n";
+                       next;
+               }
+               push(@keep, $ref) unless $seen{$ref}++;
+       }
+       $smsg->{references} = '<'.join('> <', @keep).'>' if @keep;
+       \@keep;
+}
+
 # used for v2, Import and v1 non-SQLite WWW code paths
 sub populate {
        my ($self, $hdr, $sync) = @_;