You can use imap_status
to get the message count for a given folder.
To find all folders, you can use imap_list
.
To find messages in folders, you can for instance use imap_search
. These can then be accessed using e.g. imap_headerinfo
and imap_body
For further information, please consult the documentation of the IMAP functions in PHP.