I am saving my mailbox elements to a mysql database (to perform fast searches in my intranet, since imap_search'
is too slow).
I am connecting to the server and folder, and iterating through messages.
simplified code:
$numMsg = imap_num_msg($conn);
for($i=1;$i<=$numMsg;$i++){
$uid = imap_uid($conn,$i);
echo("msg_num:".$i." - uid:".$uid);
}
and I get something like this:
msg_num:5 - uid:5msg_num:6 - uid:6msg_num:7 - uid:7msg_num:8 - uid:8msg_num:9 - uid:9msg_num:10 - uid:10msg_num:11 - uid:11msg_num:12 - uid:12
which is totally wrong!!!
uid
isn't supposed to be unique?
I get this UIDs in 5 sub-folders that I have and also in Sent Items, on the Inbox I get uids right (msg_num:5 - uid:1503msg_num:6 - uid:1504msg_num:7 - uid:1506)
Internally, each IMAP message is assigned a unique ID (UID).
RFC 3501 (IMAP): (Unique Identifier (UID) Message Attribute is) a 32-bit value assigned to each message, which when used with the unique identifier validity value (see below) forms a 64-bit value that MUST NOT refer to any other message in the mailbox or any subsequent mailbox with the same name forever.
UID is the unique identification number of a email in a IMAP folder . Each mail in a folder is assigned a uid, it is you can say a index maintained by the mail folder. Whereas message-id is a header part of a email. To understand in a simple term, UID is a unique number which cannot be duplicated within a folder.
IMAP (Internet Message Access Protocol) Folders can be created on the server to better manage the messages. The folders then sync across all devices used to check your email. Sent messages are also saved in the sent folder, allowing you to view sent emails from any computer or device.
Right, the UID is only unique per folder. The full persistent unique ID of a message is a tuple of the folder name, the folders UIDVALIDITY, and the messages UID. That tuple, on a correctly implemented server, will only ever refer to one message.
For example: (SENT, 1, 100) Indicates message with ID 100 from the 1st incarnation of the sent folder. UIDVALIDITYs tend to be about 10 digit numbers, and are supposed to change if the folder is deleted and recreated or needs to be reindexed/regenerated by the server software.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With