about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/ExtMsg.pm16
-rw-r--r--lib/PublicInbox/HTTPD.pm9
-rw-r--r--lib/PublicInbox/MID.pm25
-rw-r--r--lib/PublicInbox/View.pm5
4 files changed, 36 insertions, 19 deletions
diff --git a/lib/PublicInbox/ExtMsg.pm b/lib/PublicInbox/ExtMsg.pm
index 51e7799d..14d49cc5 100644
--- a/lib/PublicInbox/ExtMsg.pm
+++ b/lib/PublicInbox/ExtMsg.pm
@@ -11,6 +11,7 @@ use warnings;
 use PublicInbox::Hval;
 use PublicInbox::MID qw/mid2path/;
 use PublicInbox::WwwStream;
+our $MIN_PARTIAL_LEN = 16;
 
 # TODO: user-configurable
 our @EXT_URL = (
@@ -30,6 +31,7 @@ sub PARTIAL_MAX () { 100 }
 
 sub search_partial ($$) {
         my ($srch, $mid) = @_;
+        return if length($mid) < $MIN_PARTIAL_LEN;
         my $opt = { limit => PARTIAL_MAX, mset => 2 };
         my @try = ("m:$mid*");
         my $chop = $mid;
@@ -58,12 +60,12 @@ sub search_partial ($$) {
         }
 
         foreach my $m (@try) {
-                my $mset = eval { $srch->query($m, $opt) };
-                if (ref($@) eq 'Search::Xapian::QueryParserError') {
-                        # If Xapian can't handle the wildcard since it
-                        # has too many results.
-                        next;
-                }
+                # If Xapian can't handle the wildcard since it
+                # has too many results.  $@ can be
+                # Search::Xapian::QueryParserError or even:
+                # "something terrible happened at ../Search/Xapian/Enquire.pm"
+                my $mset = eval { $srch->query($m, $opt) } or next;
+
                 my @mids = map {
                         my $doc = $_->get_document;
                         PublicInbox::SearchMsg->load_doc($doc)->mid;
@@ -112,7 +114,7 @@ sub ext_msg {
         }
 
         # can't find a partial match in current inbox, try the others:
-        if (!$n_partial && length($mid) >= 16) {
+        if (!$n_partial && length($mid) >= $MIN_PARTIAL_LEN) {
                 foreach my $ibx (@ibx) {
                         $srch = $ibx->search or next;
                         $mids = search_partial($srch, $mid) or next;
diff --git a/lib/PublicInbox/HTTPD.pm b/lib/PublicInbox/HTTPD.pm
index 38517710..b0bf94ad 100644
--- a/lib/PublicInbox/HTTPD.pm
+++ b/lib/PublicInbox/HTTPD.pm
@@ -29,9 +29,16 @@ sub new {
                 'psgi.run_once'         => Plack::Util::FALSE,
                 'psgi.multithread' => Plack::Util::FALSE,
                 'psgi.multiprocess' => Plack::Util::TRUE,
+
+                # We don't use this anywhere, but we can support
+                # other PSGI apps which might use it:
                 'psgix.input.buffered' => Plack::Util::TRUE,
 
-                # XXX unstable API!
+                # XXX unstable API!, only GitHTTPBackend needs
+                # this to limit git-http-backend(1) parallelism.
+                # The rest of our PSGI code is generic, relying
+                # on "pull" model using "getline" to prevent
+                # over-buffering.
                 'pi-httpd.async' => do {
                         no warnings 'once';
                         *pi_httpd_async
diff --git a/lib/PublicInbox/MID.pm b/lib/PublicInbox/MID.pm
index cd56f272..7f1ab15e 100644
--- a/lib/PublicInbox/MID.pm
+++ b/lib/PublicInbox/MID.pm
@@ -10,6 +10,7 @@ our @EXPORT_OK = qw/mid_clean id_compress mid2path mid_mime mid_escape MID_ESC
         mids references/;
 use URI::Escape qw(uri_escape_utf8);
 use Digest::SHA qw/sha1_hex/;
+require PublicInbox::Address;
 use constant {
         MID_MAX => 40, # SHA-1 hex length # TODO: get rid of this
         MAX_MID_SIZE => 244, # max term size (Xapian limitation) - length('Q')
@@ -79,22 +80,34 @@ sub references ($) {
                         push(@mids, ($v =~ /<([^>]+)>/sg));
                 }
         }
-        uniq_mids(\@mids);
+
+        # old versions of git-send-email would prompt users for
+        # In-Reply-To and users' muscle memory would use 'y' or 'n'
+        # as responses:
+        my %addr = ( y => 1, n => 1 );
+
+        foreach my $f (qw(To From Cc)) {
+                my @v = $hdr->header_raw($f);
+                foreach my $v (@v) {
+                        $addr{$_} = 1 for (PublicInbox::Address::emails($v));
+                }
+        }
+        uniq_mids(\@mids, \%addr);
 }
 
-sub uniq_mids ($) {
-        my ($mids) = @_;
+sub uniq_mids ($;$) {
+        my ($mids, $seen) = @_;
         my @ret;
-        my %seen;
+        $seen ||= {};
         foreach my $mid (@$mids) {
                 $mid =~ tr/\n\t\r//d;
                 if (length($mid) > MAX_MID_SIZE) {
                         warn "Message-ID: <$mid> too long, truncating\n";
                         $mid = substr($mid, 0, MAX_MID_SIZE);
                 }
-                next if $seen{$mid};
+                next if $seen->{$mid};
                 push @ret, $mid;
-                $seen{$mid} = 1;
+                $seen->{$mid} = 1;
         }
         \@ret;
 }
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 5aaa72ba..ca9b9550 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -896,11 +896,6 @@ sub missing_thread {
         PublicInbox::ExtMsg::ext_msg($ctx);
 }
 
-sub _msg_date {
-        my ($hdr) = @_;
-        fmt_ts(msg_datestamp($hdr));
-}
-
 sub fmt_ts { POSIX::strftime('%Y-%m-%d %k:%M', gmtime($_[0])) }
 
 sub dedupe_subject {