+sub references ($) {
+ my ($hdr) = @_;
+ my @mids;
+ foreach my $f (qw(References In-Reply-To)) {
+ my @v = $hdr->header_raw($f);
+ foreach my $v (@v) {
+ push(@mids, ($v =~ /<([^>]+)>/sg));
+ }
+ }
+ uniq_mids(\@mids);
+}
+
+sub uniq_mids ($) {
+ my ($mids) = @_;
+ my @ret;
+ my %seen;
+ foreach my $mid (@$mids) {
+ $mid =~ tr/\n\t\r//d;
+ if (length($mid) > MAX_MID_SIZE) {
+ warn "Message-ID: <$mid> too long, truncating\n";
+ $mid = substr($mid, 0, MAX_MID_SIZE);
+ }
+ next if $seen{$mid};
+ push @ret, $mid;
+ $seen{$mid} = 1;
+ }
+ \@ret;
+}