The issue with ImapMessageInfo.UniquieId string representation

0 votes
asked Jun 25, 2011 by _Oz_ (360 points)
edited Dec 24, 2012


Background: Our mail server functionality currently use Rebex IMAP component. One of the system responsibility is to put INBOX emails in a database. To check if email already is in a database system find FolderId + UniquieId combination in a database table. Our previous Imap provider returned string view of integer value, that was unique per an email account.

Rebex Imap provider returns string unique ids like "ECvRWUABEHN". That could be ok, if Rebex documentation would contain any info about that, and, what actually was critical point, that text representation of Rebex provided UniqueI IS CASE SENSITIVE. That way, in pretty short time range in INBOX email accouint folder can appears two different emails with "ECvRWUABEHN" id and "ECvRWUABEHn" id.

The most database text configurations are CASE INSENSITIVE, so operations like DISTINCT, WHERE MessageUIN = @MessageUIN are CASE INSENSITIVE too, so Rebex style UniquieId values can seriously affects current data access and business logic, and in our case ACTUALLY DID IT.

You MUST provide more detailed documentation about things like described above. Short description like (quote from Rebex documentation) "Gets the message unique ID. " is absolutely not enough.

For now, my question is: can you change UniqueId representation such way that it will be case insensitive. Case sensitive operations on case insensitive databases is serious performance hit.

Applies to: Rebex Secure Mail

1 Answer

0 votes
answered Jun 27, 2011 by Lukas Matyska (56,670 points)
edited Dec 24, 2012

UniqueID in Rebex IMAP is Base64-encoded concatenation of IMAP's "UID" and "validity" values. The UID is assigned by the IMAP server when the message arrives and the combination of UID and validity is guaranteed to be unique in a single IMAP folder. (The server is permitted to change the validity, which invalidates all UIDs, but this doesn't occur very often on the majority of IMAP servers.)

The original values of ImapMessageInfo.UniqueId can be parsed using the ImapMessageSet.ParseUniqueId method as follows:

// get message info
ImapMessageInfo info = ...

// parse original IMAP's "UID" and "validity"
long validity, uid;
ImapMessageSet.ParseUniqueId(info.UniqueId, out validity, out uid);

You can either write your own CASE INSENSITIVE transform LONG -> STRING: {validity, uid} -> UniqueId or use your previous solution (combination of FolderId + uid).

commented Dec 21, 2012 by chmav (120 points)
edited Dec 21, 2012

Is there a function to get an UniqueID of a folder which is changed when a mail in this folder is changed(added/delete, readed)? I should know as fast as possible if something has changed in this directory. When this UniqueID is same as last check, nothing has to be done.


commented Dec 24, 2012 by Lukas Pokorny (112,470 points)
edited Dec 24, 2012

The standard IMAP protocol doesn't have such feature. A Quick Mailbox Resynchronization extension exists, but it's not yet supported by Rebex IMAP because the majority of IMAP servers don't support it either. Which IMAP serve do you use? Does it support this extension?