about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-02-06 12:18:29 +0000
committerEric Wong <e@80x24.org>2021-02-07 03:34:32 +0000
commit618c5d7767a3611d70f78825156d5ddac7ce9427 (patch)
tree8dd9b615a7e7b4ab2a4f2eab2c767a27ece18902
parent375ea9f09355d36f2a9550475012a8191cdff1b0 (diff)
downloadpublic-inbox-618c5d7767a3611d70f78825156d5ddac7ce9427.tar.gz
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.
-rw-r--r--lib/PublicInbox/LEI.pm7
-rw-r--r--lib/PublicInbox/LeiImport.pm4
-rw-r--r--t/lei.t21
3 files changed, 26 insertions, 6 deletions
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index 682d1bd1..b058b533 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -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 {
diff --git a/lib/PublicInbox/LeiImport.pm b/lib/PublicInbox/LeiImport.pm
index 4a9af8a7..2c7cbf2b 100644
--- a/lib/PublicInbox/LeiImport.pm
+++ b/lib/PublicInbox/LeiImport.pm
@@ -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 eb824a30..41d854e8 100644
--- 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 {