Search code examples
phpimapphp-imap

php : imap message sequence number gets changed after deleting one email


I have one application where people can configure there email account through IMAP and perform operations like reading email, delete, move, etc. I am facing problem that on delete of one email other email gets deleted. After debugging I found that 2 users have configured same email account and they are deleting emails from 2 different browsers without refreshing page.

Actually after deleting one email msgno returned by imap_fetch_overview gets changed but in other page same mail is still open having old msgno, and on delete of that email other mail gets deleted.

Check msgno before and after delete

In the above example after deleting mail having subject "test 4", msgno of "test 6", "test 7", "test 8" gets changed. Now if some other user who has previously opened mails tries to delete mail with subject "test 7", will actually delete mail with subject "test 8".

To delete email I am using imap_delete function which takes msgno as parameter. Please help how to handle such problem or is there a way to get unique identifier for each mail which will not change and using that identifier I can also perform IMAP operations like delete, move, etc.


Solution

  • Use unique IDs instead. I think all the PHP functions take a flag (like FT_UID?) to say use UIDs instead of sequence numbers.

    Deleting messages can mess up the Sequence IDs, especially if you're not paying attention to EXPUNGE responses.