ここにあるphpクラスetodbを使用しています
http://www.phpclasses.org/package/3324-PHP-Retrieve-e-mail-messages-into-a-MySQL-database.html
電子メール アカウントをチェックし、メッセージを mysql データベースにダウンロードします。これは完全に機能しますが、各ループ (受信トレイ内のメッセージごとにループ) の最後で電子メールを削除します。メールの削除を停止する方法は知っていますが、問題は、メッセージの削除を許可するか、受信トレイが完全に空でない限り、何らかの理由でスクリプトが新しいメールをデータベースに挿入しないことです。
上記で参照した php クラスの最後の部分を次に示します。このセクションは、各メッセージをループしてデータベースに挿入し、設定されている場合はメッセージを削除します。要約すると、私の質問は、メッセージを削除したり、受信トレイを空にしたりせずに、スクリプトを正しく機能させることです。
$total_messages = $this->num_message();
// IM ASSUMING THIS FOR LOOP IS NOT LOOPING MESSAGES CORRECTLY
for ($i = 0; $i < $total_messages; $i++) {
#Get first message
$email = $this->email_get();
$ismsgdb = $this->db_add_message($email); // THIS INSERTS EACH MSG INTO DATABASE
#Get store dir
$dir = $this->dir_name();
$id_log = $this->add_db_log($email, 'Copy e-mail - start ');
foreach($this->partsarray as $part){
if($part[text][type] == 'HTML'){
#$message_HTML = $part[text][string];
$this->db_update_message($part[text][string], $type= 'HTML');
}elseif($part[text][type] == 'PLAIN'){
$message_PLAIN = $part[text][string];
$this->db_update_message($part[text][string], $type= 'PLAIN');
}elseif($part[attachment]){
#Save files(attachments) on local disc
// $message_ATTACH[] = $part[attachment];
foreach(array($part[attachment]) as $attach){
$attach[filename] = $this->mimie_text_decode($attach[filename]);
$attach[filename] = preg_replace('/[^a-z0-9_\-\.]/i', '_', $attach[filename]);
$this->add_db_log($email, 'Start coping file:"'.strip_tags($attach[filename]).'"');
$this->save_files($this->newid.$attach[filename], $attach[string]);
$filename = $dir.$this->newid.$attach[filename];
$this->db_add_attach($attach[filename], $filename);
$this->update_db_log('<b>'.$filename.'</b>Finish coping: "'.strip_tags($attach[filename]).'"', $this->logid);
}
//
}elseif($part[image]){
#Save files(attachments) on local disc
$message_IMAGE[] = $part[image];
foreach($message_IMAGE as $image){
$image[filename] = $this->mimie_text_decode($image[filename]);
$image[filename] = preg_replace('/[^a-z0-9_\-\.]/i', '_', $image[filename]);
$this->add_db_log($email, 'Start coping file: "'.strip_tags($image[filename]).'"');
$this->save_files($this->newid.$image[filename], $image[string]);
$filename = $dir.$this->newid.$image[filename];
$this->db_add_attach($image[filename], $filename);
$this->update_db_log('<b>'.$filename.'</b>Finish coping:"'.strip_tags($image[filename]).'"', $this->logid);
}
}
}
$this->spam_detect();
$this->email_setflag();
$this->email_delete(); // WHEN I REMOVE THIS THE SCRIPT WONT GRAB NEW EMAILS
$this->email_expunge(); // WHEN I REMOVE THIS THE SCRIPT WONT GRAB NEW EMAILS
$this->update_db_log('Finish coping', $id_log);
}