Anyone know why this code just deletes random messages and not ALL the
messages? $this->headers is simply imap_headers()
$i=0;
foreach ($this->headers as $header){
#Trim the header
$header = trim($header);
#Retrieve the ID of the mesage.
if (substr($header,0,2) === 'U ' ||
substr($header,0,2) === 'N '){
$header = substr($header,2);
if (substr($header,1,1) === 'D'){
$header = substr($header,2);
$header = trim($header);
}
$msg_id_array = explode(')',$header);
$msg_id = trim($msg_id_array[0]);
$h = imap_headerinfo($this->mbox ,
$msg_id);
if ($h->Unseen === 'U' || $h->Recent
=== 'N'){
$this->messages[$i]['id'] =
$msg_id;
$this->messages[$i]['from'] =
$h->fromaddress;
$this->messages[$i]['body'] =
trim(imap_fetchbody($this->mbox , $msg_id , 1));
$uid = imap_uid($this->mbox ,
$h->Msgno);
imap_delete ($this->mbox ,
$uid , FT_UID);
imap_expunge($this->mbox);
$i++;
}
} else {
print "Invalid header:
\"$header\"\r\n";
}
}