clean.inc 969 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. require_once 'imap_include.inc';
  3. if (!isset($mailbox_suffix)) { throw new Exception("No suffix provided"); }
  4. $imap_stream = imap_open(IMAP_DEFAULT_MAILBOX, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD);
  5. // delete all msgs in default mailbox, i.e INBOX
  6. $check = imap_check($imap_stream);
  7. for ($i = 1; $i <= $check->Nmsgs; $i++) {
  8. imap_delete($imap_stream, $i);
  9. }
  10. $mailboxes = imap_getmailboxes($imap_stream, IMAP_SERVER, '*');
  11. if (!is_array($mailbox_suffix)) {
  12. $mailbox_suffixes = [$mailbox_suffix];
  13. } else {
  14. $mailbox_suffixes = $mailbox_suffix;
  15. }
  16. foreach ($mailbox_suffixes as $mailbox_suffix) {
  17. foreach($mailboxes as $value) {
  18. // Only delete mailbox with our prefix (+ optional test suffix)
  19. if (preg_match('/\{.*?\}INBOX\.' . IMAP_MAILBOX_PHPT_PREFIX . $mailbox_suffix .'$/', $value->name, $match) == 1) {
  20. imap_deletemailbox($imap_stream, $value->name);
  21. }
  22. }
  23. }
  24. imap_close($imap_stream, CL_EXPUNGE);