无法使用php-imap库在名称中打开带有波兰字符的邮箱

时间:2017-10-19 20:52:02

标签: php encoding imap php-imap

我正在尝试使用imap邮件帐户创建简单集成,但我无法打开Gmail默认邮箱:Ważne

Gmail按如下方式返回邮箱:

array:9 [▼
  0 => "{imap.gmail.com:993/imap/ssl}INBOX"
  1 => "{imap.gmail.com:993/imap/ssl}Sent"
  2 => "{imap.gmail.com:993/imap/ssl}[Gmail]/Kosz"
  3 => "{imap.gmail.com:993/imap/ssl}[Gmail]/Oznaczone gwiazdk\x01\x05"
  4 => "{imap.gmail.com:993/imap/ssl}[Gmail]/Spam"
  5 => "{imap.gmail.com:993/imap/ssl}[Gmail]/Wa\x01|ne"
  6 => "{imap.gmail.com:993/imap/ssl}[Gmail]/Wersje robocze"
  7 => "{imap.gmail.com:993/imap/ssl}[Gmail]/Wszystkie"
  8 => "{imap.gmail.com:993/imap/ssl}[Gmail]/Wys\x01Bane"
]
我正在使用的

php-imap包使我能够使用switchMailbox方法在邮箱之间切换。

以下是该软件包的代码示例:

public function switchMailbox($imapPath) {
    $this->imapPath = $imapPath;
    $this->imap('reopen', $this->imapPath);
}

public function imap($methodShortName, $args = [], $prependConnectionAsFirstArg = true, $throwExceptionClass = Exception::class) {
    if(!is_array($args)) {
        $args = [$args];
    }
    foreach($args as &$arg) {
        if(is_string($arg)) {
            $arg = imap_utf7_encode($arg);
        }
    }
    if($prependConnectionAsFirstArg) {
        array_unshift($args, $this->getImapStream());
    }

    imap_errors(); // flush errors
    $result = @call_user_func_array("imap_$methodShortName", $args);

    $errors = imap_errors();

    if($errors) {
        if($throwExceptionClass) {
            throw new $throwExceptionClass("IMAP method imap_$methodShortName() failed with error: " . implode('. ', $errors));
        }
        else {
            return false;
        }
    }

    return $result;
}

当我尝试提取时出现问题。有时候我会收到这个错误:

 IMAP protocol error: Could not parse command. Could not parse command

但有时错误说明发生了未知邮箱的原因......

以下是我的代码示例:

// getting imap object - built with user credentials
$mailbox = auth()->user()->mailbox->getIMAP(); 

$folders = $mailbox->getListingFolders();

// "ważne" folder. remember that "ż" was returned as string provided above
$mailbox->switchMailbox($folders[5]); 

// and boom! running this line breaks everything. Kids are crying, womens are screaming....
$mailbox->statusMailbox()

我该如何解决?

更新

我试图直接传递邮箱名称 - 而不是从返回的数组中传递。示例代码更改如下:

$mailbox->switchMailbox('{imap.gmail.com:993/imap/ssl}[Gmail]/Ważne');

但错误也发生了变化:

IMAP method imap_reopen() failed with error: [NONEXISTENT] Unknown Mailbox: [Gmail]/Wa&xbw-ne (now in authenticated state) (Failure)

0 个答案:

没有答案