2 # Copyright (C) 2021 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use strict; use v5.10.1; use PublicInbox::TestCommon;
6 my $doc1 = eml_load('t/plack-qp.eml');
7 $doc1->header_set('Date', PublicInbox::Smsg::date({ds => time - (86400 * 5)}));
8 my $doc2 = eml_load('t/utf8.eml');
9 $doc2->header_set('Date', PublicInbox::Smsg::date({ds => time - (86400 * 4)}));
12 my $home = $ENV{HOME};
13 my $in = $doc1->as_string;
14 lei_ok [qw(import -q -F eml -)], undef, { 0 => \$in, %$lei_opt };
15 lei_ok qw(q -q --save z:0.. d:last.week..), '-o', "$home/md/";
16 my %before = map { $_ => 1 } glob("$home/md/cur/*");
17 is_deeply(eml_load((keys %before)[0]), $doc1, 'doc1 matches');
19 my @s = glob("$home/.local/share/lei/saved-searches/md-*");
20 is(scalar(@s), 1, 'got one saved search');
21 my $cfg = PublicInbox::Config->new("$s[0]/lei.saved-search");
22 is_deeply($cfg->{'lei.q'}, ['z:0..', 'd:last.week..'],
23 'store relative time, not parsed (absolute) timestamp');
25 # ensure "lei up" works, since it compliments "lei q --save"
26 $in = $doc2->as_string;
27 lei_ok [qw(import -q -F eml -)], undef, { 0 => \$in, %$lei_opt };
28 lei_ok qw(up -q), $s[0];
29 my %after = map { $_ => 1 } glob("$home/md/cur/*");
30 is(delete $after{(keys(%before))[0]}, 1, 'original message kept');
31 is(scalar(keys %after), 1, 'one new message added');
32 is_deeply(eml_load((keys %after)[0]), $doc2, 'doc2 matches');
35 lei_ok [qw(q --save - -o), "mboxcl2:mbcl2" ],
36 undef, { -C => $home, %$lei_opt, 0 => \'d:last.week..'};
37 @s = glob("$home/.local/share/lei/saved-searches/mbcl2-*");
38 $cfg = PublicInbox::Config->new("$s[0]/lei.saved-search");
39 is_deeply $cfg->{'lei.q'}, 'd:last.week..',
40 'q --stdin stores relative time';