Skip to content

Commit a12a3d0

Browse files
committed
Merge pull request #12 from markatom/fix-encoding
Fix mailbox name encoding to support non-ASCII characters
2 parents 68b4fbd + 859168e commit a12a3d0

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

MailLibrary/Drivers/ImapDriver.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ public function setFlag($mailId, $flag, $value)
381381
* @throws DriverException
382382
*/
383383
public function copyMail($mailId, $toMailbox) {
384-
if(!imap_mail_copy($this->resource, $mailId, $this->server . $toMailbox, CP_UID)) {
384+
if(!imap_mail_copy($this->resource, $mailId, $this->server . $this->encodeMailboxName($toMailbox), CP_UID)) {
385385
throw new DriverException("Cannot copy mail to mailbox '$toMailbox': ".imap_last_error());
386386
}
387387
}
@@ -393,7 +393,7 @@ public function copyMail($mailId, $toMailbox) {
393393
* @throws DriverException
394394
*/
395395
public function moveMail($mailId, $toMailbox) {
396-
if(!imap_mail_move($this->resource, $mailId, $this->server . $toMailbox, CP_UID)) {
396+
if(!imap_mail_move($this->resource, $mailId, $this->server . $this->encodeMailboxName($toMailbox), CP_UID)) {
397397
throw new DriverException("Cannot copy mail to mailbox '$toMailbox': ".imap_last_error());
398398
}
399399
}
@@ -454,4 +454,16 @@ protected function buildIdList(array $ids)
454454
sort($ids);
455455
return implode(',', $ids);
456456
}
457+
458+
/**
459+
* Converts mailbox name encoding as defined in IMAP RFC 2060.
460+
*
461+
* @param $name
462+
* @return string
463+
*/
464+
protected function encodeMailboxName($name)
465+
{
466+
return mb_convert_encoding($name, 'UTF7-IMAP', 'UTF-8');
467+
}
468+
457469
}

0 commit comments

Comments
 (0)