Get Gmail All folder IMAP PHP

Deadly 提交于 2021-01-27 17:44:47

问题


I want to access the All folder in gmail via imap. in different language and in different name. What should i do?

The code of connection is:

$mail= imap_open('{imap.gmail.com:993/imap/ssl} //The all folder should be here ',$user,$pass);

回答1:


As described here, Gmail supports RFC 6154, IMAP LIST Extension for Special-Use Mailboxes. That means that the LIST response for the "all" folder will contain an \All attribute, independently of the language in use:

* LIST (\HasNoChildren \All) "/" "[Gmail]/All Mail"

Unfortunately, it seems like the PHP IMAP library only returns a limited number of mailbox attributes, \All not being one of them, so this will only be a viable solution once the library has been updated.




回答2:


This is the solution i found for the problem.The idea is that the All folder contains the biggest number of mails so we have to get the number of mails in all the folders and then find the biggest number which is the All Folder.

This solution has a problem when the number of messages in trash is bigger than All folder.

    $mbox=imap_open("{imap.gmail.com:993/imap/ssl}", "user", "pass");
    $list = imap_getmailboxes($mbox, "{imap.gmail.com:993/imap/ssl}", "*");
    $mailbox=null;
    $mailbox_name='';
    $number=0;
    foreach ($list as $key ) {
        $con=imap_open("$key->name", "user", "pass");
        $number_msg=imap_num_msg($con);

            if($number_msg > $number)
            {
                $number = $number_msg;
                $mailbox= $con;
                $mailbox_name= $key->name;
            }

    }



回答3:


Try

$folders = imap_listmailbox($mbox, "{imap.gmail.com:993/imap/ssl}", "ALL");



回答4:


If you're using PhpImap library, this is how you access the "all mail" folder:

$mailbox = new PhpImap\Mailbox('{imap.gmail.com:993/imap/ssl}[Gmail]/All Mail', $user, $pass, $attachment_dir);


来源:https://stackoverflow.com/questions/25530796/get-gmail-all-folder-imap-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!