Forum Moderators: coopster

Message Too Old, No Replies

PHP IMAP folder message count?

Total and unread messages per folder?

         

JAB Creations

4:26 pm on Jul 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've been working with PHP and the IMAP module and I'm just getting more and more lost as I try to achieve what I expected to be simple stuff such as listing the folder names, in example...
$boxes = imap_getmailboxes($mbox, "{mail.domain.com}", "*");

foreach($boxes as $val) {
$piece1 = explode("}", $val->name);
$piece2 = explode(".", $piece1[1]);

if (empty($piece2[1])) {echo '<div><b>Inbox</b></div>';}

Could someone please give me some direction as to what part of IMAP I should use to determine the message count and unread message count per folder?

- John

eelixduppy

4:37 pm on Jul 26, 2008 (gmt 0)



Might want to take a look at imap_status [us3.php.net]. :)

JAB Creations

5:05 pm on Jul 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yeah...I spotted it two seconds after I posted. Thank you for pointing it out in your reply of course...

I've been trying to make a function to make the folder count dynamic (from when I create a folder list). Toward the top where I define the $status with imap_status I'm trying to dynamically choose the folder (through using the PHP function's parameter). I sued both single and double quotes as well as attempting to use concatenation. Suggestions?

- John

function email_folder_count($folder)
{
$status = imap_status($mbox, '{mail.domain.com}$folder', SA_ALL);
if ($status)
{
echo "Messages: " . $status->messages . "<br />\n";
echo "Unseen: " . $status->unseen . "<br />\n";
}
else
{
echo "imap_status failed: " . imap_last_error() . "\n";
}
}

email_folder_count('INBOX');

JAB Creations

5:26 pm on Jul 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ha! I realized this again just now...I have to pass the $mbox variable as a parameter to the function for it to connect. Ok...my brain seems to have kick started for the day (seven hours later).

- John

eelixduppy

5:27 pm on Jul 26, 2008 (gmt 0)



hehe - happens to the best of us. Glad you got it resolved :)

JAB Creations

6:09 pm on Jul 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok...this will hopefully be my last question for a good while...

How do I use multiple imap_status flags? For example I don't need all of the data, just SA_MESSAGES and SA_UNSEEN.

I've tried concatenation and using a comma...I think something else too...not quite sure and there is only one example (of course) on php.net.

- John