Skip to content

Commit

Permalink
Fixed encoding for rename method, improved test
Browse files Browse the repository at this point in the history
  • Loading branch information
Omar Monterrey committed Aug 4, 2022
1 parent 14bfce7 commit e3a4cba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/Mailbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ public function renameTo(string $name = null): bool
if (null === $name) {
return false;
}
$encodedName = \mb_convert_encoding($name, 'UTF7-IMAP', 'UTF-8');
$oldFullName = $this->getFullEncodedName();
$newFullName = \str_replace($this->name, $name, $oldFullName);
$newFullName = \preg_replace('/' . \preg_quote(\mb_convert_encoding($this->name, 'UTF7-IMAP', 'UTF-8')) . '$/', $encodedName, $oldFullName);
if (null === $newFullName) {
return false;
}

$return = \imap_renamemailbox($this->resource->getStream(), $oldFullName, $newFullName);
if (false === $return) {
Expand Down
7 changes: 5 additions & 2 deletions tests/MailboxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ public function testGetName(): void

public function testRenameTo(): void
{
$this->mailbox->renameTo($this->altName);
static::assertNotSame($this->mailboxName, $this->altName);

static::assertTrue($this->mailbox->renameTo($this->altName));
static::assertSame($this->altName, $this->mailbox->getName());
$this->mailbox->renameTo($this->mailboxName);

static::assertTrue($this->mailbox->renameTo($this->mailboxName));
static::assertSame($this->mailboxName, $this->mailbox->getName());
}

Expand Down

0 comments on commit e3a4cba

Please sign in to comment.