Description

Parameters

ref should normally be just the server
specification as described in imap_open()

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.

Return Values

Returns an array of objects containing mailbox information. Each
object has the attributes name, specifying
the full name of the mailbox; delimiter,
which is the hierarchy delimiter for the part of the hierarchy
this mailbox is in; and
attributes. Attributes
is a bitmask that can be tested against:

LATT_NOINFERIORS - This mailbox contains, and may not contain any
"children" (there are no mailboxes below this one). Calling
imap_createmailbox() will not work on this mailbox.

LATT_NOSELECT - This is only a container,
not a mailbox - you cannot open it.

LATT_MARKED - This mailbox is marked. This means that it may
contain new messages since the last time it was checked. Not provided by all IMAP
servers.

LATT_UNMARKED - This mailbox is not marked, does not contain new
messages. If either MARKED or UNMARKED is
provided, you can assume the IMAP server supports this feature for this mailbox.

See Also

User Contributed Notes 5 notes

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

the documentation tell us that we check this attributes against four constants, these contents are

LATT_NOINFERIORS LATT_NOSELECT LATT_MARKEDLATT_UNMARKED

the value of these constants are

LATT_NOINFERIORS = 1LATT_NOSELECT = 2LATT_MARKED = 4LATT_UNMARKED = 8

you 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

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.

For the purposes of passing along the attributes as a json array, I wanted to pass the attributes as an indexed array to save on bandwidth and session storage. The human readable translation is then performed in javascript by relating each key to the proper attribute label. I also wanted a cleaner way of converting the attributes without calling another function or using a complex iteration. This puts each binary attribute into it's own array element for easy testing.

<?php$mailboxes = imap_getmailboxes($mailbox, $username, $password);

foreach($mailboxes as $key=>$mailbox){ ...$attrs = preg_split('//',str_pad(decbin($mailbox->attributes),7,"0",STR_PAD_LEFT),8); // convert decimal to an array of attributesarray_shift($attrs); // Remove the extra element at the front of the array in position 0...}?>

With temporary variables, the conversion would look like this.

<?php$attr_binary = decbin($mailbox->attributes); // convert decimal to binary$attr_binary = str_pad($attr_binary,7,"0",STR_PAD_LEFT); // pad with 0's on the left$attrs = $preg_split('//',$attr_binary,8); // split into an array after each characterarray_shift($attrs); // Remove the extra element at the front of the array in position 0?>

By defining the attributes as a map to the array index, you can test as follows.