Results 1 to 5 of 5

Thread: Count IMAP folder messages (read and unread) with PHP?

  1. #1
    Join Date
    Dec 2007
    Location
    Stranded in Sarasota Florida
    Posts
    75
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Question Count IMAP folder messages (read and unread) with PHP?

    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?

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    I would look into using imap_mailboxmsginfo() . I can't give you an example code at the moment, but I will work on posting something for you later on.

    Hope this helps.

    Edit: After looking into it a bit more, you might want to look into using imap_num_msg() and imap_num_recent as it will give you the total number of messages in the mailbox as well as the number of recent (unread) messages.
    Last edited by thetestingsite; 07-27-2008 at 02:34 AM.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Dec 2007
    Location
    Stranded in Sarasota Florida
    Posts
    75
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Talking

    Nah...I'm good now, thanks though.
    Code:
    function email_folder_count($mbox, $folder)
    {
     //$status = imap_status($mbox, "{imap.example.com}$folder", SA_ALL);
     $status = imap_status($mbox, "{imap.example.com}$folder", SA_ALL);
     if ($status)
     {
      echo '('.$status->messages.' Messages, '.$status->unseen.' New)';
     }
     else
     {
      echo "imap_status failed: " . imap_last_error() . "\n";
     }
    return $status;
    // EXAMPLE
    //email_folder_count($mbox, 'INBOX.Trash');
    }

  4. The Following User Says Thank You to JAB Creations For This Useful Post:

    thetestingsite (07-27-2008)

  5. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Thanks for posting that function, I think it may come in handy.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  6. #5
    Join Date
    Dec 2007
    Location
    Stranded in Sarasota Florida
    Posts
    75
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Default

    No prob...I'll most likely post a bit on php.net once I get my email client working. If you'd like an early gander shot me a private message...it's all read-only at the moment on a spam infested account...but the functionality is starting to make it viable. :-)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •