PHP Classes

Sample for getting acount usage

Recommend this page to a friend!

      IMAP  >  All threads  >  Sample for getting acount usage  >  (Un) Subscribe thread alerts  
Subject:Sample for getting acount usage
Summary:Extract the number of mails and the size they use in MB
Messages:1
Author:Anders Jenbo
Date:2010-01-06 22:08:40
 

  1. Sample for getting acount usage   Reply   Report abuse  
Picture of Anders Jenbo Anders Jenbo - 2010-01-06 22:08:40
$size = 0;
$mailsTotal = 0;

//Get full list of mailboxes
$mailboxList = $imap->list_mailbox();
foreach($mailboxList as $mailbox) {
//Open each mailbox
$mailboxStatus = $imap->open_mailbox($mailbox, true);
//Get the number of mails in the mailbox
preg_match('/([0-9]+)\sEXISTS/', $mailboxStatus, $mails);
$mailsTotal += $mails[1];
Get the size of each mail in the mailbox
preg_match_all('/SIZE\s([0-9]+)/', $imap->fetch_mail('1:'.$mails[1].'', 'FAST'), $mailSizes);
$size += array_sum($mailSizes[1]);
}

echo($mailsTotal.' : '.number_format($size/1024/1024, 1, ',', '').'MB');