use Test::More;
use PublicInbox::IMAP;
use PublicInbox::IMAPD;
+use PublicInbox::TestCommon;
+require_mods(qw(DBD::SQLite));
+require_git 2.6;
+use POSIX qw(strftime);
-{ # make sure we get '%' globbing right
+{
+ my $parse_date = \&PublicInbox::IMAP::parse_date;
+ is(strftime('%Y-%m-%d', gmtime($parse_date->('02-Oct-1993'))),
+ '1993-10-02', 'parse_date works');
+ is(strftime('%Y-%m-%d', gmtime($parse_date->('2-Oct-1993'))),
+ '1993-10-02', 'parse_date works w/o leading zero');
+
+ is($parse_date->('2-10-1993'), undef, 'bad month');
+
+ # from what I can tell, RFC 3501 says nothing about date-month
+ # case-insensitivity, so be case-sensitive for now
+ is($parse_date->('02-oct-1993'), undef, 'case-sensitive month');
+}
+
+my ($tmpdir, $for_destroy) = tmpdir();
+my $cfgfile = "$tmpdir/config";
+{
+ open my $fh, '>', $cfgfile or BAIL_OUT $!;
+ print $fh <<EOF or BAIL_OUT $!;
+[publicinbox "a"]
+ inboxdir = $tmpdir/a
+ newsgroup = x.y.z
+[publicinbox "b"]
+ inboxdir = $tmpdir/b
+ newsgroup = x.z.y
+[publicinbox "c"]
+ inboxdir = $tmpdir/c
+ newsgroup = IGNORE.THIS
+EOF
+ close $fh or BAIL_OUT $!;
+ local $ENV{PI_CONFIG} = $cfgfile;
+ for my $x (qw(a b c)) {
+ ok(run_script(['-init', '-Lbasic', '-V2', $x, "$tmpdir/$x",
+ "https://example.com/$x", "$x\@example.com"]),
+ "init $x");
+ }
+ my $imapd = PublicInbox::IMAPD->new;
my @w;
local $SIG{__WARN__} = sub { push @w, @_ };
- my @n = map { { newsgroup => $_ } } (qw(x.y.z x.z.y IGNORE.THIS));
- my $self = { imapd => { grouplist => \@n } };
- PublicInbox::IMAPD::refresh_inboxlist($self->{imapd});
+ $imapd->refresh_groups;
+ my $self = { imapd => $imapd };
is(scalar(@w), 1, 'got a warning for upper-case');
like($w[0], qr/IGNORE\.THIS/, 'warned about upper-case');
-
my $res = PublicInbox::IMAP::cmd_list($self, 'tag', 'x', '%');
is(scalar($$res =~ tr/\n/\n/), 2, 'only one result');
like($$res, qr/ x\r\ntag OK/, 'saw expected');
{
my $partial_prepare = \&PublicInbox::IMAP::partial_prepare;
my $x = {};
- my $r = $partial_prepare->($x, [], my $p = 'BODY[9]');
+ my $n = 0;
+ my $r = $partial_prepare->(\$n, $x, [], my $p = 'BODY[9]');
ok($r, $p);
- $r = $partial_prepare->($x, [], $p = 'BODY[9]<5>');
+ $r = $partial_prepare->(\$n, $x, [], $p = 'BODY[9]<5>');
ok($r, $p);
- $r = $partial_prepare->($x, [], $p = 'BODY[9]<5.1>');
+ $r = $partial_prepare->(\$n, $x, [], $p = 'BODY[9]<5.1>');
ok($r, $p);
- $r = $partial_prepare->($x, [], $p = 'BODY[1.1]');
+ $r = $partial_prepare->(\$n, $x, [], $p = 'BODY[1.1]');
ok($r, $p);
- $r = $partial_prepare->($x, [], $p = 'BODY[HEADER.FIELDS (DATE FROM)]');
+ $r = $partial_prepare->(\$n, $x, [],
+ $p = 'BODY[HEADER.FIELDS (DATE FROM)]');
ok($r, $p);
- $r = $partial_prepare->($x, [], $p = 'BODY[HEADER.FIELDS.NOT (TO)]');
+ $r = $partial_prepare->(\$n, $x, [],
+ $p = 'BODY[HEADER.FIELDS.NOT (TO)]');
ok($r, $p);
- $r = $partial_prepare->($x, [], $p = 'BODY[HEDDER.FIELDS.NOT (TO)]');
+ $r = $partial_prepare->(\$n, $x, [],
+ $p = 'BODY[HEDDER.FIELDS.NOT (TO)]');
ok(!$r, "rejected misspelling $p");
- $r = $partial_prepare->($x, [], $p = 'BODY[1.1.HEADER.FIELDS (TO)]');
+ $r = $partial_prepare->(\$n, $x, [],
+ $p = 'BODY[1.1.HEADER.FIELDS (TO)]');
ok($r, $p);
my $partial_body = \&PublicInbox::IMAP::partial_body;
my $partial_hdr_get = \&PublicInbox::IMAP::partial_hdr_get;
}, 'structure matches expected');
}
+{
+ my $fetch_compile = \&PublicInbox::IMAP::fetch_compile;
+ my ($cb, $ops, $partial) = $fetch_compile->(['BODY[]']);
+ is($partial, undef, 'no partial fetch data');
+ is_deeply($ops, [
+ undef, \&PublicInbox::IMAP::op_crlf_bref,
+ 'BODY[]', \&PublicInbox::IMAP::emit_rfc822
+ ], 'proper key and op compiled for BODY[]');
+
+ ($cb, $ops, $partial) = $fetch_compile->(['BODY', 'BODY[]']);
+ is_deeply($ops, [
+ undef, \&PublicInbox::IMAP::op_crlf_bref,
+ 'BODY[]', \&PublicInbox::IMAP::emit_rfc822,
+ undef, \&PublicInbox::IMAP::op_eml_new,
+ 'BODY', \&PublicInbox::IMAP::emit_body,
+ ], 'placed op_eml_new before emit_body');
+}
+
done_testing;