-# Copyright (C) 2018-2020 all contributors <meta@public-inbox.org>
+# Copyright (C) 2018-2021 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
# Unstable internal API.
# See L<public-inbox-v2-format(5)> manpage for more details.
package PublicInbox::ContentHash;
use strict;
-use warnings;
-use base qw/Exporter/;
-our @EXPORT_OK = qw/content_hash content_digest/;
+use v5.10.1;
+use parent qw(Exporter);
+our @EXPORT_OK = qw(content_hash content_digest git_sha);
use PublicInbox::MID qw(mids references);
use PublicInbox::MsgIter;
# Only use Sender: if From is not present
foreach my $h (qw(From Sender)) {
- my @v = $eml->header($h);
- if (@v) {
- digest_addr($dig, $h, $_) foreach @v;
- }
+ my @v = $eml->header($h) or next;
+ digest_addr($dig, $h, $_) foreach @v;
+ last;
}
foreach my $h (qw(Subject Date)) {
my @v = $eml->header($h);
content_digest($_[0])->digest;
}
+sub git_sha ($$) {
+ my ($n, $eml) = @_;
+ my $dig = Digest::SHA->new($n);
+ my $buf = $eml->as_string;
+ $dig->add('blob '.length($buf)."\0");
+ $dig->add($buf);
+ $dig;
+}
+
1;