user/dev discussion of public-inbox itself
 help / color / mirror / Atom feed
d73600b35d2ab62980c44af496bbaff784c19182 blob 3821 bytes (raw)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
 
#!perl -w
# Copyright (C) 2020 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
use strict;
use Test::More;
use Time::Local qw(timegm);
use PublicInbox::TestCommon;
require_mods(qw(Parse::RecDescent));
use_ok 'PublicInbox::IMAPsearchqp';
use_ok 'PublicInbox::IMAP';

my $imap = bless {}, 'PublicInbox::IMAP';
my $q;
my $parse = sub { PublicInbox::IMAPsearchqp::parse($imap, $_[0]) };

$q = $parse->(qq{OR HEADER TO Brian (OR FROM Ryan (OR TO Joe CC Scott))});
is($q->{sql}, undef, 'not using SQLite for complex query');
is($q->{xap}, '(t:"brian" OR (f:"ryan" OR (t:"joe" OR c:"scott")))',
	'complex query matches Xapian query string');

$q = $parse->(qq{HEADER CC b SENTSINCE 2-Oct-1993});
is($q->{xap}, 'c:"b" d:19931002..', 'compound query');

$q = $parse->(qq{CHARSET UTF-8 From b});
is($q->{xap}, 'f:"b"', 'charset handled');
$q = $parse->(qq{CHARSET WTF-8 From b});
like($q, qr/\ANO \[/, 'bad charset rejected');
{
	# TODO: squelch errors by default? clients could flood logs
	open my $fh, '>:scalar', \(my $buf) or die;
	local *STDERR = $fh;
	$q = $parse->(qq{CHARSET});
}
like($q, qr/\ABAD /, 'bad charset rejected');

$q = $parse->(qq{HEADER CC B (SENTBEFORE 2-Oct-1993)});
is($q->{xap}, 'c:"b" d:..19931002', 'compound query w/ parens');

{ # limit recursion, stack and CPU cycles ain't free
	my $n = 10;
	my $s = ('('x$n ). 'To a' . ( ')'x$n );
	$q = $parse->($s);
	is($q->{xap}, 't:"a"', 'nesting works');
	++$n;
	$s = ('('x$n ). 'To a' . ( ')'x$n );
	my $err = $parse->($s);
	like($err, qr/\ABAD /, 'reject deep nesting');
}

# IMAP has at least 6 ways of interpreting a date
{
	my $t0 = timegm(0, 0, 0, 2, 10 - 1, 1993);
	my $t1 = $t0 + 86399; # no leap (day|second) support
	my $s;

	$q = $parse->($s = qq{SENTBEFORE 2-Oct-1993});
	is_deeply($q->{sql}, \" AND ds <= $t0", 'SENTBEFORE SQL');
	$q = $parse->("FROM z $s");
	is($q->{xap}, 'f:"z" d:..19931002', 'SENTBEFORE Xapian');

	$q = $parse->($s = qq{SENTSINCE 2-Oct-1993});
	is_deeply($q->{sql}, \" AND ds >= $t0", 'SENTSINCE SQL');
	$q = $parse->("FROM z $s");
	is($q->{xap}, 'f:"z" d:19931002..', 'SENTSINCE Xapian');

	$q = $parse->($s = qq{SENTON 2-Oct-1993});
	is_deeply($q->{sql}, \" AND ds >= $t0 AND ds <= $t1", 'SENTON SQL');
	$q = $parse->("FROM z $s");
	is($q->{xap}, 'f:"z" dt:19931002000000..19931002235959',
		'SENTON Xapian');

	$q = $parse->($s = qq{BEFORE 2-Oct-1993});
	is_deeply($q->{sql}, \" AND ts <= $t0", 'BEFORE SQL');
	$q = $parse->("FROM z $s");
	is($q->{xap}, qq{f:"z" ts:..$t0}, 'BEFORE Xapian');

	$q = $parse->($s = qq{SINCE 2-Oct-1993});
	is_deeply($q->{sql}, \" AND ts >= $t0", 'SINCE SQL');
	$q = $parse->("FROM z $s");
	is($q->{xap}, qq{f:"z" ts:$t0..}, 'SINCE Xapian');

	$q = $parse->($s = qq{ON 2-Oct-1993});
	is_deeply($q->{sql}, \" AND ts >= $t0 AND ts <= $t1", 'ON SQL');
	$q = $parse->("FROM z $s");
	is($q->{xap}, qq{f:"z" ts:$t0..$t1}, 'ON Xapian');
}

{
	$imap->{uo2m} = pack('S*', (1..50000));
	$imap->{uid_base} = 50000;
	my $err = $parse->(qq{9:});
	my $s;

	like($err, qr/\ABAD /, 'bad MSN range');
	$err = $parse->(qq{UID 9:});
	like($err, qr/\ABAD /, 'bad UID range');
	$err = $parse->(qq{FROM x UID 9:});
	like($err, qr/\ABAD /, 'bad UID range with Xapian');
	$err = $parse->(qq{FROM x 9:});
	like($err, qr/\ABAD /, 'bad UID range with Xapian');

	$q = $parse->($s = qq{UID 50009:50099});
	is_deeply($q->{sql}, \' AND (num >= 50009 AND num <= 50099)',
		'SQL generated for UID range');
	$q = $parse->("CC x $s");
	is($q->{xap}, qq{c:"x" uid:50009..50099},
		'Xapian generated for UID range');

	$q = $parse->($s = qq{9:99});
	is_deeply($q->{sql}, \' AND (num >= 50009 AND num <= 50099)',
		'SQL generated for MSN range');
	$q = $parse->("CC x $s");
	is($q->{xap}, qq{c:"x" uid:50009..50099},
		'Xapian generated for MSN range');
}

done_testing;
debug log:

solving d73600b3 ...
found d73600b3 in https://80x24.org/public-inbox.git

user/dev discussion of public-inbox itself

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 meta meta/ https://public-inbox.org/meta \
		meta@public-inbox.org
	public-inbox-index meta

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for the project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git