about summary refs log tree commit homepage
path: root/lib/PublicInbox/IMAP.pm
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2020-06-10 07:04:05 +0000
committerEric Wong <e@yhbt.net>2020-06-13 07:55:45 +0000
commit7952dfc9ba1255400f85068364150bc5e0db869d (patch)
tree658e87da1395d772b1392f16cf8a965605bfef8f /lib/PublicInbox/IMAP.pm
parent9d154055ec44903052beaa4e2c1221f39d6d507a (diff)
downloadpublic-inbox-7952dfc9ba1255400f85068364150bc5e0db869d.tar.gz
I'm not sure if there's much use for this command, but it's
part of RFC3501 and works read-only.
Diffstat (limited to 'lib/PublicInbox/IMAP.pm')
-rw-r--r--lib/PublicInbox/IMAP.pm29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/PublicInbox/IMAP.pm b/lib/PublicInbox/IMAP.pm
index c8592dc0..a2d59e5c 100644
--- a/lib/PublicInbox/IMAP.pm
+++ b/lib/PublicInbox/IMAP.pm
@@ -306,6 +306,35 @@ sub uid_fetch_m { # long_response
         1;
 }
 
+sub cmd_status ($$$;@) {
+        my ($self, $tag, $mailbox, @items) = @_;
+        my $ibx = $self->{imapd}->{groups}->{$mailbox} or
+                return "$tag NO Mailbox doesn't exist: $mailbox\r\n";
+        return "$tag BAD no items\r\n" if !scalar(@items);
+        ($items[0] !~ s/\A\(//s || $items[-1] !~ s/\)\z//s) and
+                return "$tag BAD invalid args\r\n";
+
+        my $mm = $ibx->mm;
+        my ($max, @it);
+        for my $it (@items) {
+                $it = uc($it);
+                push @it, $it;
+                if ($it =~ /\A(?:MESSAGES|UNSEEN|RECENT)\z/) {
+                        push(@it, ($max //= $mm->max // 0));
+                } elsif ($it eq 'UIDNEXT') {
+                        push(@it, ($max //= $mm->max // 0) + 1);
+                } elsif ($it eq 'UIDVALIDITY') {
+                        push(@it, $mm->created_at //
+                                return("$tag BAD UIDVALIDITY\r\n"));
+                } else {
+                        return "$tag BAD invalid item\r\n";
+                }
+        }
+        return "$tag BAD no items\r\n" if !@it;
+        "* STATUS $mailbox (".join(' ', @it).")\r\n" .
+        "$tag OK Status complete\r\n";
+}
+
 sub cmd_uid_fetch ($$$;@) {
         my ($self, $tag, $range, @want) = @_;
         my $ibx = $self->{ibx} or return "$tag BAD No mailbox selected\r\n";