unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH] searchmsg: ensure long subject lines are not broken
@ 2016-04-30  2:05 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2016-04-30  2:05 UTC (permalink / raw)
  To: meta

Noticed when using a long URL in the subject.
---
 lib/PublicInbox/SearchMsg.pm |  7 ++-----
 t/search.t                   | 25 ++++++++++++++++++++++++-
 2 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/lib/PublicInbox/SearchMsg.pm b/lib/PublicInbox/SearchMsg.pm
index a089915..1244aee 100644
--- a/lib/PublicInbox/SearchMsg.pm
+++ b/lib/PublicInbox/SearchMsg.pm
@@ -148,12 +148,9 @@ sub ensure_metadata {
 sub mini_mime {
 	my ($self) = @_;
 	$self->ensure_metadata;
-	my @hs = (
+	my @h = (
 		'Subject' => $self->subject,
 		'X-PI-From' => $self->from_name,
-	);
-
-	my @h = (
 		# prevent Email::Simple::Creator from running,
 		# this header is useless for threading as we use X-PI-TS
 		# for sorting and display:
@@ -164,7 +161,7 @@ sub mini_mime {
 	if (my $refs = $self->{references}) {
 		push @h, References => $refs;
 	}
-	my $mime = Email::MIME->create(header_str => \@hs, header => \@h);
+	my $mime = Email::MIME->create(header => \@h);
 	my $h = $mime->header_obj;
 
 	# set these headers manually since Encode::encode('MIME-Q', ...)
diff --git a/t/search.t b/t/search.t
index bbf1a89..d5f9d95 100644
--- a/t/search.t
+++ b/t/search.t
@@ -274,10 +274,11 @@ sub filter_mids {
 
 # circular references
 {
+	my $s = 'foo://'. ('Circle' x 15).'/foo';
 	my $doc_id = $rw->add_message(Email::MIME->create(
+		header => [ Subject => $s ],
 		header_str => [
 			Date => 'Sat, 02 Oct 2010 00:00:01 +0000',
-			Subject => 'Circle',
 			'Message-ID' => '<circle@a>',
 			'References' => '<circle@a>',
 			'In-Reply-To' => '<circle@a>',
@@ -289,6 +290,28 @@ sub filter_mids {
 	my $smsg = $rw->lookup_message('circle@a');
 	$smsg->ensure_metadata;
 	is($smsg->references, '', "no references created");
+	my $msg = PublicInbox::SearchMsg->load_doc($smsg->{doc});
+	is($s, $msg->mini_mime->header('Subject'), 'long subject not rewritten');
+}
+
+{
+	my $str = eval {
+		my $mbox = 't/utf8.mbox';
+		open(my $fh, '<', $mbox) or die "failed to open mbox: $mbox\n";
+		local $/;
+		<$fh>
+	};
+	$str =~ s/\AFrom [^\n]+\n//s;
+	my $mime = Email::MIME->new($str);
+	my $doc_id = $rw->add_message($mime);
+	ok($doc_id > 0, 'message indexed doc_id with UTF-8');
+	my $smsg = $rw->lookup_message('testmessage@example.com');
+	my $msg = PublicInbox::SearchMsg->load_doc($smsg->{doc});
+
+	# mini_mime technically not valid (I think),
+	# but good enough for displaying HTML:
+	is($mime->header('Subject'), $msg->mini_mime->header('Subject'),
+		'UTF-8 subject preserved');
 }
 
 done_testing();
-- 
EW


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2016-04-30  2:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-30  2:05 [PATCH] searchmsg: ensure long subject lines are not broken Eric Wong

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).