2
votes

I have written a PHP script which connects to my Gmail account and loops messages inside the "INBOX" folder. However, I want to learn the "labels" of each message that exist in the INBOX folder. In other words, I want to learn which other IMAP folder does each message in the inbox exist? In this way, I am planning to write a small stats php script which will show me messages from each label. For example, My Gmail IMAP folders are;

  • INBOX (75 messages)
  • Personal (21839 messages)
  • Business (129 messages)
  • Friends (4321 messages)
  • Facebook (293 messages)

All those 75 messages in the INBOX are also labeled with other folders. I want to show how many of those 75 messages belong to "Personal" or "Business" folder also. Is this possible with PHP imap functions?

Thanks.

1
Did you ever solve this? I'm looking for the answer as well.stpe

1 Answers

1
votes

Imap store messages in a mailboxes, a different mailbox for each folder. You need to check the folders separately, look this sample:

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

 }