about summary refs log tree commit homepage
path: root/lib/PublicInbox
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-01-24 04:46:54 -0700
committerEric Wong <e@80x24.org>2021-01-24 15:46:08 -0400
commit7355803ccf17bd609c9d667d3b9cadb2adfc31bd (patch)
tree543679a5e0b6d0e23b3322bb51af7dc53033ee5e /lib/PublicInbox
parentac35655d75706ce297a71b6537334a2f690b6247 (diff)
downloadpublic-inbox-7355803ccf17bd609c9d667d3b9cadb2adfc31bd.tar.gz
Having parse_references in OverIdx was awkward and Smsg is
a better place for it.
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r--lib/PublicInbox/LeiXSearch.pm3
-rw-r--r--lib/PublicInbox/OverIdx.pm22
-rw-r--r--lib/PublicInbox/SearchIdx.pm2
-rw-r--r--lib/PublicInbox/Smsg.pm22
4 files changed, 24 insertions, 25 deletions
diff --git a/lib/PublicInbox/LeiXSearch.pm b/lib/PublicInbox/LeiXSearch.pm
index afd2fc24..fb608d00 100644
--- a/lib/PublicInbox/LeiXSearch.pm
+++ b/lib/PublicInbox/LeiXSearch.pm
@@ -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,
diff --git a/lib/PublicInbox/OverIdx.pm b/lib/PublicInbox/OverIdx.pm
index e606dcf5..985c5473 100644
--- a/lib/PublicInbox/OverIdx.pm
+++ b/lib/PublicInbox/OverIdx.pm
@@ -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};
diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm
index 7f7b980d..826302de 100644
--- a/lib/PublicInbox/SearchIdx.pm
+++ b/lib/PublicInbox/SearchIdx.pm
@@ -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);
         }
diff --git a/lib/PublicInbox/Smsg.pm b/lib/PublicInbox/Smsg.pm
index c6ff7f52..2b72e8b5 100644
--- a/lib/PublicInbox/Smsg.pm
+++ b/lib/PublicInbox/Smsg.pm
@@ -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) = @_;