From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Cc: Eric Wong <e@80x24.org>
Subject: [RFC 07/11] view: hoist out index_walk function
Date: Sun, 16 Aug 2015 08:37:55 +0000 [thread overview]
Message-ID: <1439714279-21923-8-git-send-email-e@80x24.org> (raw)
In-Reply-To: <1439714279-21923-1-git-send-email-e@80x24.org>
We will reuse it for thread views when powered by Xapian.
---
lib/PublicInbox/View.pm | 77 +++++++++++++++++++++++++++----------------------
1 file changed, 42 insertions(+), 35 deletions(-)
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index fe4f2df..66d3bcb 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -92,41 +92,9 @@ sub index_entry {
my $more = 'message';
# scan through all parts, looking for displayable text
$mime->walk_parts(sub {
- my ($part) = @_;
- return if $part->subparts; # walk_parts already recurses
- my $ct = $part->content_type;
-
- # account for filter bugs...
- return if defined $ct && $ct =~ m!\btext/[xh]+tml\b!i;
-
- my $enc = enc_for($ct, $enc_msg);
-
- if ($part_nr > 0) {
- my $fn = $part->filename;
- defined($fn) or $fn = "part #" . ($part_nr + 1);
- $rv .= $pfx . add_filename_line($enc->decode($fn));
- }
-
- my $s = add_text_body_short($enc, $part, $part_nr, $fhref);
-
- # drop the remainder of git patches, they're usually better
- # to review when the full message is viewed
- $s =~ s!^---+\n.*\z!!ms and $more = 'more...';
-
- # Drop signatures
- $s =~ s/^-- \n.*\z//ms and $more = 'more...';
-
- # kill any leading or trailing whitespace
- $s =~ s/\A\s+//s;
- $s =~ s/\s+\z//s;
-
- if (length $s) {
- # add prefix:
- $s =~ s/^/$pfx/sgm;
-
- $rv .= $s . "\n";
- }
- ++$part_nr;
+ $rv .= index_walk($_[0], $pfx, $enc_msg, $part_nr, $fhref,
+ \$more);
+ $part_nr++;
});
$rv .= "\n$pfx<a\nhref=\"$mhref\">$more</a> ";
@@ -150,6 +118,45 @@ sub index_entry {
# only private functions below.
+sub index_walk {
+ my ($part, $pfx, $enc_msg, $part_nr, $fhref, $more) = @_;
+ my $rv = '';
+ return $rv if $part->subparts; # walk_parts already recurses
+ my $ct = $part->content_type;
+
+ # account for filter bugs...
+ return if defined $ct && $ct =~ m!\btext/[xh]+tml\b!i;
+
+ my $enc = enc_for($ct, $enc_msg);
+
+ if ($part_nr > 0) {
+ my $fn = $part->filename;
+ defined($fn) or $fn = "part #" . ($part_nr + 1);
+ $rv .= $pfx . add_filename_line($enc->decode($fn));
+ }
+
+ my $s = add_text_body_short($enc, $part, $part_nr, $fhref);
+
+ # drop the remainder of git patches, they're usually better
+ # to review when the full message is viewed
+ $s =~ s!^---+\n.*\z!!ms and $$more = 'more...';
+
+ # Drop signatures
+ $s =~ s/^-- \n.*\z//ms and $$more = 'more...';
+
+ # kill any leading or trailing whitespace
+ $s =~ s/\A\s+//s;
+ $s =~ s/\s+\z//s;
+
+ if (length $s) {
+ # add prefix:
+ $s =~ s/^/$pfx/sgm;
+
+ $rv .= $s . "\n";
+ }
+ $rv;
+}
+
sub enc_for {
my ($ct, $default) = @_;
$default ||= $enc_utf8;
--
EW
next prev parent reply other threads:[~2015-08-16 8:38 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-16 8:37 [RFC 0/11] work-in-progress search branch updated Eric Wong
2015-08-16 8:37 ` [RFC 01/11] search: implement index_sync to fixup indexer Eric Wong
2015-08-16 8:37 ` [RFC 02/11] extract redundant Message-ID handling code Eric Wong
2015-08-16 8:37 ` [RFC 03/11] search: make search results more OO Eric Wong
2015-08-16 8:37 ` [RFC 04/11] view: display replies in per-message view Eric Wong
2015-08-16 8:37 ` [RFC 05/11] thread: common sorting code Eric Wong
2015-08-16 8:37 ` [RFC 06/11] view: reply threading adjustment Eric Wong
2015-08-16 8:37 ` Eric Wong [this message]
2015-08-16 9:23 ` [RFC 07/11] view: hoist out index_walk function Eric Wong
2015-08-16 8:37 ` [RFC 08/11] www: /t/$MESSAGE_ID.html for threads Eric Wong
2015-08-16 8:37 ` [RFC 09/11] search: remove unnecessary xpfx export Eric Wong
2015-08-16 8:37 ` [RFC 10/11] implement /s/$SUBJECT_PATH.html lookups Eric Wong
2015-08-16 8:37 ` [RFC 11/11] SearchMsg: ensure metadata for ghost messages mid Eric Wong
2015-08-16 8:55 ` [RFC 12/11] view: deduplicate common code for loading search results Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1439714279-21923-8-git-send-email-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).