X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FEml.pm;h=462d51fc0cbcd118770abc2ba8bbe0af9fea1008;hb=af0b0fb7a454470a32c452119d0392e0dedb3fe1;hp=6f6874cd2379b145f9cbe23177e9fe651de1c2ac;hpb=e60231148eb604a379033c69e8c4494eb1753783;p=public-inbox.git diff --git a/lib/PublicInbox/Eml.pm b/lib/PublicInbox/Eml.pm index 6f6874cd..462d51fc 100644 --- a/lib/PublicInbox/Eml.pm +++ b/lib/PublicInbox/Eml.pm @@ -1,4 +1,4 @@ -# Copyright (C) 2020 all contributors +# Copyright (C) 2020-2021 all contributors # License: AGPL-3.0+ # # Lazy MIME parser, it still slurps the full message but keeps short @@ -129,7 +129,7 @@ sub new { sub new_sub { my (undef, $ref) = @_; # special case for messages like <85k5su9k59.fsf_-_@lola.goethe.zz> - $$ref =~ /\A(\r?\n)/s or goto &new; + $$ref =~ /\A(\r?\n)/s or return new(undef, $ref); my $hdr = substr($$ref, 0, $+[0], ''); # sv_chop on $$ref bless { hdr => \$hdr, crlf => $1, bdy => $ref }, __PACKAGE__; } @@ -235,11 +235,11 @@ sub mp_descend ($$) { # $arg - user-supplied arg (think pthread_create) # $once - unref body scalar during iteration sub each_part { - my ($self, $cb, $arg, $once) = @_; + my ($self, $cb, $arg, $once, $all) = @_; my $p = mp_descend($self, $once // 0) or - return $cb->([$self, 0, 0], $arg); + return $cb->([$self, 0, 1], $arg); - $cb->([$self, 0, 0], $arg) if $self->{-call_cb}; # rare + $cb->([$self, 0, 0], $arg) if ($all || $self->{-call_cb}); # rare $p = [ $p, 0 ]; my @s; # our virtual stack @@ -255,7 +255,8 @@ sub each_part { (my $nxt = mp_descend($sub, $nr))) { push(@s, $p) if scalar @{$p->[0]}; $p = [ $nxt, @idx, 0 ]; - $cb->([$sub, $depth, @idx], $arg) if $sub->{-call_cb}; + ($all || $sub->{-call_cb}) and + $cb->([$sub, $depth, @idx], $arg); } else { # a leaf node $cb->([$sub, $depth, @idx], $arg); } @@ -367,14 +368,19 @@ sub header_str_set { my ($self, $name, @vals) = @_; for (@vals) { next unless /[^\x20-\x7e]/; - utf8::encode($_); # to octets # 39: int((75 - length("Subject: =?UTF-8?B?".'?=') ) / 4) * 3; - s/(.{1,39})/'=?UTF-8?B?'.encode_base64($1, '').'?='/ges; + s/(.{1,39})/ + my $x = $1; + utf8::encode($x); # to octets + '=?UTF-8?B?'.encode_base64($x, '').'?=' + /xges; } header_set($self, $name, @vals); } -sub mhdr_decode ($) { eval { $MIME_Header->decode($_[0]) } // $_[0] } +sub mhdr_decode ($) { + eval { $MIME_Header->decode($_[0], Encode::FB_DEFAULT) } // $_[0]; +} sub filename { my $dis = header_raw($_[0], 'Content-Disposition');