PHP 7.2.0 Release Candidate 4 Released

imap_mailboxmsginfo

(PHP 4, PHP 5, PHP 7)

imap_mailboxmsginfoПолучить информацию о текущем почтовом ящике

Описание

object imap_mailboxmsginfo ( resource $imap_stream )

Проверяет статус текущего почтового ящика на сервере. Аналогично imap_status(), но дополнительно вычисляет суммарный размер всех писем в ящике, из-за чего работает несколько медленнее.

Список параметров

imap_stream

Поток IMAP, полученный из imap_open().

Возвращаемые значения

Возвращает объект со следующими полями:

Свойства почтового ящика
Date дата последнего изменения (текущие дата и время)
Driver драйвер
Mailbox имя почтового ящика
Nmsgs количество писем
Recent количество новых
Unread количество непрочтенных
Deleted количество удаленных
Size размер ящика

В случае ошибки возвращает FALSE.

Примеры

Пример #1 Пример использования imap_mailboxmsginfo()

<?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_mailboxmsginfo() failed: " imap_last_error() . "<br />\n";
}

imap_close($mbox);

?>

add a note add a note

User Contributed Notes 8 notes

up
1
phrank
7 years ago
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.
up
1
Maxg
13 years ago
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)
up
1
m at tacker dot org
14 years ago
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 **/

?>
up
0
til_roque at yahoo dot com
14 years ago
the 'recent' of this function returns the same as 'UIDvalidity' from imap_status() ... makes no sense (or dos it?)
up
0
js at jerntorget dot se, ej at jerntorget dot se
15 years ago
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);
}
up
0
stephane-wantiez at tiscalinet dot be
15 years ago
imap_get_quota need you to be the admin of the mail server !
up
0
whw at my169 dot com
15 years ago
It is very slow,so don't use it to get mailbox size,used imap_get_quota instead.
up
-1
dolce at koulikov dot cc
15 years ago
Don't lie... I've timed it, there is merely a time difference, besides it returns a lot of other useful info packed in an object!
To Top