I'm looking into using the imap_mailboxmsginfo in my application on every folder in the users account and it seems that I have to open an IMAP connection for each folder I'm checking. If the user has 100 folders in his account this would mean that I have to open (and close) 100 connections just to get the information about the folders. Some email providers don't like this behaviour. Is there anyway I can make the PHP IMAP package use the IMAP SELECT command which would just select a different folder while preserving the connection?

Many thanks.

    Thanks drew010, this was helpfull but I still haven't found the solution. Basically, I need to list all the folders in an IMAP account and suffix the folders with unread/total messages in each folder. imap_list doesn't do the job, imap_getmailboxes might but I'm having problems finding what information is returned in each object of the array. Any clues? (I'm new to php, so please be understanding 😉 ).

    I also tried the imap_status command, but didn't get satisfactory results. Is there a site somewhere with some sample code I could look at (google search for all things php isn't very helpfull - to many mirrors 🙁 )

      i have a lot of experience with php, but very little with imap, so i have checked some functions and here is my best guess at a sample script to check out what folders there are and return how many messages and unread messages each box contains. hopefully it will work since i am unable to test it.

      //see next message
      
      ?>
      

        here is some working code, there are only 2 changes, one is the object names were wrong, and 2, the imap_status had the wrong thing in the 2nd parameter.

        <?php
        
        $mbox = imap_open("{drew-phillips.com/imap}", "username", "pass", OP_HALFOPEN) or die("Imap Error: " . imap_last_error());
        
        $boxes = imap_list($mbox, "{drew-phillips.com}", "*");
        
        if (!$boxes) {
          die("no boxes listed");
        }
        
        foreach($boxes as $box) {
        	$status = imap_status($mbox, $box, SA_ALL);
        
        echo "<b>Mailbox $box</b><br />\n";
        echo "- " . $status->messages . " messages<br />\n";
        echo "- " . $status->unseen . " new messages<br />\n";
        echo "<br />\n\n";
        }
        
        imap_close($mbox);
        
        ?>
        

        www.drew-phillips.com/php/test.php

          Many thanks for your help, that did the job!

            Write a Reply...