From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-3.9 required=3.0 tests=ALL_TRUSTED,BAYES_00, RP_MATCHES_RCVD shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: meta@public-inbox.org Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id E88D320A8A for ; Sat, 30 Apr 2016 02:05:25 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH] searchmsg: ensure long subject lines are not broken Date: Sat, 30 Apr 2016 02:05:25 +0000 Message-Id: <20160430020525.11608-1-e@80x24.org> List-Id: 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' => '', 'References' => '', 'In-Reply-To' => '', @@ -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