Created
November 15, 2011 13:33
-
-
Save tochiz/1367080 to your computer and use it in GitHub Desktop.
delete all mail in inbox from imap mail box.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* delete_inbox.php | |
* inboxを空にする。cronなどで回す | |
*/ | |
// IDとパスワードとホスト名。SSL検証はエラー出るので回避。 | |
$id = ''; | |
$ps = ''; | |
$host = '{imap.ezweb.ne.jp:993/imap/ssl/novalidate-cert}'; | |
// 削除中ならば終了 | |
if(file_exists(dirname(__FILE__).'/.deletenow')) | |
exit(); | |
// 削除開始 | |
touch(dirname(__FILE__).'/.deletenow'); | |
// 受信BOXを開く | |
$mbox = imap_open($host.'INBOX', $id, $ps); | |
// 現在のメール数を取得&0になるまで繰り返す | |
while($num = imap_num_msg($mbox)) | |
{ | |
echo "現在のメッセージ数: $num\n"; | |
echo "削除中...\n"; | |
// Deleteフラグを全てにセット | |
imap_setflag_full($mbox, "1:$num", "\\Deleted"); | |
// 実際に削除する | |
imap_expunge ($mbox); | |
} | |
// 接続を閉じる | |
imap_close($mbox); | |
// 削除終了 | |
unlink(dirname(__FILE__).'/.deletenow'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment