X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Fimap_searchqp.t;h=e2f49e5aa27496290a7e4e4e3f8aa9dfd4c1f78d;hb=7ffa98cbbf5bff8225fdfedb0f2b7c2beb5d0a6f;hp=3e4dde6ffae55556ecd558016bd768430d37538d;hpb=07caa8528db2ac22d81a0763e1cefd59acd827f1;p=public-inbox.git diff --git a/t/imap_searchqp.t b/t/imap_searchqp.t index 3e4dde6f..e2f49e5a 100644 --- a/t/imap_searchqp.t +++ b/t/imap_searchqp.t @@ -1,11 +1,11 @@ #!perl -w -# Copyright (C) 2020 all contributors +# Copyright (C) 2020-2021 all contributors # License: AGPL-3.0+ use strict; -use Test::More; +use v5.10.1; use Time::Local qw(timegm); use PublicInbox::TestCommon; -require_mods(qw(Parse::RecDescent)); +require_mods(qw(-imapd)); use_ok 'PublicInbox::IMAPsearchqp'; use_ok 'PublicInbox::IMAP'; @@ -13,6 +13,9 @@ my $imap = bless {}, 'PublicInbox::IMAP'; my $q; my $parse = sub { PublicInbox::IMAPsearchqp::parse($imap, $_[0]) }; +$q = $parse->(qq{BODY oops}); +is($q->{xap}, 'b:"oops"', 'BODY key supported'); + $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")))', @@ -21,6 +24,18 @@ is($q->{xap}, '(t:"brian" OR (f:"ryan" OR (t:"joe" OR c:"scott")))', $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'); @@ -60,17 +75,17 @@ is($q->{xap}, 'c:"b" d:..19931002', 'compound query w/ parens'); $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'); + is($q->{xap}, qq{f:"z" rt:..$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'); + is($q->{xap}, qq{f:"z" rt:$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'); + is($q->{xap}, qq{f:"z" rt:$t0..$t1}, 'ON Xapian'); } {