diff options
author | Eric Wong <e@80x24.org> | 2021-01-24 04:46:54 -0700 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-01-24 15:46:08 -0400 |
commit | 7355803ccf17bd609c9d667d3b9cadb2adfc31bd (patch) | |
tree | 543679a5e0b6d0e23b3322bb51af7dc53033ee5e /lib/PublicInbox/Smsg.pm | |
parent | ac35655d75706ce297a71b6537334a2f690b6247 (diff) | |
download | public-inbox-7355803ccf17bd609c9d667d3b9cadb2adfc31bd.tar.gz |
Having parse_references in OverIdx was awkward and Smsg is a better place for it.
Diffstat (limited to 'lib/PublicInbox/Smsg.pm')
-rw-r--r-- | lib/PublicInbox/Smsg.pm | 22 |
1 files changed, 21 insertions, 1 deletions
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) = @_; |