0

我正在尝试创建与 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)
4

0 回答 0