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 # Content-* headers are often no-ops, so maybe we don't need them
15 my @ID_HEADERS = qw(Subject From Date To Cc);
17 sub content_digest ($) {
19 my $dig = Digest::SHA->new(256);
20 my $hdr = $mime->header_obj;
22 # References: and In-Reply-To: get used interchangeably
23 # in some "duplicates" in LKML. We treat them the same
24 # in SearchIdx, so treat them the same for this:
26 foreach my $mid (@{mids($hdr)}) {
27 $dig->add('mid: '.$mid);
30 foreach my $mid (@{references($hdr)}) {
32 $dig->add('ref: '.$mid);
34 foreach my $h (@ID_HEADERS) {
35 my @v = $hdr->header_raw($h);
36 $dig->add("$h: $_") foreach @v;
38 $dig->add($mime->body_raw);
43 content_digest($_[0])->digest;