Server/Command/Select.pm untested

filter: Statementstmt 0.0% 0 / 38 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 68 CC 10 SCAR 34.7
CC
10
Cov
0%
run
56.0
validate
20.0
poll_after
2.0
CRAP 32.0
1 package Net::IMAP::Server::Command::Select;
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 < 1;
15 return $self->bad_command("Too many options") if @options > 1;
16  
17 return 1;
18 }
19  
20 sub run {
21 my $self = shift;
22  
23 $self->connection->selected->expunge
24 if $self->connection->selected
25 and not $self->connection->selected->read_only;
26 $self->connection->selected(undef);
27  
28 my $mailbox = $self->connection->model->lookup( $self->parsed_options );
29 return $self->no_command("Mailbox does not exist") unless $mailbox;
30 return $self->no_command("Mailbox is not selectable") unless $mailbox->is_selectable;
31  
32 $mailbox->poll;
33 $self->connection->last_poll(time);
34 $self->connection->selected($mailbox, $self->command eq "Examine");
35  
36 $self->untagged_response(
37 'FLAGS (' . join( ' ', $mailbox->flags ) . ')' );
38 $self->untagged_response( $mailbox->exists . ' EXISTS' );
39 $self->untagged_response( $mailbox->recent . ' RECENT' );
40  
41 my $unseen = $mailbox->first_unseen;
42 $self->untagged_response("OK [UNSEEN $unseen]");
43  
44 my $uidvalidity = $mailbox->uidvalidity;
45 $self->untagged_response("OK [UIDVALIDITY $uidvalidity]")
46 if defined $uidvalidity;
47  
48 my $uidnext = $mailbox->uidnext;
49 $self->untagged_response("OK [UIDNEXT $uidnext]") if defined $uidnext;
50  
51 my $permanentflags = $mailbox->permanentflags;
52 $self->untagged_response( "OK [PERMANENTFLAGS ("
53 . join( ' ', $mailbox->permanentflags )
54 . ')]' );
55  
56 if ( $mailbox->read_only ) {
57 $self->ok_command("[READ-ONLY] Completed");
58 } else {
59 $self->ok_command("[READ-WRITE] Completed");
60 }
61 }
62  
63 sub poll_after { 0 }
64  
65 1;