]> Sergey Matveev's repositories - public-inbox.git/commitdiff
msg_iter: support read-only elements
authorEric Wong <e@80x24.org>
Thu, 16 Jun 2016 22:45:24 +0000 (22:45 +0000)
committerEric Wong <e@80x24.org>
Fri, 17 Jun 2016 00:19:31 +0000 (00:19 +0000)
Apparently, it's possible to have read-only bodies in
Email::MIME objects.  Haven't gotten a chance to reliably
reproduce it, though...

lib/PublicInbox/MsgIter.pm

index e0127ab99de9478c78121eac03049de7fbd09f3b..ef0d209f6b391efc45ab843c3c8154a5cbd66557 100644 (file)
@@ -7,6 +7,7 @@ use warnings;
 use base qw(Exporter);
 our @EXPORT = qw(msg_iter);
 use Email::MIME;
+use Scalar::Util qw(readonly);
 
 # Workaround Email::MIME versions without
 # commit dcef9be66c49ae89c7a5027a789bbbac544499ce
@@ -36,7 +37,14 @@ sub msg_iter ($$) {
                                @parts = (@sub, @parts);
                        } else {
                                if ($extra_nl) {
-                                       ${$part->{body}} .= $part->{mycrlf};
+                                       my $lf = $part->{mycrlf};
+                                       my $bref = $part->{body};
+                                       if (readonly($$bref)) {
+                                               my $s = $$bref . $lf;
+                                               $part->{body} = \$s;
+                                       } else {
+                                               $$bref .= $lf;
+                                       }
                                }
                                $cb->($p);
                        }