xref: /PHP-5.6/ext/imap/tests/clean.inc (revision f5e46d5b)
1<?php
2include_once(dirname(__FILE__) . '/imap_include.inc');
3
4$imap_stream = imap_open($default_mailbox, $username, $password);
5
6// delete all msgs in default mailbox, i.e INBOX
7$check = imap_check($imap_stream);
8for ($i = 1; $i <= $check->Nmsgs; $i++) {
9	imap_delete($imap_stream, $i);
10}
11
12$mailboxes = imap_getmailboxes($imap_stream, $server, '*');
13
14foreach($mailboxes as $value) {
15	// Only delete mailboxes with our prefix
16	if (preg_match('/\{.*?\}INBOX\.(.+)/', $value->name, $match) == 1) {
17		if (strlen($match[1]) >= strlen($mailbox_prefix)
18		&& substr_compare($match[1], $mailbox_prefix, 0, strlen($mailbox_prefix)) == 0) {
19			imap_deletemailbox($imap_stream, $value->name);
20		}
21	}
22}
23
24imap_close($imap_stream, CL_EXPUNGE);
25?>