# RENAME the mailbox $oldname to $newname.
# If $try is set, print a warning but don't crash if the command fails.
# /!\ Requires a LIST command to be issued to determine the hierarchy
-# delimiter for the original name.
+# delimiter and the mailbox attributes for the original name.
sub rename($$$;$) {
my ($self, $from, $to, $try) = @_;
- my $delim = $self->{_CACHE}->{$from}->{DELIMITER} if defined $self->{_CACHE}->{$from};
+ my ($delim, @attrs);
+ if ($self->{_CACHE}->{$from}) {
+ $delim = $self->{_CACHE}->{$from}->{DELIMITER};
+ @attrs = @{$self->{_CACHE}->{$from}->{LIST_ATTRIBUTES} // []};
+ }
my $r = $self->_send("RENAME ".quote($from).' '.quote($to));
$self->{_CACHE}->{$to} = delete $self->{_CACHE}->{$from} if exists $self->{_CACHE}->{$from};
$self->{_PCACHE}->{$to} = delete $self->{_PCACHE}->{$from} if exists $self->{_PCACHE}->{$from};
- if (defined $delim) {
+ if (defined $delim and !grep {lc $_ eq lc '\NoInferiors' or lc $_ eq lc '\HasNoChildren'} @attrs) {
# on non-flat mailboxes, move children as well (cf 3501)
foreach my $c1 (grep /\A\Q$from$delim\E/, keys %{$self->{_CACHE}}) {
my $c2 = $c1 =~ s/\A\Q$from$delim\E/$to$delim/r;
$callback->(split(/ /, ($1 =~ s/^ //r))) if defined $callback and $cmd eq 'SEARCH';
}
elsif (s/\ALIST \((\\?$RE_ATOM_CHAR+(?: \\?$RE_ATOM_CHAR+)*)?\) ("(?:\\[\x22\x5C]|[\x01-\x09\x0B\x0C\x0E-\x21\x23-\x5B\x5D-\x7F])"|NIL) //) {
- my ($delim, $flags) = ($2, $1);
- my @flags = defined $flags ? split(/ /, $flags) : ();
+ my ($delim, $attrs) = ($2, $1);
+ my @attrs = defined $attrs ? split(/ /, $attrs) : ();
my $mailbox = $self->_astring(\$_);
$self->panic($_) unless $_ eq '';
$mailbox = 'INBOX' if uc $mailbox eq 'INBOX'; # INBOX is case-insensitive
undef $delim if uc $delim eq 'NIL';
$delim =~ s/\A"(.*)"\Z/$1/ if defined $delim;
$self->_update_cache_for($mailbox, DELIMITER => $delim);
- $callback->($mailbox, $delim, @flags) if defined $callback and $cmd eq 'LIST';
+ $self->_update_cache_for($mailbox, LIST_ATTRIBUTES => \@attrs);
+ $callback->($mailbox, $delim, @attrs) if defined $callback and $cmd eq 'LIST';
}
elsif (s/\ASTATUS //) {
my $mailbox = $self->_astring(\$_);