]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/IMAPsearchqp.pm
www: improve navigation around contemporary threads
[public-inbox.git] / lib / PublicInbox / IMAPsearchqp.pm
index fba3baccf50679913733b61f79f6a5513044f1fb..5c82faa5cfcf201282320e06643e03bfcc766b61 100644 (file)
@@ -16,9 +16,9 @@ my %MM = map {; $MoY[$_-1] => sprintf('%02u', $_) } (1..12);
 
 # IMAP to Xapian header search key mapping
 my %IH2X = (
-       TEXT => '',
        SUBJECT => 's:',
        BODY => 'b:',
+       # TEXT => undef, # => everything
        FROM => 'f:',
        TO => 't:',
        CC => 'c:',
@@ -165,7 +165,7 @@ sub msn_set {
 my $prd = Parse::RecDescent->new(<<'EOG');
 <nocheck>
 { my $q = $PublicInbox::IMAPsearchqp::q; }
-search_key : search_key1(s) { $return = $q }
+search_key : CHARSET(?) search_key1(s) { $return = $q }
 search_key1 : "ALL" | "RECENT" | "UNSEEN" | "NEW"
        | OR_search_keys
        | NOT_search_key
@@ -183,11 +183,17 @@ search_key1 : "ALL" | "RECENT" | "UNSEEN" | "NEW"
        | CC_string
        | BCC_string
        | SUBJECT_string
+       | BODY_string
+       | TEXT_string
        | UID_set
        | MSN_set
        | sub_query
        | <error>
 
+charset : /\S+/
+CHARSET : 'CHARSET' charset
+{ $item{charset} =~ /\A(?:UTF-8|US-ASCII)\z/ ? 1 : die('NO [BADCHARSET]'); }
+
 SENTSINCE_date : 'SENTSINCE' date { $q->SENTSINCE(\%item) }
 SENTON_date : 'SENTON' date { $q->SENTON(\%item) }
 SENTBEFORE_date : 'SENTBEFORE' date { $q->SENTBEFORE(\%item) }
@@ -235,6 +241,8 @@ TO_string : "TO" string { $q->ih2x('TO', $item{string}) }
 CC_string : "CC" string { $q->ih2x('CC', $item{string}) }
 BCC_string : "BCC" string { $q->ih2x('BCC', $item{string}) }
 SUBJECT_string : "SUBJECT" string { $q->ih2x('SUBJECT', $item{string}) }
+BODY_string : "BODY" string { $q->ih2x('BODY', $item{string}) }
+TEXT_string : "TEXT" string { $q->ih2x(undef, $item{string}) }
 op_subq_enter : '(' { $q->subq_enter }
 sub_query : op_subq_enter search_key1(s) ')' { $q->subq_leave }
 
@@ -253,7 +261,7 @@ sub parse {
        %$q = (sql => \$sql, imap => $imap); # imap = PublicInbox::IMAP obj
        # $::RD_TRACE = 1;
        my $res = eval { $prd->search_key(uc($query)) };
-       return $@ if $@ && $@ =~ /\ABAD /;
+       return $@ if $@ && $@ =~ /\A(?:BAD|NO) /;
        return 'BAD unexpected result' if !$res || $res != $q;
        if (exists $q->{sql}) {
                delete $q->{xap};