I’m trying to write a cron job that checks and then does some transformations on mail in my mailbox. I’m using the PHP IMAP extension and accessing the mailbox (which is google hosted) through POP3.
I’m testing it at the moment and I want to be able to have one email in the mailbox and keep testing my code on that email until I’m happy.
Unfortunately, once I’ve checked that email it will no longer download and I get “Mailbox empty”. Can anyone help me save some time and let me know how I can keep checking mail I’ve already checked?
When you fetch mails via pop3, then there are two different options:
You need leave on server.
There is also a flag called “seen” which determines, which mails are unread to you. Make sure that you handle this flag right, otherwise you might ask for new mails and your mails are not new.
imap_status() will set the read flag, imap_num_msg() does not touch any flags.
imap_fetchstructure() fetches not only the message structure, but the entire message and I suspect, that it also marks the mail read. Please verify if it changes anything when you explicitly mark the mail as new (or unread) in a client like thunderbird: there is a green bubble in the overview that changes to black when the mail is read. Click it to mark the mail unread.