about summary refs log tree commit homepage
path: root/lib/PublicInbox/SearchMsg.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-08-15 09:28:34 +0000
committerEric Wong <e@80x24.org>2015-08-15 23:34:34 +0000
commit226657eb31e326cc8329229e8ba0f63ff4c75083 (patch)
treeec6afeed7dde21b1bda566ad9bf29eb508139fdd /lib/PublicInbox/SearchMsg.pm
parent7edf30e5349ab5566815e5050e9ba0f53e1d0bb9 (diff)
downloadpublic-inbox-226657eb31e326cc8329229e8ba0f63ff4c75083.tar.gz
This can be used to quickly scan for replies in a message without
displaying an entire thread.
Diffstat (limited to 'lib/PublicInbox/SearchMsg.pm')
-rw-r--r--lib/PublicInbox/SearchMsg.pm30
1 files changed, 28 insertions, 2 deletions
diff --git a/lib/PublicInbox/SearchMsg.pm b/lib/PublicInbox/SearchMsg.pm
index 619a19d4..550521aa 100644
--- a/lib/PublicInbox/SearchMsg.pm
+++ b/lib/PublicInbox/SearchMsg.pm
@@ -6,9 +6,12 @@ use strict;
 use warnings;
 use Search::Xapian;
 use Email::Address qw//;
+use Email::Simple qw//;
 use POSIX qw//;
 use Date::Parse qw/str2time/;
 use PublicInbox::MID qw/mid_clean mid_compressed/;
+use Encode qw/find_encoding/;
+my $enc_utf8 = find_encoding('UTF-8');
 our $PFX2TERM_RE = undef;
 
 sub new {
@@ -26,7 +29,9 @@ sub wrap {
 
 sub load_doc {
         my ($class, $doc) = @_;
-        my ($mid, $subj, $from, $date) = split(/\n/, $doc->get_data);
+        my $data = $doc->get_data;
+        $data = $enc_utf8->decode($data);
+        my ($mid, $subj, $from, $date) = split(/\n/, $data);
         bless {
                 doc => $doc,
                 mid => $mid,
@@ -52,11 +57,11 @@ sub from {
         my @from;
 
         if ($from) {
+                $from =~ tr/\n/ /;
                 @from = Email::Address->parse($from);
                 $self->{from} = $from[0];
                 $from = $from[0]->name;
         }
-        $from =~ tr/\n/ /;
         $self->{from_name} = $from;
         $self->{from};
 }
@@ -122,6 +127,27 @@ sub ensure_metadata {
         }
 }
 
+# for threading only
+sub mini_mime {
+        my ($self) = @_;
+        $self->ensure_metadata;
+        my @h = (
+                Subject => $self->subject,
+                'X-PI-From' => $self->from_name,
+                'X-PI-Date' => $self->date,
+                'X-PI-TS' => $self->ts,
+                'Message-ID' => "<$self->{mid}>",
+        );
+        if (my $refs = $self->{references}) {
+                push @h, References => '<' . join('> <', @$refs) . '>';
+        }
+        if (my $irt = $self->{inreplyto}) {
+                push @h, 'In-Reply-To' => "<$irt>";
+        }
+
+        Email::MIME->create(header_str => \@h);
+}
+
 sub mid {
         my ($self, $mid) = @_;