]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/View.pm
view: change wording to include "thread" in footer
[public-inbox.git] / lib / PublicInbox / View.pm
1 # Copyright (C) 2014, Eric Wong <normalperson@yhbt.net> and all contributors
2 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
3 package PublicInbox::View;
4 use strict;
5 use warnings;
6 use URI::Escape qw/uri_escape_utf8/;
7 use Date::Parse qw/str2time/;
8 use Encode qw/find_encoding/;
9 use Encode::MIME::Header;
10 use Email::MIME::ContentType qw/parse_content_type/;
11 use PublicInbox::Hval;
12 use PublicInbox::MID qw/mid_clean mid_compress mid2path/;
13 use Digest::SHA qw/sha1_hex/;
14 my $SALT = rand;
15 require POSIX;
16
17 # TODO: make these constants tunable
18 use constant MAX_INLINE_QUOTED => 12; # half an 80x24 terminal
19 use constant MAX_TRUNC_LEN => 72;
20 use constant PRE_WRAP => "<pre\nstyle=\"white-space:pre-wrap\">";
21 use constant T_ANCHOR => '#u';
22
23 *ascii_html = *PublicInbox::Hval::ascii_html;
24
25 my $enc_utf8 = find_encoding('UTF-8');
26
27 # public functions:
28 sub msg_html {
29         my ($ctx, $mime, $full_pfx, $footer) = @_;
30         if (defined $footer) {
31                 $footer = "\n" . $footer;
32         } else {
33                 $footer = '';
34         }
35         headers_to_html_header($mime, $full_pfx, $ctx) .
36                 multipart_text_as_html($mime, $full_pfx) .
37                 '</pre><hr />' . PRE_WRAP .
38                 html_footer($mime, 1, $full_pfx, $ctx) .
39                 $footer .
40                 '</pre></body></html>';
41 }
42
43 sub feed_entry {
44         my ($class, $mime, $full_pfx) = @_;
45
46         PRE_WRAP . multipart_text_as_html($mime, $full_pfx) . '</pre>';
47 }
48
49 # this is already inside a <pre>
50 sub index_entry {
51         my ($fh, $mime, $level, $state) = @_;
52         my $midx = $state->{anchor_idx}++;
53         my $ctx = $state->{ctx};
54         my $srch = $ctx->{srch};
55         my ($prev, $next) = ($midx - 1, $midx + 1);
56         my $part_nr = 0;
57         my $enc = enc_for($mime->header("Content-Type"));
58         my $subj = $mime->header('Subject');
59         my $header_obj = $mime->header_obj;
60
61         my $mid_raw = $header_obj->header('Message-ID');
62         my $id = anchor_for($mid_raw);
63         my $seen = $state->{seen};
64         $seen->{$id} = "#$id"; # save the anchor for later
65
66         my $mid = PublicInbox::Hval->new_msgid($mid_raw);
67         my $from = PublicInbox::Hval->new_oneline($mime->header('From'))->raw;
68         my @from = Email::Address->parse($from);
69         $from = $from[0]->name;
70
71         $from = PublicInbox::Hval->new_oneline($from)->as_html;
72         $subj = PublicInbox::Hval->new_oneline($subj)->as_html;
73         my $more = 'permalink';
74         my $root_anchor = $state->{root_anchor};
75         my $path = $root_anchor ? '../../' : '';
76         my $href = $mid->as_href;
77         my $irt = $header_obj->header('In-Reply-To');
78         my ($anchor_idx, $anchor);
79         if (defined $irt) {
80                 $anchor_idx = anchor_for($irt);
81                 $anchor = $seen->{$anchor_idx};
82         }
83         if ($srch) {
84                 $subj = "<a\nhref=\"${path}$href/t/#u\">$subj</a>";
85         }
86         if ($root_anchor && $root_anchor eq $id) {
87                 $subj = "<u\nid=\"u\">$subj</u>";
88         }
89
90         my $ts = _msg_date($mime);
91         my $rv = "<table\nsummary=l$level><tr>";
92         if ($level) {
93                 $rv .= '<td><pre>' . ('  ' x $level) . '</pre></td>';
94         }
95         $rv .= "<td\nid=s$midx>" . PRE_WRAP;
96         $rv .= "<b\nid=\"$id\">$subj</b>\n";
97         $rv .= "- by $from @ $ts UTC - ";
98         $rv .= "<a\nhref=\"#s$next\">next</a>";
99         if ($prev >= 0) {
100                 $rv .= "/<a\nhref=\"#s$prev\">prev</a>";
101         }
102         $fh->write($rv .= "\n\n");
103
104         my ($fhref, $more_ref);
105         my $mhref = "${path}$href/";
106         if ($level > 0) {
107                 $fhref = "${path}$href/f/";
108                 $more_ref = \$more;
109         }
110         # scan through all parts, looking for displayable text
111         $mime->walk_parts(sub {
112                 index_walk($fh, $_[0], $enc, \$part_nr, $fhref, $more_ref);
113         });
114         $mime->body_set('');
115
116         my $txt = "${path}$href/raw";
117         $rv = "\n<a\nhref=\"$mhref\">$more</a> <a\nhref=\"$txt\">raw</a> ";
118         $rv .= html_footer($mime, 0, undef, $ctx);
119
120         if (defined $irt) {
121                 unless (defined $anchor) {
122                         my $v = PublicInbox::Hval->new_msgid($irt);
123                         $v = $v->as_href;
124                         $anchor = "${path}$v/";
125                         $seen->{$anchor_idx} = $anchor;
126                 }
127                 $rv .= " <a\nhref=\"$anchor\">parent</a>";
128         }
129
130         $fh->write($rv .= '</pre></td></tr></table>');
131 }
132
133 sub thread_html {
134         my ($ctx, $foot, $srch) = @_;
135         sub { emit_thread_html($_[0], $ctx, $foot, $srch) }
136 }
137
138 # only private functions below.
139
140 sub emit_thread_html {
141         my ($cb, $ctx, $foot, $srch) = @_;
142         my $mid = mid_compress($ctx->{mid});
143         my $res = $srch->get_thread($mid);
144         my $msgs = load_results($res);
145         my $nr = scalar @$msgs;
146         return missing_thread($cb) if $nr == 0;
147         my $fh = $cb->([200,['Content-Type'=>'text/html; charset=UTF-8']]);
148         my $th = thread_results($msgs);
149         my $state = {
150                 ctx => $ctx,
151                 seen => {},
152                 root_anchor => anchor_for($mid),
153                 anchor_idx => 0,
154         };
155         {
156                 require PublicInbox::GitCatFile;
157                 my $git = PublicInbox::GitCatFile->new($ctx->{git_dir});
158                 thread_entry($fh, $git, $state, $_, 0) for $th->rootset;
159         }
160         my $final_anchor = $state->{anchor_idx};
161         my $next = "<a\nid=\"s$final_anchor\">";
162         $next .= $final_anchor == 1 ? 'only message in' : 'end of';
163         $next .= " thread</a>, back to <a\nhref=\"../../\">index</a>\n";
164         $next .= "download thread: <a\nhref=\"../t.mbox.gz\">mbox.gz</a>";
165         $next .= " / follow: <a\nhref=\"../t.atom\">Atom feed</a>\n\n";
166         $fh->write("<hr />" . PRE_WRAP . $next . $foot .
167                    "</pre></body></html>");
168         $fh->close;
169 }
170
171 sub index_walk {
172         my ($fh, $part, $enc, $part_nr, $fhref, $more) = @_;
173         my $s = add_text_body($enc, $part, $part_nr, $fhref);
174
175         if ($more) {
176                 # drop the remainder of git patches, they're usually better
177                 # to review when the full message is viewed
178                 $s =~ s!^---+\n.*\z!!ms and $$more = 'more...';
179
180                 # Drop signatures
181                 $s =~ s/^-- \n.*\z//ms and $$more = 'more...';
182         }
183
184         # kill any leading or trailing whitespace lines
185         $s =~ s/^\s*$//sgm;
186         $s =~ s/\s+\z//s;
187
188         if ($s ne '') {
189                 # kill per-line trailing whitespace
190                 $s =~ s/[ \t]+$//sgm;
191                 $s .= "\n" unless $s =~ /\n\z/s;
192         }
193         $fh->write($s);
194 }
195
196 sub enc_for {
197         my ($ct, $default) = @_;
198         $default ||= $enc_utf8;
199         defined $ct or return $default;
200         my $ct_parsed = parse_content_type($ct);
201         if ($ct_parsed) {
202                 if (my $charset = $ct_parsed->{attributes}->{charset}) {
203                         my $enc = find_encoding($charset);
204                         return $enc if $enc;
205                 }
206         }
207         $default;
208 }
209
210 sub multipart_text_as_html {
211         my ($mime, $full_pfx, $srch) = @_;
212         my $rv = "";
213         my $part_nr = 0;
214         my $enc = enc_for($mime->header("Content-Type"));
215
216         # scan through all parts, looking for displayable text
217         $mime->walk_parts(sub {
218                 my ($part) = @_;
219                 $rv .= add_text_body($enc, $part, \$part_nr, $full_pfx);
220         });
221         $mime->body_set('');
222         $rv;
223 }
224
225 sub add_filename_line {
226         my ($enc, $fn) = @_;
227         my $len = 72;
228         my $pad = "-";
229         $fn = $enc->decode($fn);
230         $len -= length($fn);
231         $pad x= ($len/2) if ($len > 0);
232         "$pad " . ascii_html($fn) . " $pad\n";
233 }
234
235 my $LINK_RE = qr!\b((?:ftp|https?|nntp)://
236                  [\@:\w\.-]+/
237                  ?[\@\w\+\&\?\.\%\;/#=-]*)!x;
238
239 sub linkify_1 {
240         my ($link_map, $s) = @_;
241         $s =~ s!$LINK_RE!
242                 my $url = $1;
243                 # salt this, as this could be exploited to show
244                 # links in the HTML which don't show up in the raw mail.
245                 my $key = sha1_hex($url . $SALT);
246                 $link_map->{$key} = $url;
247                 'PI-LINK-'. $key;
248         !ge;
249         $s;
250 }
251
252 sub linkify_2 {
253         my ($link_map, $s) = @_;
254
255         # Added "PI-LINK-" prefix to avoid false-positives on git commits
256         $s =~ s!\bPI-LINK-([a-f0-9]{40})\b!
257                 my $key = $1;
258                 my $url = $link_map->{$key};
259                 if (defined $url) {
260                         $url = ascii_html($url);
261                         "<a\nhref=\"$url\">$url</a>";
262                 } else {
263                         # false positive or somebody tried to mess with us
264                         $key;
265                 }
266         !ge;
267         $s;
268 }
269
270 sub flush_quote {
271         my ($quot, $n, $part_nr, $full_pfx, $final) = @_;
272
273         if ($full_pfx) {
274                 if (!$final && scalar(@$quot) <= MAX_INLINE_QUOTED) {
275                         # show quote inline
276                         my %l;
277                         my $rv = join('', map { linkify_1(\%l, $_) } @$quot);
278                         @$quot = ();
279                         $rv = ascii_html($rv);
280                         return linkify_2(\%l, $rv);
281                 }
282
283                 # show a short snippet of quoted text and link to full version:
284                 @$quot = map { s/^(?:>\s*)+//gm; $_ } @$quot;
285                 my $cur = join(' ', @$quot);
286                 @$quot = split(/\s+/, $cur);
287                 $cur = '';
288                 do {
289                         my $tmp = shift(@$quot);
290                         my $len = length($tmp) + length($cur);
291                         if ($len > MAX_TRUNC_LEN) {
292                                 @$quot = ();
293                         } else {
294                                 $cur .= $tmp . ' ';
295                         }
296                 } while (@$quot && length($cur) < MAX_TRUNC_LEN);
297                 @$quot = ();
298                 $cur =~ s/ \z/ .../s;
299                 $cur = ascii_html($cur);
300                 my $nr = ++$$n;
301                 "&gt; [<a\nhref=\"$full_pfx#q${part_nr}_$nr\">$cur</a>]\n";
302         } else {
303                 # show everything in the full version with anchor from
304                 # short version (see above)
305                 my $nr = ++$$n;
306                 my $rv = "";
307                 my %l;
308                 $rv .= join('', map { linkify_1(\%l, $_) } @$quot);
309                 @$quot = ();
310                 $rv = ascii_html($rv);
311                 "<a\nid=q${part_nr}_$nr></a>" . linkify_2(\%l, $rv);
312         }
313 }
314
315 sub add_text_body {
316         my ($enc_msg, $part, $part_nr, $full_pfx) = @_;
317         return '' if $part->subparts;
318
319         my $ct = $part->content_type;
320         # account for filter bugs...
321         if (defined $ct && $ct =~ m!\btext/[xh]+tml\b!i) {
322                 $part->body_set('');
323                 return '';
324         }
325         my $enc = enc_for($ct, $enc_msg);
326         my $n = 0;
327         my $nr = 0;
328         my $s = $part->body;
329         $part->body_set('');
330         $s = $enc->decode($s);
331         my @lines = split(/^/m, $s);
332         $s = '';
333
334         if ($$part_nr > 0) {
335                 my $fn = $part->filename;
336                 defined($fn) or $fn = "part #" . ($$part_nr + 1);
337                 $s .= add_filename_line($enc, $fn);
338         }
339
340         my @quot;
341         while (defined(my $cur = shift @lines)) {
342                 if ($cur !~ /^>/) {
343                         # show the previously buffered quote inline
344                         if (scalar @quot) {
345                                 $s .= flush_quote(\@quot, \$n, $$part_nr,
346                                                   $full_pfx, 0);
347                         }
348
349                         # regular line, OK
350                         my %l;
351                         $cur = linkify_1(\%l, $cur);
352                         $cur = ascii_html($cur);
353                         $s .= linkify_2(\%l, $cur);
354                 } else {
355                         push @quot, $cur;
356                 }
357         }
358         $s .= flush_quote(\@quot, \$n, $$part_nr, $full_pfx, 1) if scalar @quot;
359         $s .= "\n" unless $s =~ /\n\z/s;
360         ++$$part_nr;
361         $s;
362 }
363
364 sub headers_to_html_header {
365         my ($mime, $full_pfx, $ctx) = @_;
366         my $srch = $ctx->{srch} if $ctx;
367         my $rv = "";
368         my @title;
369         my $header_obj = $mime->header_obj;
370         my $mid = $header_obj->header('Message-ID');
371         $mid = PublicInbox::Hval->new_msgid($mid);
372         my $mid_href = $mid->as_href;
373         foreach my $h (qw(From To Cc Subject Date)) {
374                 my $v = $mime->header($h);
375                 defined($v) && ($v ne '') or next;
376                 $v = PublicInbox::Hval->new_oneline($v);
377
378                 if ($h eq 'From') {
379                         my @from = Email::Address->parse($v->raw);
380                         $title[1] = ascii_html($from[0]->name);
381                 } elsif ($h eq 'Subject') {
382                         $title[0] = $v->as_html;
383                         if ($srch) {
384                                 my $p = $full_pfx ? '' : '../';
385                                 $rv .= "$h: <a\nid=\"t\"\nhref=\"${p}t/#u\">";
386                                 $rv .= $v->as_html . "</a>\n";
387                                 next;
388                         }
389                 }
390                 $rv .= "$h: " . $v->as_html . "\n";
391
392         }
393         $rv .= 'Message-ID: &lt;' . $mid->as_html . '&gt; ';
394         my $raw_ref = $full_pfx ? 'raw' : '../raw';
395         $rv .= "(<a\nhref=\"$raw_ref\">raw</a>)\n";
396         if ($srch) {
397                 $rv .= "<a\nhref=\"#r\">References: [see below]</a>\n";
398         } else {
399                 $rv .= _parent_headers_nosrch($header_obj);
400         }
401         $rv .= "\n";
402
403         ("<html><head><title>".  join(' - ', @title) .
404          '</title></head><body>' . PRE_WRAP . $rv);
405 }
406
407 sub thread_inline {
408         my ($dst, $ctx, $cur, $full_pfx) = @_;
409         my $srch = $ctx->{srch};
410         my $mid = mid_compress(mid_clean($cur->header('Message-ID')));
411         my $res = $srch->get_thread($mid);
412         my $nr = $res->{total};
413
414         if ($nr <= 1) {
415                 $$dst .= "\n[no followups, yet]\n";
416                 return;
417         }
418         my $upfx = $full_pfx ? '' : '../';
419
420         $$dst .= "\n\n~$nr messages in thread: ".
421                  "(<a\nhref=\"${upfx}t/#u\">expand</a>)\n";
422         my $subj = $srch->subject_path($cur->header('Subject'));
423         my $state = {
424                 seen => { $subj => 1 },
425                 srch => $srch,
426                 cur => $mid,
427         };
428         for (thread_results(load_results($res))->rootset) {
429                 inline_dump($dst, $state, $upfx, $_, 0);
430         }
431         $state->{next_msg};
432 }
433
434 sub _parent_headers_nosrch {
435         my ($header_obj) = @_;
436         my $rv = '';
437
438         my $irt = $header_obj->header('In-Reply-To');
439         if (defined $irt) {
440                 my $v = PublicInbox::Hval->new_msgid($irt);
441                 my $html = $v->as_html;
442                 my $href = $v->as_href;
443                 $rv .= "In-Reply-To: &lt;";
444                 $rv .= "<a\nhref=\"../$href/\">$html</a>&gt;\n";
445         }
446
447         my $refs = $header_obj->header('References');
448         if ($refs) {
449                 # avoid redundant URLs wasting bandwidth
450                 my %seen;
451                 $seen{mid_clean($irt)} = 1 if defined $irt;
452                 my @refs;
453                 my @raw_refs = ($refs =~ /<([^>]+)>/g);
454                 foreach my $ref (@raw_refs) {
455                         next if $seen{$ref};
456                         $seen{$ref} = 1;
457                         push @refs, linkify_ref($ref);
458                 }
459
460                 if (@refs) {
461                         $rv .= 'References: '. join(' ', @refs) . "\n";
462                 }
463         }
464         $rv;
465 }
466
467 sub html_footer {
468         my ($mime, $standalone, $full_pfx, $ctx) = @_;
469         my %cc; # everyone else
470         my $to; # this is the From address
471
472         foreach my $h (qw(From To Cc)) {
473                 my $v = $mime->header($h);
474                 defined($v) && ($v ne '') or next;
475                 my @addrs = Email::Address->parse($v);
476                 foreach my $recip (@addrs) {
477                         my $address = $recip->address;
478                         my $dst = lc($address);
479                         $cc{$dst} ||= $address;
480                         $to ||= $dst;
481                 }
482         }
483         Email::Address->purge_cache if $standalone;
484
485         my $subj = $mime->header('Subject') || '';
486         $subj = "Re: $subj" unless $subj =~ /\bRe:/i;
487         my $mid = $mime->header('Message-ID');
488         my $irt = uri_escape_utf8($mid);
489         delete $cc{$to};
490         $to = uri_escape_utf8($to);
491         $subj = uri_escape_utf8($subj);
492
493         my $cc = uri_escape_utf8(join(',', sort values %cc));
494         my $href = "mailto:$to?In-Reply-To=$irt&Cc=${cc}&Subject=$subj";
495
496         my $srch = $ctx->{srch} if $ctx;
497         my $upfx = $full_pfx ? '../' : '../../';
498         my $idx = $standalone ? " <a\nhref=\"$upfx\">index</a>" : '';
499         if ($idx && $srch) {
500                 my $next = thread_inline(\$idx, $ctx, $mime, $full_pfx);
501                 $irt = $mime->header('In-Reply-To');
502                 if (defined $irt) {
503                         $irt = PublicInbox::Hval->new_msgid($irt);
504                         $irt = $irt->as_href;
505                         $irt = "<a\nhref=\"$upfx$irt/\">parent</a> ";
506                 } else {
507                         $irt = ' ' x length('parent ');
508                 }
509                 if ($next) {
510                         $irt .= "<a\nhref=\"$upfx$next/\">next</a> ";
511                 } else {
512                         $irt .= '     ';
513                 }
514         } else {
515                 $irt = '';
516         }
517
518         "$irt<a\nhref=\"" . ascii_html($href) . '">reply</a>' . $idx;
519 }
520
521 sub linkify_ref {
522         my $v = PublicInbox::Hval->new_msgid($_[0]);
523         my $html = $v->as_html;
524         my $href = $v->as_href;
525         "&lt;<a\nhref=\"../$href/\">$html</a>&gt;";
526 }
527
528 sub anchor_for {
529         my ($msgid) = @_;
530         my $id = $msgid;
531         if ($id !~ /\A[a-f0-9]{40}\z/) {
532                 $id = mid_compress(mid_clean($id), 1);
533         }
534         'm' . $id;
535 }
536
537 sub thread_html_head {
538         my ($mime) = @_;
539         my $s = PublicInbox::Hval->new_oneline($mime->header('Subject'));
540         $s = $s->as_html;
541         "<html><head><title>$s</title></head><body>";
542 }
543
544 sub thread_entry {
545         my ($fh, $git, $state, $node, $level) = @_;
546         return unless $node;
547         if (my $mime = $node->message) {
548
549                 # lazy load the full message from mini_mime:
550                 my $path = mid2path(mid_clean($mime->header('Message-ID')));
551                 $mime = eval { Email::MIME->new($git->cat_file("HEAD:$path")) };
552                 if ($mime) {
553                         if ($state->{anchor_idx} == 0) {
554                                 $fh->write(thread_html_head($mime));
555                         }
556                         index_entry($fh, $mime, $level, $state);
557                 }
558         }
559         thread_entry($fh, $git, $state, $node->child, $level + 1);
560         thread_entry($fh, $git, $state, $node->next, $level);
561 }
562
563 sub load_results {
564         my ($res) = @_;
565
566         [ map { $_->mini_mime } @{delete $res->{msgs}} ];
567 }
568
569 sub msg_timestamp {
570         my ($mime) = @_;
571         my $ts = eval { str2time($mime->header('Date')) };
572         defined($ts) ? $ts : 0;
573 }
574
575 sub thread_results {
576         my ($msgs) = @_;
577         require PublicInbox::Thread;
578         my $th = PublicInbox::Thread->new(@$msgs);
579         $th->thread;
580         no warnings 'once';
581         $th->order(*PublicInbox::Thread::sort_ts);
582         $th
583 }
584
585 sub missing_thread {
586         my ($cb) = @_;
587         my $title = 'Thread does not exist';
588         $cb->([404, ['Content-Type' => 'text/html']])->write(<<EOF);
589 <html><head><title>$title</title></head><body><pre>$title
590 <a href="../../">Return to index</a></pre></body></html>
591 EOF
592 }
593
594 sub _msg_date {
595         my ($mime) = @_;
596         my $ts = $mime->header('X-PI-TS') || msg_timestamp($mime);
597         POSIX::strftime('%Y-%m-%d %H:%M', gmtime($ts));
598 }
599
600 sub _inline_header {
601         my ($dst, $state, $upfx, $mime, $level) = @_;
602         my $pfx = '  ' x $level;
603
604         my $cur = $state->{cur};
605         my $mid = $mime->header('Message-ID');
606         my $f = $mime->header('X-PI-From');
607         my $d = _msg_date($mime);
608         $f = PublicInbox::Hval->new($f);
609         $d = PublicInbox::Hval->new($d);
610         $f = $f->as_html;
611         $d = $d->as_html . ' UTC';
612         my $midc = mid_compress(mid_clean($mid));
613         if ($cur) {
614                 if ($cur eq $midc) {
615                         delete $state->{cur};
616                         $$dst .= "$pfx` <b><a\nid=\"r\"\nhref=\"#t\">".
617                                  "[this message]</a></b> by $f @ $d\n";
618
619                         return;
620                 }
621         } else {
622                 $state->{next_msg} ||= $midc;
623         }
624
625         # Subject is never undef, this mail was loaded from
626         # our Xapian which would've resulted in '' if it were
627         # really missing (and Filter rejects empty subjects)
628         my $s = $mime->header('Subject');
629         my $h = $state->{srch}->subject_path($s);
630         if ($state->{seen}->{$h}) {
631                 $s = undef;
632         } else {
633                 $state->{seen}->{$h} = 1;
634                 $s = PublicInbox::Hval->new($s);
635                 $s = $s->as_html;
636         }
637         my $m = PublicInbox::Hval->new_msgid($mid);
638         $m = $upfx . '../' . $m->as_href . '/';
639         if (defined $s) {
640                 $$dst .= "$pfx` <a\nhref=\"$m\">$s</a>\n" .
641                          "$pfx  $f @ $d\n";
642         } else {
643                 $$dst .= "$pfx` <a\nhref=\"$m\">$f @ $d</a>\n";
644         }
645 }
646
647 sub inline_dump {
648         my ($dst, $state, $upfx, $node, $level) = @_;
649         return unless $node;
650         return if $state->{stopped};
651         if (my $mime = $node->message) {
652                 _inline_header($dst, $state, $upfx, $mime, $level);
653         }
654         inline_dump($dst, $state, $upfx, $node->child, $level+1);
655         inline_dump($dst, $state, $upfx, $node->next, $level);
656 }
657
658 1;