]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/ContentHash.pm
pop3: reduce memory use while generating the mailbox cache
[public-inbox.git] / lib / PublicInbox / ContentHash.pm
index cc4a54c922d09c9788cfb63b03097631ecc7bcb0..bacc9cdda12498abbb0ada5d2a2e2faec10190f2 100644 (file)
@@ -20,6 +20,7 @@ use Digest::SHA;
 sub digest_addr ($$$) {
        my ($dig, $h, $v) = @_;
        $v =~ tr/"//d;
+       $v =~ tr/\r\n\t / /s;
        $v =~ s/@([a-z0-9\_\.\-\(\)]*([A-Z])\S*)/'@'.lc($1)/ge;
        utf8::encode($v);
        $dig->add("$h\0$v\0");
@@ -52,9 +53,9 @@ sub content_dig_i {
        $dig->add($s);
 }
 
-sub content_digest ($) {
-       my ($eml) = @_;
-       my $dig = Digest::SHA->new(256);
+sub content_digest ($;$) {
+       my ($eml, $dig) = @_;
+       $dig //= Digest::SHA->new(256);
 
        # References: and In-Reply-To: get used interchangeably
        # in some "duplicates" in LKML.  We treat them the same