0

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;
        }
    }
}

}

Cesar Bielich
  • 4,754
  • 9
  • 39
  • 81

1 Answers1

0

You are not using UIDs, so don't set the ST_UID flag on imap_setflag_full. You are using message sequence numbers everywhere:

imap_setflag_full($hMail, $idxMsg, "\\Seen \\Flagged");
Max
  • 10,701
  • 2
  • 24
  • 48