メールボックスに接続し、スパムを迷惑メールフォルダに移動するクラスを作成しました。しかし、それは機能していないようで、理由はわかりません。これが私が持っているものです:
<?php
$cleaner = new Mail_cleaner();
echo 'Deleted '.$cleaner->deleted.' files';
Class Mail_cleaner {
public $server = '{mail.gridhost.co.uk:993/imap/ssl}';
public $folder = 'INBOX';
public $user = 'email@domain.com';
public $password = 'password';
public $mailbox;
public $check;
public $thelist;
public $overviews;
public $ids = array();
public $deleted = 0;
function __construct() {
$this->open_connection();
$this->get_messages();
}
function get_messages() {
$this->ids = array();
$this->overviews = imap_fetch_overview($this->mailbox,"1:{$this->check->Nmsgs}");
foreach($this->overviews as $overview) {
//print_r($overview); exit;
if(stripos($overview->subject, 'SPAM')!==FALSE
|| stripos($overview->subject, 'Luxury Replicas')!==FALSE
|| stripos($overview->subject, 'Pharmacy')!==FALSE
|| stripos($overview->subject, 'viagra')!==FALSE
|| stripos($overview->subject, 'dr.maxman')!==FALSE
|| stripos($overview->subject, 'cialis')!==FALSE
|| stripos($overview->subject, 'penis enlarge')!==FALSE
|| stripos($overview->from, 'westin')!==FALSE
|| stripos($overview->from, 'rightmove')!==FALSE
|| stripos($overview->from, 'groupon')!==FALSE
|| stripos($overview->from, 'primelocation')!==FALSE
|| stripos($overview->from, 'mg-rover')!==FALSE
) {
$this->ids[] = $overview->uid;
}
}
if(count($this->ids) > 0) {
$this->move_and_delete();
}
}
function move_and_delete() {
foreach($this->ids as $id) {
// move to junk
$result = imap_mail_move($this->mailbox, $id, 'INBOX.Junk');
if($result) {
//imap_delete($this->mailbox, $id);
$this->deleted++;
}
}
imap_expunge($this->mailbox);
imap_close($this->mailbox);
}
function open_connection() {
$this->mailbox = imap_open($this->server.$this->folder, $this->user, $this->password);
$this->check = imap_check($this->mailbox);
$this->thelist = imap_getmailboxes($this->mailbox, $this->server, "*");
}
}
?>
115個のメッセージが削除されたというメッセージが毎回同じ出力になります。2回続けて実行すると、2回目の出力は0メッセージ削除されます。つまり、基本的には、受信トレイからジャンクに消えていないため、適切に移動していません。誰もが理由を知っていますか?それはすべてのメッセージを取得し、それらをループしていますが、動きは起こっていないようです。