]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/View.pm
Merge commit 'mem'
[public-inbox.git] / lib / PublicInbox / View.pm
index eb002aebbb443d919502a6ac9b6e2ac0d0b77593..cd125e008c08ffe4c6178a60de79531241a4d179 100644 (file)
@@ -119,6 +119,9 @@ sub msg_reply {
 
        my ($arg, $link, $reply_to_all) =
                        PublicInbox::Reply::mailto_arg_link($ibx, $hdr);
+       if (ref($arg) eq 'SCALAR') {
+               return '<pre id=R>'.ascii_html($$arg).'</pre>';
+       }
 
        # mailto: link only works if address obfuscation is disabled
        if ($link) {
@@ -215,11 +218,15 @@ sub index_entry {
        $rv .= $subj . "\n";
        $rv .= _th_index_lite($mid_raw, \$irt, $id, $ctx);
        my @tocc;
-       my $mime = $smsg->{mime};
+       my $ds = $smsg->ds; # for v1 non-Xapian/SQLite users
+       # deleting {mime} is critical to memory use,
+       # the rest of the fields saves about 400K as we iterate across 1K msgs
+       my ($mime) = delete @$smsg{qw(mime ds ts blob subject)};
+
        my $hdr = $mime->header_obj;
        my $from = _hdr_names_html($hdr, 'From');
        obfuscate_addrs($obfs_ibx, $from) if $obfs_ibx;
-       $rv .= "From: $from @ ".fmt_ts($smsg->ds)." UTC";
+       $rv .= "From: $from @ ".fmt_ts($ds)." UTC";
        my $upfx = $ctx->{-upfx};
        my $mhref = $upfx . mid_escape($mid_raw) . '/';
        $rv .= qq{ (<a\nhref="$mhref">permalink</a> / };
@@ -307,7 +314,10 @@ sub _th_index_lite {
        my $nr_s = 0;
        my $siblings;
        if (my $smsg = $node->{smsg}) {
-               ($$irt) = (($smsg->{references} || '') =~ m/<([^>]+)>\z/);
+               # delete saves about 200KB on a 1K message thread
+               if (my $refs = delete $smsg->{references}) {
+                       ($$irt) = ($refs =~ m/<([^>]+)>\z/);
+               }
        }
        my $irt_map = $mapping->{$$irt} if defined $$irt;
        if (defined $irt_map) {
@@ -540,33 +550,14 @@ sub add_text_body {
        my ($part, $depth) = @$p; # attachment @idx is unused
        my $ct = $part->content_type || 'text/plain';
        my $fn = $part->filename;
+       my ($s, $err) = msg_part_text($part, $ct);
 
-       if ($ct =~ m!\btext/x?html\b!i) {
-               return attach_link($upfx, $ct, $p, $fn);
-       }
-
-       my $s = eval { $part->body_str };
-
-       # badly-encoded message? tell the world about it!
-       my $err = $@;
-       if ($err) {
-               if ($ct =~ m!\btext/plain\b!i) {
-                       # Try to assume UTF-8 because Alpine seems to
-                       # do wacky things and set charset=X-UNKNOWN
-                       $part->charset_set('UTF-8');
-                       $s = eval { $part->body_str };
-
-                       # If forcing charset=UTF-8 failed,
-                       # attach_link will warn further down...
-                       $s = $part->body if $@;
-               } else {
-                       return attach_link($upfx, $ct, $p, $fn);
-               }
-       }
+       return attach_link($upfx, $ct, $p, $fn) unless defined $s;
 
        my @lines = split(/^/m, $s);
        $s = '';
        if (defined($fn) || $depth > 0 || $err) {
+               # badly-encoded message with $err? tell the world about it!
                $s .= attach_link($upfx, $ct, $p, $fn, $err);
                $s .= "\n";
        }