]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei: favor "keywords" over "flags", test --no-kw
authorEric Wong <e@80x24.org>
Sat, 6 Feb 2021 12:18:29 +0000 (12:18 +0000)
committerEric Wong <e@80x24.org>
Sun, 7 Feb 2021 03:34:32 +0000 (03:34 +0000)
JMAP brain says "keywords", IMAP brain says "flags";
JMAP brain wins today.

Since "keywords" is a bit long, support "kw" as a shortcut since
there's no conflict and "kw:" will be our search prefix for
looking up messages by keyword.

lib/PublicInbox/LEI.pm
lib/PublicInbox/LeiImport.pm
t/lei.t

index 682d1bd1846e1561c489adb259909948c6737473..b058b533c97298c144bd68b9a97c13a519da4ac7 100644 (file)
@@ -131,7 +131,7 @@ our %CMD = ( # sorted in order of importance/use:
        'exclude mail matching From: or thread from non-Message-ID searches',
        qw(stdin| thread|t from|f=s mid=s oid=s) ],
 'mark' => [ 'MESSAGE_FLAGS...',
-       'set/unset flags on message(s) from stdin',
+       'set/unset keywords on message(s) from stdin',
        qw(stdin| oid=s exact by-mid|mid:s) ],
 'forget' => [ '[--stdin|--oid=OID|--by-mid=MID]',
        "exclude message(s) on stdin from `q' search results",
@@ -152,7 +152,8 @@ our %CMD = ( # sorted in order of importance/use:
 
 'add-watch' => [ '[URL_OR_PATHNAME]',
                'watch for new messages and flag changes',
-       qw(import! flags! interval=s recursive|r exclude=s include=s) ],
+       qw(import! kw|keywords|flags! interval=s recursive|r
+       exclude=s include=s) ],
 'ls-watch' => [ '[FILTER...]', 'list active watches with numbers and status',
                qw(format|f=s z) ],
 'pause-watch' => [ '[WATCH_NUMBER_OR_FILTER]', qw(all local remote) ],
@@ -163,7 +164,7 @@ our %CMD = ( # sorted in order of importance/use:
 'import' => [ 'URLS_OR_PATHNAMES...|--stdin',
        'one-time import/update from URL or filesystem',
        qw(stdin| offset=i recursive|r exclude=s include|I=s
-       format|f=s flags!),
+       format|f=s kw|keywords|flags!),
        ],
 
 'config' => [ '[...]', sub {
index 4a9af8a75ed6d9a397a7357f79f148494c72e632..2c7cbf2bc96bb8bac87cdce6ed4b8cb5a4df3638 100644 (file)
@@ -26,7 +26,7 @@ sub call { # the main "lei import" method
        my ($cls, $lei, @argv) = @_;
        my $sto = $lei->_lei_store(1);
        $sto->write_prepare($lei);
-       $lei->{opt}->{flags} //= 1;
+       $lei->{opt}->{kw} //= 1;
        my $fmt = $lei->{opt}->{'format'};
        my $self = $lei->{imp} = bless {}, $cls;
        return $lei->fail('--format unspecified') if !$fmt;
@@ -63,7 +63,7 @@ sub ipc_atfork_child {
 
 sub _import_fh {
        my ($lei, $fh, $x) = @_;
-       my $set_kw = $lei->{opt}->{flags};
+       my $set_kw = $lei->{opt}->{kw};
        my $fmt = $lei->{opt}->{'format'};
        eval {
                if ($fmt eq 'eml') {
diff --git a/t/lei.t b/t/lei.t
index eb824a307f6df70558203a3d4c8c2c44656ab26e..41d854e859a7ff3accfdfe06a61b61244ede0327 100644 (file)
--- a/t/lei.t
+++ b/t/lei.t
@@ -400,7 +400,26 @@ my $test_import = sub {
        ok($lei->(qw(q s:boolean)), 'search hit after import');
        ok($lei->(qw(import -f eml), 't/data/message_embed.eml'),
                'import single file by path');
-       $cleanup->();
+
+       my $str = <<'';
+From: a@b
+Message-ID: <x@y>
+Status: RO
+
+       ok($lei->([qw(import -f eml -)], undef, { %$opt, 0 => \$str }),
+               'import single file with keywords from stdin');
+       $lei->(qw(q m:x@y));
+       my $res = $json->decode($out);
+       is($res->[1], undef, 'only one result');
+       is_deeply($res->[0]->{kw}, ['seen'], "message `seen' keyword set");
+
+       $str =~ tr/x/v/; # v@y
+       ok($lei->([qw(import --no-kw -f eml -)], undef, { %$opt, 0 => \$str }),
+               'import single file with --no-kw from stdin');
+       $lei->(qw(q m:v@y));
+       $res = $json->decode($out);
+       is($res->[1], undef, 'only one result');
+       is_deeply($res->[0]->{kw}, [], 'no keywords set');
 };
 
 my $test_lei_common = sub {