I'm using PHP IMAP and I want to remove all the mails in my box, but I can't find the way to select all folder.
I can retrieve all the folders names using imap_listmailbox
:
<?php
$folders = imap_listmailbox($mbox, "{imap.example.org:143}", "*");
?>
Yahoo for example : return the following Folders names : (INBOX, Bulk Mail, Draft...)
And I can connect to all those folders and remove the mails
inside using a loop, but not in the same time since I have to specify always the FolderName
like example bellow :
<?php
$mailBox = imap_open("{imap.example.org:143}FolderName", "username", "password");
//__________________________________________^
$mailsIds = imap_search($mailBox, 'ALL');
foreach($mailsIds as $mailId)
imap_delete($mailBox, $mailId);
imap_expunge($mailBox);
?>
When I Try with no folder name, e.g :
$mailBox = imap_open("{imap.example.org:143}", "username", "password");
That select default folder INBOX
.
When I Try with ALL
, e.g :
$mailBox = imap_open("{imap.example.org:143}ALL", "username", "password");
That not return anything.
NOTE : In GMAIL I can found that they have a folder called [Gmail]/Tous les messages
that contains all the mails.