about summary refs log tree commit homepage
path: root/lib/PublicInbox/LeiTag.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/PublicInbox/LeiTag.pm')
-rw-r--r--lib/PublicInbox/LeiTag.pm56
1 files changed, 2 insertions, 54 deletions
diff --git a/lib/PublicInbox/LeiTag.pm b/lib/PublicInbox/LeiTag.pm
index f019202f..f5791947 100644
--- a/lib/PublicInbox/LeiTag.pm
+++ b/lib/PublicInbox/LeiTag.pm
@@ -7,58 +7,6 @@ use strict;
 use v5.10.1;
 use parent qw(PublicInbox::IPC PublicInbox::LeiInput);
 
-# JMAP RFC 8621 4.1.1
-# https://www.iana.org/assignments/imap-jmap-keywords/imap-jmap-keywords.xhtml
-my @KW = (qw(seen answered flagged draft), # widely-compatible
-        qw(forwarded phishing junk notjunk)); # rarely supported
-# note: RFC 8621 states "Users may add arbitrary keywords to an Email",
-# but is it good idea?  Stick to the system and reserved ones, for now.
-# The widely-compatible ones map to IMAP system flags, Maildir flags
-# and mbox Status/X-Status headers.
-my %KW = map { $_ => 1 } @KW;
-my $L_MAX = 244; # Xapian term limit - length('L')
-
-# RFC 8621, sec 2 (Mailboxes) a "label" for us is a JMAP Mailbox "name"
-# "Servers MAY reject names that violate server policy"
-my %ERR = (
-        L => sub {
-                my ($label) = @_;
-                length($label) >= $L_MAX and
-                        return "`$label' too long (must be <= $L_MAX)";
-                $label =~ m{\A[a-z0-9_](?:[a-z0-9_\-\./\@,]*[a-z0-9])?\z}i ?
-                        undef : "`$label' is invalid";
-        },
-        kw => sub {
-                my ($kw) = @_;
-                $KW{$kw} ? undef : <<EOM;
-`$kw' is not one of: `seen', `flagged', `answered', `draft'
-`junk', `notjunk', `phishing' or `forwarded'
-EOM
-        }
-);
-
-# like Getopt::Long, but for +kw:FOO and -kw:FOO to prepare
-# for update_xvmd -> update_vmd
-sub vmd_mod_extract {
-        my $argv = $_[-1];
-        my $vmd_mod = {};
-        my @new_argv;
-        for my $x (@$argv) {
-                if ($x =~ /\A(\+|\-)(kw|L):(.+)\z/) {
-                        my ($op, $pfx, $val) = ($1, $2, $3);
-                        if (my $err = $ERR{$pfx}->($val)) {
-                                push @{$vmd_mod->{err}}, $err;
-                        } else { # set "+kw", "+L", "-L", "-kw"
-                                push @{$vmd_mod->{$op.$pfx}}, $val;
-                        }
-                } else {
-                        push @new_argv, $x;
-                }
-        }
-        @$argv = @new_argv;
-        $vmd_mod;
-}
-
 sub input_eml_cb { # used by PublicInbox::LeiInput::input_fh
         my ($self, $eml) = @_;
         if (my $xoids = $self->{lei}->{ale}->xoids_for($eml)) {
@@ -99,7 +47,7 @@ sub lei_tag { # the "lei tag" method
         $sto->write_prepare($lei);
         my $self = bless { missing => 0 }, __PACKAGE__;
         $lei->ale; # refresh and prepare
-        my $vmd_mod = vmd_mod_extract(\@argv);
+        my $vmd_mod = $self->vmd_mod_extract(\@argv);
         return $lei->fail(join("\n", @{$vmd_mod->{err}})) if $vmd_mod->{err};
         $self->prepare_inputs($lei, \@argv) or return;
         grep(defined, @$vmd_mod{qw(+kw +L -L -kw)}) or
@@ -161,7 +109,7 @@ sub _complete_mark_common ($) {
 sub _complete_tag {
         my ($self, @argv) = @_;
         my @L = eval { $self->_lei_store->search->all_terms('L') };
-        my @all = ((map { ("+kw:$_", "-kw:$_") } @KW),
+        my @all = ((map { ("+kw:$_", "-kw:$_") } @PublicInbox::LeiInput::KW),
                 (map { ("+L:$_", "-L:$_") } @L));
         return @all if !@argv;
         my ($cur, $re) = _complete_mark_common(\@argv);