if ($was_ghost) {
$doc_id = $smsg->doc_id;
- $self->link_message($smsg, 0);
+ $self->link_message($smsg, $smsg->thread_id);
$doc->set_data($smsg->to_doc_data);
$db->replace_document($doc_id, $doc);
} else {
- $self->link_message($smsg, 0);
+ $self->link_message($smsg);
$doc->set_data($smsg->to_doc_data);
$doc_id = $db->add_document($doc);
}
}
sub link_message {
- my ($self, $smsg, $is_ghost) = @_;
-
- if ($is_ghost) {
- $smsg->ensure_metadata;
- } else {
- $self->link_message_to_parents($smsg);
- }
-}
-
-sub link_message_to_parents {
- my ($self, $smsg) = @_;
+ my ($self, $smsg, $old_tid) = @_;
my $doc = $smsg->{doc};
my $mid = $smsg->mid;
my $mime = $smsg->mime;
# but we can never trust clients to do the right thing
my $ref = shift @refs;
$tid = $self->_resolve_mid_to_tid($ref);
+ $self->merge_threads($tid, $old_tid) if defined $old_tid;
# the rest of the refs should point to this tid:
foreach $ref (@refs) {
my ($git, $blob, $sizeref) = @_;
my $mime = eval {
my $str = $git->cat_file($blob, $sizeref);
+ # fixup bugs from import:
+ $$str =~ s/\A[\r\n]*From [^\r\n]*\r?\n//s;
Email::MIME->new($str);
};
$@ ? undef : $mime;
}
sub create_ghost {
- my ($self, $mid, $tid) = @_;
-
- $tid = $self->next_thread_id unless defined $tid;
+ my ($self, $mid) = @_;
+ my $tid = $self->next_thread_id;
my $doc = Search::Xapian::Document->new;
$doc->add_term(xpfx('mid') . $mid);
$doc->add_term(xpfx('thread') . $tid);
$doc->add_term(xpfx('type') . 'ghost');
my $smsg = PublicInbox::SearchMsg->wrap($doc, $mid);
- $self->link_message($smsg, 1);
$self->{xdb}->add_document($doc);
$smsg;