+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 ($) {
+ my ($subj) = @_;
+ $subj = subject_normalized($subj);
+ $subj =~ s![^a-zA-Z0-9_\.~/\-]+!_!g;
+ lc($subj);
+}
+
+sub add_overview {
+ my ($self, $mime, $smsg) = @_;
+ $smsg->{lines} = $mime->body_raw =~ tr!\n!\n!;
+ $smsg->{mime} = $mime; # XXX temporary?
+ my $hdr = $mime->header_obj;
+ my $mids = mids_for_index($hdr);
+ my $refs = parse_references($smsg, $hdr, $mids);
+ my $subj = $smsg->subject;
+ my $xpath;
+ if ($subj ne '') {
+ $xpath = subject_path($subj);
+ $xpath = id_compress($xpath);
+ }
+ my $dd = $smsg->to_doc_data;
+ utf8::encode($dd);
+ $dd = compress($dd);
+ add_over($self, [ @$smsg{qw(ts ds num)}, $mids, $refs, $xpath, $dd ]);
+}
+