]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/IMAP.pm
daemon: use ->can to check for IO::Socket::SSL
[public-inbox.git] / lib / PublicInbox / IMAP.pm
index dd983dfd2822b90d08a03f2b415b5205a1b0c25c..d8b1fce109ea151bdda1a6438d7d2f75219c332c 100644 (file)
@@ -166,7 +166,7 @@ sub cmd_login ($$$$) {
 
 sub cmd_close ($$) {
        my ($self, $tag) = @_;
-       delete $self->{uid_base};
+       delete @$self{qw(uid_base uo2m)};
        delete $self->{ibx} ? "$tag OK Close done\r\n"
                                : "$tag BAD No mailbox\r\n";
 }
@@ -220,7 +220,7 @@ sub uo2m_hibernate ($) {
 
 sub uo2m_last_uid ($) {
        my ($self) = @_;
-       my $uo2m = $self->{uo2m} or die 'BUG: uo2m_last_uid w/o {uo2m}';
+       defined(my $uo2m = $self->{uo2m}) or die 'BUG: uo2m_last_uid w/o {uo2m}';
        (ref($uo2m) ? @$uo2m : (length($uo2m) >> 1)) + $self->{uid_base};
 }
 
@@ -415,6 +415,7 @@ sub cmd_examine ($$$) {
        my ($ibx, $exists, $uidnext, $base) = inbox_lookup($self, $mailbox);
        return "$tag NO Mailbox doesn't exist: $mailbox\r\n" if !$ibx;
        $self->{uid_base} = $base;
+       delete $self->{uo2m};
 
        # XXX: do we need this? RFC 5162/7162
        my $ret = $self->{ibx} ? "* OK [CLOSED] previous closed\r\n" : '';
@@ -1154,13 +1155,8 @@ sub xap_append ($$$$) {
 }
 
 sub parse_query ($$) {
-       my ($self, $rest) = @_;
-       if (uc($rest->[0]) eq 'CHARSET') {
-               shift @$rest;
-               defined(my $c = shift @$rest) or return 'BAD missing charset';
-               $c =~ /\A(?:UTF-8|US-ASCII)\z/ or return 'NO [BADCHARSET]';
-       }
-       my $q = PublicInbox::IMAPsearchqp::parse($self, join(' ', @$rest));
+       my ($self, $query) = @_;
+       my $q = PublicInbox::IMAPsearchqp::parse($self, $query);
        if (ref($q)) {
                my $max = $self->{ibx}->over->max;
                my $beg = 1;
@@ -1202,9 +1198,9 @@ sub search_xap_range { # long_response
 }
 
 sub search_common {
-       my ($self, $tag, $rest, $want_msn) = @_;
+       my ($self, $tag, $query, $want_msn) = @_;
        my $ibx = $self->{ibx} or return "$tag BAD No mailbox selected\r\n";
-       my $q = parse_query($self, $rest);
+       my $q = parse_query($self, $query);
        return "$tag $q\r\n" if !ref($q);
        my ($sql, $range_info) = delete @$q{qw(sql range_info)};
        if (!scalar(keys %$q)) { # overview.sqlite3
@@ -1222,14 +1218,14 @@ sub search_common {
        }
 }
 
-sub cmd_uid_search ($$$;) {
-       my ($self, $tag) = splice(@_, 0, 2);
-       search_common($self, $tag, \@_);
+sub cmd_uid_search ($$$) {
+       my ($self, $tag, $query) = @_;
+       search_common($self, $tag, $query);
 }
 
 sub cmd_search ($$$;) {
-       my ($self, $tag) = splice(@_, 0, 2);
-       search_common($self, $tag, \@_, 1);
+       my ($self, $tag, $query) = @_;
+       search_common($self, $tag, $query, 1);
 }
 
 sub args_ok ($$) { # duplicated from PublicInbox::NNTP