Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Gmail All folder IMAP PHP

Tags:

php

imap

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);
like image 857
Makram Avatar asked Jul 23 '26 04:07

Makram


1 Answers

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

    }
like image 198
Makram Avatar answered Jul 25 '26 20:07

Makram