1use lib 't/lib'; 2use strict; 3use warnings; 4 5use Net::IMAP::Server::Test; 6my $t = "Net::IMAP::Server::Test"; 7 8$t->start_server_ok; 9$t->connect_ok; 10 11$t->cmd_like("DELETE foo" => "tag BAD Log in first" ); 12 13$t->cmd_ok("LOGIN username password"); 14 15$t->cmd_like("DELETE" => "tag BAD Not enough options" ); 16$t->cmd_like("DELETE foo bar" => "tag BAD Too many options" ); 17 18# Prune INBOX/username 19$t->cmd_ok("DELETE INBOX/username"); 20my %mailboxes = $t->mailbox_list; 21is(delete $mailboxes{"INBOX"}, "\\HasNoChildren", 22 "INBOX exists"); 23is(keys %mailboxes, 0, "No other mailboxes"); 24 25# Removing a non-existant mailbox is a failure 26$t->cmd_like("DELETE bogus" => "tag NO Mailbox doesn't exist"); 27 28# Removing the INBOX (in any case) is a failure 29$t->cmd_like("DELETE INBOX" => "tag NO INBOX cannot be deleted"); 30$t->cmd_like("DELETE InBoX" => "tag NO INBOX cannot be deleted"); 31 32# The RFC is slightly inconsistent with how removing a mailbox with 33# inferiors should function: 34# * Messages are removed from the mailbox 35# * The mailbox is marked as \Noselect 36# * Per the _first_ example under 6.3.4, this mailbox still shows to 37# `LIST "" "*"`; however, per the second, it does _not_ -- only to 38# `LIST "" "%"`. While the RENAME example supports the former 39# interpretation, the explicit contrast of * to % in the second 40# DELETE example implies that it is intentional. 41# * Removing this \Noselect'd mailbox will fail in the future 42# Currently, Net::IMAP::Server simply refuses to remove mailboxes which 43# have inferiors, avoiding the \Noselect difficulty entirely. 44$t->cmd_ok("CREATE INBOX/with/children"); 45{ 46 local $TODO = "Mailbox deletion is still too-conservative"; 47 $t->cmd_ok("DELETE INBOX/with"); 48} 49%mailboxes = $t->mailbox_list; 50is(delete $mailboxes{"INBOX/with/children"}, "\\HasNoChildren", 51 "Inferior mailbox still exists"); 52{ 53 local $TODO = "Mailbox deletion is still too-conservative"; 54 ok(!$mailboxes{"INBOX/with"}, "Mailbox is gone"); 55 is(keys %mailboxes, 1, "No other mailboxes"); 56} 57%mailboxes = $t->mailbox_list("", "INBOX/%"); 58my $mid = delete $mailboxes{"INBOX/with"}; 59ok($mid, "Found mid-mailbox using %"); 60like($mid, qr/\\HasChildren/, "Is marked \\HasChildren"); 61{ 62 local $TODO = "Mailbox deletion is still too-conservative"; 63 like($mid, qr/\\Noselect/, "Is marked \\Noselect"); 64} 65 66done_testing; 67