Skip to content
Advertisement

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

Advertisement

Answer

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

    }
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement