PHP Conference Fukuoka 2025

imap_getmailboxes

(PHP 4, PHP 5, PHP 7, PHP 8)

imap_getmailboxesLista los buzones de correo y devuelve los detalles de cada uno

Descripción

imap_getmailboxes(IMAP\Connection $imap, string $reference, string $pattern): array|false

Lista los buzones de correo.

Parámetros

imap

An IMAP\Connection instance.

reference

reference debería ser solo el servidor en la forma descrita en imap_open()

Advertencia

Passing untrusted data to this parameter is insecure, unless imap.enable_insecure_rsh is disabled.

pattern

Specifies where in the mailbox hierarchy to start searching.

There are two special characters you can pass as part of the pattern: '*' and '%'. '*' means to return all mailboxes. If you pass pattern as '*', you will get a list of the entire mailbox hierarchy. '%' means to return the current level only. '%' as the pattern parameter will return only the top level mailboxes; '~/mail/%' on UW_IMAPD will return every mailbox in the ~/mail directory, but none in subfolders of that directory.

Valores devueltos

Devuelve un array de objetos que contienen información sobre los buzones de correo. Cada objeto posee un atributo de name, que contiene el nombre completo del buzón de correo, delimiter que es el delimitador jerárquico y attributes. attributes es una máscara de bits, que contiene :

  • LATT_NOINFERIORS - Este buzón de correo no tiene "hijos" (no hay más buzones de correo debajo de este) y no puede contener ninguno. Una llamada a la función imap_createmailbox() no funcionará en este buzón.

  • LATT_NOSELECT - Esto es solo un contenedor, no un buzón de correo (no se puede abrir).

  • LATT_MARKED - Este buzón de correo está marcado. Esto significa que puede contener nuevos mensajes desde la última vez que fue verificado. Este marcador no se proporciona con todos los servidores IMAP.

  • LATT_UNMARKED - Este buzón de correo no está marcado y no contiene nuevos mensajes. Si MARKED o UNMARKED se proporciona, se puede asumir que el servidor IMAP soporta esta funcionalidad para este buzón de correo.

  • LATT_REFERRAL - Este contenedor tiene una referencia a un buzón de correo remoto.

  • LATT_HASCHILDREN - Este buzón de correo tiene inferiores seleccionables.

  • LATT_HASNOCHILDREN - Este buzón de correo no tiene inferiores seleccionables.

Devuelve false en caso de fallo.

Historial de cambios

Versión Descripción
8.1.0 The imap parameter expects an IMAP\Connection instance now; previously, a valid imap resource was expected.

Ejemplos

Ejemplo #1 Ejemplo con imap_getmailboxes()

<?php
$mbox
= imap_open("{imap.example.org}", "username", "password", OP_HALFOPEN)
or die(
"Conexión imposible: " . imap_last_error());

$list = imap_getmailboxes($mbox, "{imap.example.org}", "*");
if (
is_array($list)) {
foreach (
$list as $key => $val) {
echo
"($key) ";
echo
imap_utf7_decode($val->name) . ",";
echo
"'" . $val->delimiter . "',";
echo
$val->attributes . "<br />\n";
}
} else {
echo
"imap_getmailboxes ha fallado: " . imap_last_error() . "\n";
}

imap_close($mbox);
?>

Ver también

add a note

User Contributed Notes 3 notes

up
13
Mohamed Abbas mabbas_xyz at yahoo dot com
18 years ago
i am currently develop a simple IMAP client, when i call imap_getmailboxes() i receive a different values in attributes property of the mailbox object the problem is how can i manipulate these attributes to get a meaningful value,if you make a hard search to find a solution for this, you willnot find any useful documents for this problem, let us take a closer look for this problem.when i call imap_getmailboxes() against different IMAP servers i got these attribute values[attributes] => 9[attributes] => 1[attributes] => 64[attributes] => 32[attributes] => 40 the documentation tell us that we check this attributes against four constants, these contents areLATT_NOINFERIORS LATT_NOSELECT LATT_MARKEDLATT_UNMARKEDthe value of these constants are LATT_NOINFERIORS = 1LATT_NOSELECT = 2LATT_MARKED = 4LATT_UNMARKED = 8you can got this result by echo each constant, unfortunately the documentation not explain how we can check the attributes against the constants, after a long time of searching i find the answer in source code of c-client (you can get the source from ftp://ftp.cac.washington.edu/imap/)under \src\c-client you will find mail.h open it and you will find this                               /* terminal node in hierarchy */#define LATT_NOINFERIORS (long) 0x1                /* name can not be selected */#define LATT_NOSELECT (long) 0x2                /* changed since last accessed */#define LATT_MARKED (long) 0x4                /* accessed since last changed */#define LATT_UNMARKED (long) 0x8                /* name has referral to remote mailbox */#define LATT_REFERRAL (long) 0x10                /* has selectable inferiors */#define LATT_HASCHILDREN (long) 0x20                /* has no selectable inferiors */#define LATT_HASNOCHILDREN (long) 0x40as you notice here these are our four constants and three additional constants LATT_REFERRALLATT_HASCHILDRENLATT_HASNOCHILDRENthen what is the value of these 3 attributes LATT_REFERRAL 0x10 = 00010000 in binary, the bitmask value is 2^4 = 16 and so on, or simply echo this constant to get the value, thenLATT_REFERRAL = 16LATT_HASCHILDREN = 32LATT_HASNOCHILDREN = 64finally the full list of constants will beLATT_NOINFERIORS = 1LATT_NOSELECT = 2LATT_MARKED = 4LATT_UNMARKED = 8LATT_REFERRAL = 16LATT_HASCHILDREN = 32LATT_HASNOCHILDREN = 64ok let's back to our attributes [attributes] => 9[attributes] => 1[attributes] => 64[attributes] => 32[attributes] => 40 [attributes] => 9 this mean it's LATT_UNMARKED and LATT_NOINFERIORS 1+8 =9[attributes] => 1 this mean LATT_NOINFERIORS[attributes] => 64 this mean LATT_HASNOCHILDREN[attributes] => 32 this mean LATT_HASCHILDREN [attributes] => 40 this mean LATT_HASCHILDREN and LATT_UNMARKED 32+8=40this just like linux file permission 7 mean read, write, and execute 4+2+1 read=4 write=2 execute=1that is what i found, i hope this can help Mohamed AbbasNileweb Egypt
up
5
foom at fuhm dot NO_supercalifragilisticexpialidocious_SPAM dot net
24 years ago
The list of mailbox attributes in this document is very misleading. In particular the explanation of noinferiors is just wrong. It does not mean that the mailbox currently has no children, it means that it *cannot* have children ever. Also, it is untrue that marked and unmarked are only used by UW-IMAP. They are in the official IMAP specification and are used by at least Courier-imap as well.

One thing to watch out for, however, is broken IMAP servers which do send \Noinferiors when they mean that there are currently no children.

From the IMAP4rev1 specs (RFC 2060):
      \Noinferiors

         It is not possible for any child levels of hierarchy to exist
         under this name; no child levels exist now and none can be
         created in the future.

      \Noselect

         It is not possible to use this name as a selectable mailbox.

      \Marked

         The mailbox has been marked "interesting" by the server; the
         mailbox probably contains messages that have been added since
         the last time the mailbox was selected.

      \Unmarked

         The mailbox does not contain any additional messages since the
         last time the mailbox was selected.
up
1
ad-rotator.com
21 years ago
In case you print_r() or var_dump() the object and see an int for attribute, these are the constant integers for the bitmask.1 LATT_NOINFERIORS2 LATT_NOSELECT4 LATT_MARKED8 LATT_UNMARKED
To Top