问题
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