]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/View.pm
view: close possible race condition in thread view
[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 $orig_cb = $cb;
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(\$cb, $git, $state, $_, 0) for $th->rootset;
159         }
160         Email::Address->purge_cache;
161
162         # there could be a race due to a message being deleted in git
163         # but still being in the Xapian index:
164         return missing_thread($cb) if ($orig_cb eq $cb);
165
166         my $final_anchor = $state->{anchor_idx};
167         my $next = "<a\nid=\"s$final_anchor\">";
168         $next .= $final_anchor == 1 ? 'only message in' : 'end of';
169         $next .= " thread</a>, back to <a\nhref=\"../../\">index</a>\n";
170         $next .= "download thread: <a\nhref=\"../t.mbox.gz\">mbox.gz</a>";
171         $next .= " / follow: <a\nhref=\"../t.atom\">Atom feed</a>\n\n";
172         $cb->write("<hr />" . PRE_WRAP . $next . $foot .
173                    "</pre></body></html>");
174         $cb->close;
175 }
176
177 sub index_walk {
178         my ($fh, $part, $enc, $part_nr, $fhref, $more) = @_;
179         my $s = add_text_body($enc, $part, $part_nr, $fhref);
180
181         if ($more) {
182                 # drop the remainder of git patches, they're usually better
183                 # to review when the full message is viewed
184                 $s =~ s!^---+\n.*\z!!ms and $$more = 'more...';
185
186                 # Drop signatures
187                 $s =~ s/^-- \n.*\z//ms and $$more = 'more...';
188         }
189
190         # kill any leading or trailing whitespace lines
191         $s =~ s/^\s*$//sgm;
192         $s =~ s/\s+\z//s;
193
194         if ($s ne '') {
195                 # kill per-line trailing whitespace
196                 $s =~ s/[ \t]+$//sgm;
197                 $s .= "\n" unless $s =~ /\n\z/s;
198         }
199         $fh->write($s);
200 }
201
202 sub enc_for {
203         my ($ct, $default) = @_;
204         $default ||= $enc_utf8;
205         defined $ct or return $default;
206         my $ct_parsed = parse_content_type($ct);
207         if ($ct_parsed) {
208                 if (my $charset = $ct_parsed->{attributes}->{charset}) {
209                         my $enc = find_encoding($charset);
210                         return $enc if $enc;
211                 }
212         }
213         $default;
214 }
215
216 sub multipart_text_as_html {
217         my ($mime, $full_pfx, $srch) = @_;
218         my $rv = "";
219         my $part_nr = 0;
220         my $enc = enc_for($mime->header("Content-Type"));
221
222         # scan through all parts, looking for displayable text
223         $mime->walk_parts(sub {
224                 my ($part) = @_;
225                 $rv .= add_text_body($enc, $part, \$part_nr, $full_pfx);
226         });
227         $mime->body_set('');
228         $rv;
229 }
230
231 sub add_filename_line {
232         my ($enc, $fn) = @_;
233         my $len = 72;
234         my $pad = "-";
235         $fn = $enc->decode($fn);
236         $len -= length($fn);
237         $pad x= ($len/2) if ($len > 0);
238         "$pad " . ascii_html($fn) . " $pad\n";
239 }
240
241 my $LINK_RE = qr!\b((?:ftp|https?|nntp)://
242                  [\@:\w\.-]+/
243                  ?[\@\w\+\&\?\.\%\;/#=-]*)!x;
244
245 sub linkify_1 {
246         my ($link_map, $s) = @_;
247         $s =~ s!$LINK_RE!
248                 my $url = $1;
249                 # salt this, as this could be exploited to show
250                 # links in the HTML which don't show up in the raw mail.
251                 my $key = sha1_hex($url . $SALT);
252                 $link_map->{$key} = $url;
253                 'PI-LINK-'. $key;
254         !ge;
255         $s;
256 }
257
258 sub linkify_2 {
259         my ($link_map, $s) = @_;
260
261         # Added "PI-LINK-" prefix to avoid false-positives on git commits
262         $s =~ s!\bPI-LINK-([a-f0-9]{40})\b!
263                 my $key = $1;
264                 my $url = $link_map->{$key};
265                 if (defined $url) {
266                         $url = ascii_html($url);
267                         "<a\nhref=\"$url\">$url</a>";
268                 } else {
269                         # false positive or somebody tried to mess with us
270                         $key;
271                 }
272         !ge;
273         $s;
274 }
275
276 sub flush_quote {
277         my ($quot, $n, $part_nr, $full_pfx, $final) = @_;
278
279         if ($full_pfx) {
280                 if (!$final && scalar(@$quot) <= MAX_INLINE_QUOTED) {
281                         # show quote inline
282                         my %l;
283                         my $rv = join('', map { linkify_1(\%l, $_) } @$quot);
284                         @$quot = ();
285                         $rv = ascii_html($rv);
286                         return linkify_2(\%l, $rv);
287                 }
288
289                 # show a short snippet of quoted text and link to full version:
290                 @$quot = map { s/^(?:>\s*)+//gm; $_ } @$quot;
291                 my $cur = join(' ', @$quot);
292                 @$quot = split(/\s+/, $cur);
293                 $cur = '';
294                 do {
295                         my $tmp = shift(@$quot);
296                         my $len = length($tmp) + length($cur);
297                         if ($len > MAX_TRUNC_LEN) {
298                                 @$quot = ();
299                         } else {
300                                 $cur .= $tmp . ' ';
301                         }
302                 } while (@$quot && length($cur) < MAX_TRUNC_LEN);
303                 @$quot = ();
304                 $cur =~ s/ \z/ .../s;
305                 $cur = ascii_html($cur);
306                 my $nr = ++$$n;
307                 "&gt; [<a\nhref=\"$full_pfx#q${part_nr}_$nr\">$cur</a>]\n";
308         } else {
309                 # show everything in the full version with anchor from
310                 # short version (see above)
311                 my $nr = ++$$n;
312                 my $rv = "";
313                 my %l;
314                 $rv .= join('', map { linkify_1(\%l, $_) } @$quot);
315                 @$quot = ();
316                 $rv = ascii_html($rv);
317                 "<a\nid=q${part_nr}_$nr></a>" . linkify_2(\%l, $rv);
318         }
319 }
320
321 sub add_text_body {
322         my ($enc_msg, $part, $part_nr, $full_pfx) = @_;
323         return '' if $part->subparts;
324
325         my $ct = $part->content_type;
326         # account for filter bugs...
327         if (defined $ct && $ct =~ m!\btext/[xh]+tml\b!i) {
328                 $part->body_set('');
329                 return '';
330         }
331         my $enc = enc_for($ct, $enc_msg);
332         my $n = 0;
333         my $nr = 0;
334         my $s = $part->body;
335         $part->body_set('');
336         $s = $enc->decode($s);
337         my @lines = split(/^/m, $s);
338         $s = '';
339
340         if ($$part_nr > 0) {
341                 my $fn = $part->filename;
342                 defined($fn) or $fn = "part #" . ($$part_nr + 1);
343                 $s .= add_filename_line($enc, $fn);
344         }
345
346         my @quot;
347         while (defined(my $cur = shift @lines)) {
348                 if ($cur !~ /^>/) {
349                         # show the previously buffered quote inline
350                         if (scalar @quot) {
351                                 $s .= flush_quote(\@quot, \$n, $$part_nr,
352                                                   $full_pfx, 0);
353                         }
354
355                         # regular line, OK
356                         my %l;
357                         $cur = linkify_1(\%l, $cur);
358                         $cur = ascii_html($cur);
359                         $s .= linkify_2(\%l, $cur);
360                 } else {
361                         push @quot, $cur;
362                 }
363         }
364         $s .= flush_quote(\@quot, \$n, $$part_nr, $full_pfx, 1) if scalar @quot;
365         $s .= "\n" unless $s =~ /\n\z/s;
366         ++$$part_nr;
367         $s;
368 }
369
370 sub headers_to_html_header {
371         my ($mime, $full_pfx, $ctx) = @_;
372         my $srch = $ctx->{srch} if $ctx;
373         my $rv = "";
374         my @title;
375         my $header_obj = $mime->header_obj;
376         my $mid = $header_obj->header('Message-ID');
377         $mid = PublicInbox::Hval->new_msgid($mid);
378         my $mid_href = $mid->as_href;
379         foreach my $h (qw(From To Cc Subject Date)) {
380                 my $v = $mime->header($h);
381                 defined($v) && ($v ne '') or next;
382                 $v = PublicInbox::Hval->new_oneline($v);
383
384                 if ($h eq 'From') {
385                         my @from = Email::Address->parse($v->raw);
386                         $title[1] = ascii_html($from[0]->name);
387                 } elsif ($h eq 'Subject') {
388                         $title[0] = $v->as_html;
389                         if ($srch) {
390                                 my $p = $full_pfx ? '' : '../';
391                                 $rv .= "$h: <a\nid=\"t\"\nhref=\"${p}t/#u\">";
392                                 $rv .= $v->as_html . "</a>\n";
393                                 next;
394                         }
395                 }
396                 $rv .= "$h: " . $v->as_html . "\n";
397
398         }
399         $rv .= 'Message-ID: &lt;' . $mid->as_html . '&gt; ';
400         my $raw_ref = $full_pfx ? 'raw' : '../raw';
401         $rv .= "(<a\nhref=\"$raw_ref\">raw</a>)\n";
402         if ($srch) {
403                 $rv .= "<a\nhref=\"#r\">References: [see below]</a>\n";
404         } else {
405                 $rv .= _parent_headers_nosrch($header_obj);
406         }
407         $rv .= "\n";
408
409         ("<html><head><title>".  join(' - ', @title) .
410          '</title></head><body>' . PRE_WRAP . $rv);
411 }
412
413 sub thread_inline {
414         my ($dst, $ctx, $cur, $full_pfx) = @_;
415         my $srch = $ctx->{srch};
416         my $mid = mid_compress(mid_clean($cur->header('Message-ID')));
417         my $res = $srch->get_thread($mid);
418         my $nr = $res->{total};
419
420         if ($nr <= 1) {
421                 $$dst .= "\n[no followups, yet]\n";
422                 return;
423         }
424         my $upfx = $full_pfx ? '' : '../';
425
426         $$dst .= "\n\n~$nr messages in thread: ".
427                  "(<a\nhref=\"${upfx}t/#u\">expand</a>)\n";
428         my $subj = $srch->subject_path($cur->header('Subject'));
429         my $state = {
430                 seen => { $subj => 1 },
431                 srch => $srch,
432                 cur => $mid,
433         };
434         for (thread_results(load_results($res))->rootset) {
435                 inline_dump($dst, $state, $upfx, $_, 0);
436         }
437         $state->{next_msg};
438 }
439
440 sub _parent_headers_nosrch {
441         my ($header_obj) = @_;
442         my $rv = '';
443
444         my $irt = $header_obj->header('In-Reply-To');
445         if (defined $irt) {
446                 my $v = PublicInbox::Hval->new_msgid($irt);
447                 my $html = $v->as_html;
448                 my $href = $v->as_href;
449                 $rv .= "In-Reply-To: &lt;";
450                 $rv .= "<a\nhref=\"../$href/\">$html</a>&gt;\n";
451         }
452
453         my $refs = $header_obj->header('References');
454         if ($refs) {
455                 # avoid redundant URLs wasting bandwidth
456                 my %seen;
457                 $seen{mid_clean($irt)} = 1 if defined $irt;
458                 my @refs;
459                 my @raw_refs = ($refs =~ /<([^>]+)>/g);
460                 foreach my $ref (@raw_refs) {
461                         next if $seen{$ref};
462                         $seen{$ref} = 1;
463                         push @refs, linkify_ref($ref);
464                 }
465
466                 if (@refs) {
467                         $rv .= 'References: '. join(' ', @refs) . "\n";
468                 }
469         }
470         $rv;
471 }
472
473 sub html_footer {
474         my ($mime, $standalone, $full_pfx, $ctx) = @_;
475         my %cc; # everyone else
476         my $to; # this is the From address
477
478         foreach my $h (qw(From To Cc)) {
479                 my $v = $mime->header($h);
480                 defined($v) && ($v ne '') or next;
481                 my @addrs = Email::Address->parse($v);
482                 foreach my $recip (@addrs) {
483                         my $address = $recip->address;
484                         my $dst = lc($address);
485                         $cc{$dst} ||= $address;
486                         $to ||= $dst;
487                 }
488         }
489         Email::Address->purge_cache if $standalone;
490
491         my $subj = $mime->header('Subject') || '';
492         $subj = "Re: $subj" unless $subj =~ /\bRe:/i;
493         my $mid = $mime->header('Message-ID');
494         my $irt = uri_escape_utf8($mid);
495         delete $cc{$to};
496         $to = uri_escape_utf8($to);
497         $subj = uri_escape_utf8($subj);
498
499         my $cc = uri_escape_utf8(join(',', sort values %cc));
500         my $href = "mailto:$to?In-Reply-To=$irt&Cc=${cc}&Subject=$subj";
501
502         my $srch = $ctx->{srch} if $ctx;
503         my $upfx = $full_pfx ? '../' : '../../';
504         my $idx = $standalone ? " <a\nhref=\"$upfx\">index</a>" : '';
505         if ($idx && $srch) {
506                 my $next = thread_inline(\$idx, $ctx, $mime, $full_pfx);
507                 $irt = $mime->header('In-Reply-To');
508                 if (defined $irt) {
509                         $irt = PublicInbox::Hval->new_msgid($irt);
510                         $irt = $irt->as_href;
511                         $irt = "<a\nhref=\"$upfx$irt/\">parent</a> ";
512                 } else {
513                         $irt = ' ' x length('parent ');
514                 }
515                 if ($next) {
516                         $irt .= "<a\nhref=\"$upfx$next/\">next</a> ";
517                 } else {
518                         $irt .= '     ';
519                 }
520         } else {
521                 $irt = '';
522         }
523
524         "$irt<a\nhref=\"" . ascii_html($href) . '">reply</a>' . $idx;
525 }
526
527 sub linkify_ref {
528         my $v = PublicInbox::Hval->new_msgid($_[0]);
529         my $html = $v->as_html;
530         my $href = $v->as_href;
531         "&lt;<a\nhref=\"../$href/\">$html</a>&gt;";
532 }
533
534 sub anchor_for {
535         my ($msgid) = @_;
536         my $id = $msgid;
537         if ($id !~ /\A[a-f0-9]{40}\z/) {
538                 $id = mid_compress(mid_clean($id), 1);
539         }
540         'm' . $id;
541 }
542
543 sub thread_html_head {
544         my ($cb, $mime) = @_;
545         $$cb = $$cb->([200, ['Content-Type'=> 'text/html; charset=UTF-8']]);
546
547         my $s = PublicInbox::Hval->new_oneline($mime->header('Subject'));
548         $s = $s->as_html;
549         $$cb->write("<html><head><title>$s</title></head><body>");
550 }
551
552 sub thread_entry {
553         my ($cb, $git, $state, $node, $level) = @_;
554         return unless $node;
555         if (my $mime = $node->message) {
556
557                 # lazy load the full message from mini_mime:
558                 my $path = mid2path(mid_clean($mime->header('Message-ID')));
559                 $mime = eval { Email::MIME->new($git->cat_file("HEAD:$path")) };
560                 if ($mime) {
561                         if ($state->{anchor_idx} == 0) {
562                                 thread_html_head($cb, $mime);
563                         }
564                         index_entry($$cb, $mime, $level, $state);
565                 }
566         }
567         thread_entry($cb, $git, $state, $node->child, $level + 1);
568         thread_entry($cb, $git, $state, $node->next, $level);
569 }
570
571 sub load_results {
572         my ($res) = @_;
573
574         [ map { $_->mini_mime } @{delete $res->{msgs}} ];
575 }
576
577 sub msg_timestamp {
578         my ($mime) = @_;
579         my $ts = eval { str2time($mime->header('Date')) };
580         defined($ts) ? $ts : 0;
581 }
582
583 sub thread_results {
584         my ($msgs) = @_;
585         require PublicInbox::Thread;
586         my $th = PublicInbox::Thread->new(@$msgs);
587         $th->thread;
588         no warnings 'once';
589         $th->order(*PublicInbox::Thread::sort_ts);
590         $th
591 }
592
593 sub missing_thread {
594         my ($cb) = @_;
595         my $title = 'Thread does not exist';
596         $cb->([404, ['Content-Type' => 'text/html']])->write(<<EOF);
597 <html><head><title>$title</title></head><body><pre>$title
598 <a href="../../">Return to index</a></pre></body></html>
599 EOF
600 }
601
602 sub _msg_date {
603         my ($mime) = @_;
604         my $ts = $mime->header('X-PI-TS') || msg_timestamp($mime);
605         POSIX::strftime('%Y-%m-%d %H:%M', gmtime($ts));
606 }
607
608 sub _inline_header {
609         my ($dst, $state, $upfx, $mime, $level) = @_;
610         my $pfx = '  ' x $level;
611
612         my $cur = $state->{cur};
613         my $mid = $mime->header('Message-ID');
614         my $f = $mime->header('X-PI-From');
615         my $d = _msg_date($mime);
616         $f = PublicInbox::Hval->new($f);
617         $d = PublicInbox::Hval->new($d);
618         $f = $f->as_html;
619         $d = $d->as_html . ' UTC';
620         my $midc = mid_compress(mid_clean($mid));
621         if ($cur) {
622                 if ($cur eq $midc) {
623                         delete $state->{cur};
624                         $$dst .= "$pfx` <b><a\nid=\"r\"\nhref=\"#t\">".
625                                  "[this message]</a></b> by $f @ $d\n";
626
627                         return;
628                 }
629         } else {
630                 $state->{next_msg} ||= $midc;
631         }
632
633         # Subject is never undef, this mail was loaded from
634         # our Xapian which would've resulted in '' if it were
635         # really missing (and Filter rejects empty subjects)
636         my $s = $mime->header('Subject');
637         my $h = $state->{srch}->subject_path($s);
638         if ($state->{seen}->{$h}) {
639                 $s = undef;
640         } else {
641                 $state->{seen}->{$h} = 1;
642                 $s = PublicInbox::Hval->new($s);
643                 $s = $s->as_html;
644         }
645         my $m = PublicInbox::Hval->new_msgid($mid);
646         $m = $upfx . '../' . $m->as_href . '/';
647         if (defined $s) {
648                 $$dst .= "$pfx` <a\nhref=\"$m\">$s</a>\n" .
649                          "$pfx  $f @ $d\n";
650         } else {
651                 $$dst .= "$pfx` <a\nhref=\"$m\">$f @ $d</a>\n";
652         }
653 }
654
655 sub inline_dump {
656         my ($dst, $state, $upfx, $node, $level) = @_;
657         return unless $node;
658         return if $state->{stopped};
659         if (my $mime = $node->message) {
660                 _inline_header($dst, $state, $upfx, $mime, $level);
661         }
662         inline_dump($dst, $state, $upfx, $node->child, $level+1);
663         inline_dump($dst, $state, $upfx, $node->next, $level);
664 }
665
666 1;