about summary refs log tree commit homepage
path: root/lib/PublicInbox/ContentId.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-12-25 07:50:55 +0000
committerEric Wong <e@80x24.org>2019-12-27 20:00:37 +0000
commita77caf8cd92fcc13d90f7e8b68da6e87008241f8 (patch)
tree454124bb0b5ce31a9bbbb744542ca72e66b7db40 /lib/PublicInbox/ContentId.pm
parent1f53f1bf532a390f130c2029168cf90706595570 (diff)
downloadpublic-inbox-a77caf8cd92fcc13d90f7e8b68da6e87008241f8.tar.gz
msg_iter now passes a user specified arg into the supplied
callback, so we can use that to pass the Digest object into
the \&content_dig_i callback.
Diffstat (limited to 'lib/PublicInbox/ContentId.pm')
-rw-r--r--lib/PublicInbox/ContentId.pm53
1 files changed, 28 insertions, 25 deletions
diff --git a/lib/PublicInbox/ContentId.pm b/lib/PublicInbox/ContentId.pm
index 9d9be417..eb937a0e 100644
--- a/lib/PublicInbox/ContentId.pm
+++ b/lib/PublicInbox/ContentId.pm
@@ -25,6 +25,33 @@ sub digest_addr ($$$) {
         $dig->add("$h\0$v\0");
 }
 
+sub content_dig_i {
+        my ($dig) = $_[1];
+        my ($part, $depth, @idx) = @{$_[0]};
+        $dig->add("\0$depth:".join('.', @idx)."\0");
+        my $fn = $part->filename;
+        if (defined $fn) {
+                utf8::encode($fn);
+                $dig->add("fn\0$fn\0");
+        }
+        my @d = $part->header('Content-Description');
+        foreach my $d (@d) {
+                utf8::encode($d);
+                $dig->add("d\0$d\0");
+        }
+        $dig->add("b\0");
+        my $ct = $part->content_type || 'text/plain';
+        my ($s, undef) = msg_part_text($part, $ct);
+        if (defined $s) {
+                $s =~ s/\r\n/\n/gs;
+                $s =~ s/\s*\z//s;
+                utf8::encode($s);
+        } else {
+                $s = $part->body;
+        }
+        $dig->add($s);
+}
+
 sub content_digest ($) {
         my ($mime) = @_;
         my $dig = Digest::SHA->new(256);
@@ -65,31 +92,7 @@ sub content_digest ($) {
                 my @v = $hdr->header($h);
                 digest_addr($dig, $h, $_) foreach @v;
         }
-        msg_iter($mime, sub {
-                my ($part, $depth, @idx) = @{$_[0]};
-                $dig->add("\0$depth:".join('.', @idx)."\0");
-                my $fn = $part->filename;
-                if (defined $fn) {
-                        utf8::encode($fn);
-                        $dig->add("fn\0$fn\0");
-                }
-                my @d = $part->header('Content-Description');
-                foreach my $d (@d) {
-                        utf8::encode($d);
-                        $dig->add("d\0$d\0");
-                }
-                $dig->add("b\0");
-                my $ct = $part->content_type || 'text/plain';
-                my ($s, undef) = msg_part_text($part, $ct);
-                if (defined $s) {
-                        $s =~ s/\r\n/\n/gs;
-                        $s =~ s/\s*\z//s;
-                        utf8::encode($s);
-                } else {
-                        $s = $part->body;
-                }
-                $dig->add($s);
-        });
+        msg_iter($mime, \&content_dig_i, $dig);
         $dig;
 }