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-28 21:43:17 +0000
committerEric Wong <e@80x24.org>2019-12-28 21:43:17 +0000
commit65e3cc8f6cc73e45db827cbeee4ccecbf1502496 (patch)
treec7575754de71f56b92b9ac808cc3d675f374fef2 /lib/PublicInbox/ContentId.pm
parentac1ac3b4e2858bcee5a644aac8b6320422ea7383 (diff)
parentf2364c5765f0692d2f1e82b61804359a38f3fdfc (diff)
downloadpublic-inbox-65e3cc8f6cc73e45db827cbeee4ccecbf1502496.tar.gz
* no-closure: (30 commits)
  search: retry_reopen passes user arg to callback
  solvergit: allow passing arg to user-supplied callback
  viewvcs: avoid anonymous sub for HTML response
  wwwattach: avoid anonymous sub for msg_iter
  view: msg_iter calls add_body_text directly
  searchview: remove anonymous sub when sorting threads by relevance
  view: thread_html: pass named sub to WwwStream
  searchview: pass named subs to Www*Stream
  wwwtext: avoid anonymous sub in response
  contentid: no anonymous sub
  view: msg_html: stop using an anonymous sub
  view: avoid anon sub in stream_thread
  config: each_inbox: pass user arg to callback
  feed: avoid anonymous subs
  mboxgz: pass $ctx to callback to avoid anon subs
  www: lazy load Plack::Util
  githttpbackend: split out wwwstatic
  qspawn: psgi_return: allow non-anon parse_hdr callback
  qspawn: drop "qspawn.filter" support, for now
  qspawn: psgi_qx: eliminate anonymous subs
  ...
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;
 }