0

In the beginning, suppose that there are 3 messages on the remote mail server. Uid 1, 2, 3 We download them by using PHP IMAP functions (namely POP3 connection). Mail server provides us with next uid, i.e. uid 4. And we save it.

Several days later, suppose that there are new messages on the remote mail server, some of them being deleted. Uid 1, 2, 3, 4(deleted), 5(deleted), 6(deleted), 7, 8, 9

So, actual situation will look like as such: Uid 1, 2, 3, 7, 8, 9 The question is: when we give uid 3 (or uid 4), we want to get next greater existent uid, i.e. uid 7.

To put in a more general way: Uid = {1, 2, 3, 7, 8, 9, 12, 13}

f(2) = 3  [give uid 2, and get uid 3]
f(3) = 7
f(4) = 7
f(8) = 9
f(9) = 12
f(10) = 12
f(13) = null or empty
f(17) = null or empty

When we have uid number, we can obtain message number, and download messages.

I am developping a mail client, and I am not able to get next uid.

Bayram
  • 1
  • Use imap_sort() to get a sorted list of message ids that fit a particular search filter, and then iterate over that list and call imap_body() (and/or imap_fetchheader()) for each message. After downloading a message, delete it or tag it somehow (like mark it as read) so that your search filter skips it in the future. Don't rely on the UID to be incremental or continuous. – Alex Howansky Feb 22 '23 at 17:33
  • Do not use POP3 to fetch messages if you want to use the UID functions. POP3 does not have the same idea of UIDs, not does it have the concept of \Deleted messages, and can't tell you if a message is deleted or not. – Max Feb 22 '23 at 20:15
  • If uidvalidity check is true, do you think that uid number is still unreliable? If this is the case, uid number will not have any meaning. – Bayram Feb 23 '23 at 07:23
  • UIDVALIDITY is meaningless with a POP connection. Are you really using POP3 or are you using IMAP? – Max Feb 27 '23 at 15:30

0 Answers0