]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Smsg.pm
www_stream: extra link to mirroring information in the footer
[public-inbox.git] / lib / PublicInbox / Smsg.pm
index c6ff7f52b0ac90a2aad2326f80c4b862b4cc982b..da8ce590991a3e40522bcab2bc0c561d5aa5683f 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;
+               }
+               $seen{$ref} //= push(@keep, $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) = @_;