imap_mailboxmsginfo
(PHP 4, PHP 5)
imap_mailboxmsginfo — Get information about the current mailbox
Description
object imap_mailboxmsginfo
( resource
$imap_stream
)Checks the current mailbox status on the server. It is similar to imap_status(), but will additionally sum up the size of all messages in the mailbox, which will take some additional time to execute.
Return Values
Returns the information in an object with following properties:
Date | date of last change (current datetime) |
Driver | driver |
Mailbox | name of the mailbox |
Nmsgs | number of messages |
Recent | number of recent messages |
Unread | number of unread messages |
Deleted | number of deleted messages |
Size | mailbox size |
Returns FALSE
on failure.
Examples
Example #1 imap_mailboxmsginfo() example
<?php
$mbox = imap_open("{imap.example.org}INBOX", "username", "password")
or die("can't connect: " . imap_last_error());
$check = imap_mailboxmsginfo($mbox);
if ($check) {
echo "Date: " . $check->Date . "<br />\n" ;
echo "Driver: " . $check->Driver . "<br />\n" ;
echo "Mailbox: " . $check->Mailbox . "<br />\n" ;
echo "Messages: " . $check->Nmsgs . "<br />\n" ;
echo "Recent: " . $check->Recent . "<br />\n" ;
echo "Unread: " . $check->Unread . "<br />\n" ;
echo "Deleted: " . $check->Deleted . "<br />\n" ;
echo "Size: " . $check->Size . "<br />\n" ;
} else {
echo "imap_check() failed: " . imap_last_error() . "<br />\n";
}
imap_close($mbox);
?>
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для работы с почтой
- IMAP, POP3 и NNTP
- imap_8bit
- imap_alerts
- imap_append
- imap_base64
- imap_binary
- imap_body
- imap_bodystruct
- imap_check
- imap_clearflag_full
- imap_close
- imap_create
- imap_createmailbox
- imap_delete
- imap_deletemailbox
- imap_errors
- imap_expunge
- imap_fetch_overview
- imap_fetchbody
- imap_fetchheader
- imap_fetchmime
- imap_fetchstructure
- imap_fetchtext
- imap_gc
- imap_get_quota
- imap_get_quotaroot
- imap_getacl
- imap_getmailboxes
- imap_getsubscribed
- imap_header
- imap_headerinfo
- imap_headers
- imap_last_error
- imap_list
- imap_listmailbox
- imap_listscan
- imap_listsubscribed
- imap_lsub
- imap_mail_compose
- imap_mail_copy
- imap_mail_move
- imap_mail
- imap_mailboxmsginfo
- imap_mime_header_decode
- imap_msgno
- imap_num_msg
- imap_num_recent
- imap_open
- imap_ping
- imap_qprint
- imap_rename
- imap_renamemailbox
- imap_reopen
- imap_rfc822_parse_adrlist
- imap_rfc822_parse_headers
- imap_rfc822_write_address
- imap_savebody
- imap_scan
- imap_scanmailbox
- imap_search
- imap_set_quota
- imap_setacl
- imap_setflag_full
- imap_sort
- imap_status
- imap_subscribe
- imap_thread
- imap_timeout
- imap_uid
- imap_undelete
- imap_unsubscribe
- imap_utf7_decode
- imap_utf7_encode
- imap_utf8
Коментарии
imap_get_quota need you to be the admin of the mail server !
then use imap_get_quotaroot().....
or use this one (works with qmail):
function get_quotaroot() {
if(!$socket = @fsockopen("your server", your port);
return false;
fgets($socket, 1024);
fputs($socket, "a001 LOGIN ".$username." ".$password."\n");
fgets($socket, 1024);
fputs($socket, "a002 GETQUOTAROOT INBOX\n");
fgets($socket, 1024);
$result = fgets($socket, 1024);
fputs($socket, "a003 LOGOUT\n");
fgets($socket, 1024);
sscanf($result, '* QUOTA "ROOT" (STORAGE %d %d MESSAGE %d %d', $usedSize, $maxSize, $usedNum, $maxNum);
return array("usedSize" => $usedSize, "maxSize" => $maxSize, "usedNum" => $usedNum, "maxNum" => $maxNum);
}
The runtime difference between imap_status and imap_mailboxmsginfo is very significant on large mailboxes
<?php
/** opening connection to a
* mailbox with 3987 messages
* and retrive status information **/
$mbox = imap_open ('{mail.somwhere.com:110}', $user, $password);
$mbox_info = imap_status($mbox, '{mail.somwhere.com:110}INBOX', SA_MESSAGES);
/** took 11.05 seconds **/
$mbox_info = imap_mailboxmsginfo($mbox);
/** took 6 minutes 5.382 seconds **/
?>
About the slowness of imap_mailboxmsginfo() : if used on an IMAP connection, I did checked my mailserver logs and it appeared to send FETCH commands to retrieve the headers of EVERY messages of the mailbox ...
So, if you have, let's say, 400 messages in a folder, the function will be very slow (>1.5 sec on a local server !) ...
I strongly advise you to use imap_status() instead, which only sends one < STATUS "Mailbox/Name" (MESSAGES UNSEEN) > and is actually a lot faster (at least with IMAP, but that's maybe not true with POP3)
imap_mailboxmsginfo() is NOT similar to imap_status(). You will easily recognize that if you compare the prototypes:
object imap_mailboxmsginfo ( resource $imap_stream )
object imap_status ( resource $imap_stream , string $mailbox , int $options )
One SIGNIFICANT difference is that imap_mailboxmsginfo() gets the mailbox name from the stream resource and imap_status() requires any mailbox name as second argument.
If you need to get only time for the mailbox you should go with imap_check()