Makram
Makram

Reputation: 843

Get Gmail All folder IMAP PHP

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);

Upvotes: 2

Views: 5142

Answers (4)

Ryan
Ryan

Reputation: 384

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);

Upvotes: 2

Belmendo
Belmendo

Reputation: 1

Try

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

Upvotes: 0

Makram
Makram

Reputation: 843

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;
            }

    }

Upvotes: 4

legoscia
legoscia

Reputation: 41527

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.

Upvotes: 3

Related Questions