about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/Git.pm43
-rw-r--r--lib/PublicInbox/NNTP.pm27
-rw-r--r--lib/PublicInbox/SearchIdx.pm6
-rw-r--r--lib/PublicInbox/SearchMsg.pm6
4 files changed, 45 insertions, 37 deletions
diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm
index 68445b3c..6a87661c 100644
--- a/lib/PublicInbox/Git.pm
+++ b/lib/PublicInbox/Git.pm
@@ -145,41 +145,24 @@ again:
                 fail($self, "Unexpected result from git cat-file: $head");
 
         my $size = $1;
-        my $ref_type = $ref ? ref($ref) : '';
-
         my $rv;
         my $left = $size;
-        $$ref = $size if ($ref_type eq 'SCALAR');
-        my $cb_err;
-
-        if ($ref_type eq 'CODE') {
-                $rv = eval { $ref->($in, \$left) };
-                $cb_err = $@;
-                # drain the rest
-                my $max = 8192;
-                while ($left > 0) {
-                        my $r = read($in, my $x, $left > $max ? $max : $left);
-                        defined($r) or fail($self, "read failed: $!");
-                        $r == 0 and fail($self, 'exited unexpectedly');
-                        $left -= $r;
-                }
-        } else {
-                my $offset = 0;
-                my $buf = '';
-                while ($left > 0) {
-                        my $r = read($in, $buf, $left, $offset);
-                        defined($r) or fail($self, "read failed: $!");
-                        $r == 0 and fail($self, 'exited unexpectedly');
-                        $left -= $r;
-                        $offset += $r;
-                }
-                $rv = \$buf;
+        $$ref = $size if $ref;
+
+        my $offset = 0;
+        my $buf = '';
+        while ($left > 0) {
+                my $r = read($in, $buf, $left, $offset);
+                defined($r) or fail($self, "read failed: $!");
+                $r == 0 and fail($self, 'exited unexpectedly');
+                $left -= $r;
+                $offset += $r;
         }
+        $rv = \$buf;
 
-        my $r = read($in, my $buf, 1);
+        my $r = read($in, my $lf, 1);
         defined($r) or fail($self, "read failed: $!");
-        fail($self, 'newline missing after blob') if ($r != 1 || $buf ne "\n");
-        die $cb_err if $cb_err;
+        fail($self, 'newline missing after blob') if ($r != 1 || $lf ne "\n");
 
         $rv;
 }
diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index be80560f..8a31b910 100644
--- a/lib/PublicInbox/NNTP.pm
+++ b/lib/PublicInbox/NNTP.pm
@@ -434,6 +434,26 @@ sub xref ($$$$) {
 sub set_nntp_headers ($$$$$) {
         my ($self, $hdr, $ng, $n, $mid) = @_;
 
+        # why? leafnode requires a Path: header for some inexplicable
+        # reason.  We'll fake the shortest one possible.
+        $hdr->header_set('Path', 'y');
+
+        # leafnode (and maybe other NNTP clients) have trouble dealing
+        # with v2 messages which have multiple Message-IDs (either due
+        # to our own content-based dedupe or buggy git-send-email versions).
+        my @mids = $hdr->header('Message-ID');
+        if (scalar(@mids) > 1) {
+                my $mid0 = "<$mid>";
+                $hdr->header_set('Message-ID', $mid0);
+                my @alt = $hdr->header('X-Alt-Message-ID');
+                my %seen = map { $_ => 1 } (@alt, $mid0);
+                foreach my $m (@mids) {
+                        next if $seen{$m}++;
+                        push @alt, $m;
+                }
+                $hdr->header_set('X-Alt-Message-ID', @alt);
+        }
+
         # clobber some
         my $xref = xref($self, $ng, $n, $mid);
         $hdr->header_set('Xref', $xref);
@@ -515,6 +535,13 @@ sub _header ($) {
         my $hdr = $_[0]->header_obj->as_string;
         utf8::encode($hdr);
         $hdr =~ s/(?<!\r)\n/\r\n/sg;
+
+        # for leafnode compatibility, we need to ensure Message-ID headers
+        # are only a single line.  We can't subclass Email::Simple::Header
+        # and override _default_fold_at in here, either; since that won't
+        # affect messages already in the archive.
+        $hdr =~ s/^(Message-ID:)[ \t]*\r\n[ \t]+([^\r]+)\r\n/$1 $2\r\n/igsm;
+
         $hdr
 }
 
diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm
index 99856286..7cd67f12 100644
--- a/lib/PublicInbox/SearchIdx.pm
+++ b/lib/PublicInbox/SearchIdx.pm
@@ -117,7 +117,11 @@ sub _xdb_acquire {
                 }
         }
         return unless defined $flag;
-        $self->{xdb} = Search::Xapian::WritableDatabase->new($dir, $flag);
+        my $xdb = eval { Search::Xapian::WritableDatabase->new($dir, $flag) };
+        if ($@) {
+                die "Failed opening $dir: ", $@;
+        }
+        $self->{xdb} = $xdb;
 }
 
 sub add_val ($$$) {
diff --git a/lib/PublicInbox/SearchMsg.pm b/lib/PublicInbox/SearchMsg.pm
index 5f3c8af8..96a26b15 100644
--- a/lib/PublicInbox/SearchMsg.pm
+++ b/lib/PublicInbox/SearchMsg.pm
@@ -25,12 +25,6 @@ sub wrap {
         bless { mid => $mid }, $class;
 }
 
-sub get {
-        my ($class, $head, $db, $mid) = @_;
-        my $doc_id = $head->get_docid;
-        load_expand(wrap($class, $mid), $db->get_document($doc_id));
-}
-
 sub get_val ($$) {
         my ($doc, $col) = @_;
         Search::Xapian::sortable_unserialise($doc->get_value($col));