use PublicInbox::Hval;
use PublicInbox::MID qw/mid2path/;
use PublicInbox::WwwStream;
+our $MIN_PARTIAL_LEN = 16;
# TODO: user-configurable
our @EXT_URL = (
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;
}
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;
}
# 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;
'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
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')
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;
}
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 {
$mime->header_set('Message-ID', "<hello\tworld>");
is_deeply(mids($mime->header_obj), ['helloworld'],
'drop \t in Message-ID');
+
+ $mime->header_set('To', 'u@example.com');
+ $mime->header_set('References', '<hello> <world> <n> <u@example.com>');
+ is_deeply(references($mime->header_obj), [qw(hello world)]);
}
done_testing();