1 # Copyright (C) 2018 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 package PublicInbox::ContentId;
8 our @EXPORT_OK = qw/content_id content_digest/;
9 use PublicInbox::MID qw(mids references);
11 # not sure if less-widely supported hash families are worth bothering with
14 sub content_digest ($) {
16 my $dig = Digest::SHA->new(256);
17 my $hdr = $mime->header_obj;
19 # References: and In-Reply-To: get used interchangeably
20 # in some "duplicates" in LKML. We treat them the same
21 # in SearchIdx, so treat them the same for this:
23 foreach my $mid (@{mids($hdr)}) {
24 $dig->add('mid: '.$mid);
27 foreach my $mid (@{references($hdr)}) {
29 $dig->add('ref: '.$mid);
32 # Only use Sender: if From is not present
33 foreach my $h (qw(From Sender)) {
34 my @v = $hdr->header_raw($h);
36 $dig->add("$h: $_") foreach @v;
41 # Content-* headers are often no-ops, so maybe we don't need them
42 foreach my $h (qw(Subject Date To Cc)) {
43 my @v = $hdr->header_raw($h);
44 $dig->add("$h: $_") foreach @v;
46 $dig->add($mime->body_raw);
51 content_digest($_[0])->digest;