I have a script that checks users mailbox and processes those email into a ticket system. For 99% of the time the script works fine. Once in a while I come across an email that does not get marked as read after processing. I have not been using the imap_setflag_full
flag to mark it as read, it does it automatically. So far this is happening with Gmail.
imap_setflag_full($hMail, $idxMsg, "\\Seen \\Flagged", ST_UID);
So even trying to use imap_setflag_full
the email still does not get marked as read. The only thing I can do it manually go into the inbox and remove the email.
Anyone have any idea why this is happening?
$hMail = imap_open("{".$row['address'].":".$row['port']."/".$row['transport']."/".$row['security']."}INBOX", "$strUser", "$strPassword");
if ($hMail) {
// get headers
$aHeaders = imap_headers($hMail);
// get message count
$objMail = imap_mailboxmsginfo( $hMail );
// process messages
for( $idxMsg = 1; $idxMsg <= $objMail->Nmsgs; $idxMsg++ ) {
// get header info
$objHeader = imap_headerinfo( $hMail, $idxMsg );
// is unread mail
if($objHeader->Unseen == 'U') {
// email unread so process
imap_setflag_full($hMail, $idxMsg, "\\Seen \\Flagged", ST_UID);
} else {
// email read already so skip
if ($row['delete_email'] == 1) {
// delete message
imap_delete( $hMail, $idxMsg );
}
continue;
}
}
}
}