| 1 | package Net::IMAP::Server::Command::Status; | ||
| 2 | |||
| 3 | use warnings; | ||
| 4 | use strict; | ||
| 5 | |||
| 6 | use base qw/Net::IMAP::Server::Command/; | ||
| 7 | |||
| 8 | sub validate { | ||
| 9 | my $self = shift; | ||
| 10 | |||
| 11 | return $self->bad_command("Log in first") if $self->connection->is_unauth; | ||
| 12 | |||
| 13 | my @options = $self->parsed_options; | ||
| 14 | return $self->bad_command("Not enough options") if @options < 2; | ||
| 15 | return $self->bad_command("Too many options") if @options > 2; | ||
| 16 | |||
| 17 | my ( $name, $flags ) = @options; | ||
| 18 | return $self->bad_command("Wrong second option") unless ref $flags; | ||
| 19 | |||
| 20 | my $mailbox = $self->connection->model->lookup( $name ); | ||
| 21 | return $self->no_command("Mailbox does not exist") unless $mailbox; | ||
| 22 | return $self->no_command("Mailbox is not selectable") unless $mailbox->is_selectable; | ||
| 23 | |||
| 24 | return 1; | ||
| 25 | } | ||
| 26 | |||
| 27 | sub run { | ||
| 28 | my $self = shift; | ||
| 29 | |||
| 30 | my ( $name, $flags ) = $self->parsed_options; | ||
| 31 | my $mailbox = $self->connection->model->lookup( $name ); | ||
| 32 | |||
| 33 | my %items = $mailbox->status(map {uc $_} @{$flags}); | ||
| 34 | $self->untagged_response( "STATUS ".$self->data_out({type=>"string", value => $name}) . " " | ||
| 35 | . $self->data_out([map {(\$_, $items{$_})}keys %items]) ); | ||
| 36 | $self->ok_completed; | ||
| 37 | } | ||
| 38 | |||
| 39 | 1; |