]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/imap.t
search: index byte size of a message for IMAP search
[public-inbox.git] / t / imap.t
index aa262a196329f49d79808c7b4c951a6fb5ecc81f..47e86ef42c79d305a11e4c21eac34a16c8a9eb4f 100644 (file)
--- a/t/imap.t
+++ b/t/imap.t
@@ -6,16 +6,54 @@ use strict;
 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');