I have a simple server which listen for incoming email messages from one or more folders and from one or more mailboxes.
Downloaded messages (quite all except their bodies and attachments) are persisted in a database, so even their UID and they can be retrieved each time a client want by referencing them by their UID.
I've unfortunately "just" discovered that Mail Servers may renumber some or maybe all their messages, so that renumbering invalidate all my UIDS previously persisted in database.
I'm not understanding what action should I take to overcome this behaviour, this renumbering, what I can do to intercept this renumbering and what can I do to renumber my messages, a part of them or all ?
I have understood the UIDValidity mechanism but I'm not understanding what exactly do when I discover its change.
I was thinking to:
Best regards
You cannot really do anything. Once the IMAP server tells you that the UIDVALIDITY
has changed, then the only standard-compliant, reliable and safe action is to discard everything from your local cache.
There are some non-standard extensions which might help you. GMail, for example, has its own X-GM-MSGID
, but it doesn't specify whether these get invalidated upon an UIDVALIDITY
change.
There were some efforts among the Courier and Dovecot maintainers to standardize a DIGEST
extension for computing cryptographic hashes of individual messages. These would be exactly what you're looking for. However, I don't think these ever got standardized. Also, keep in mind that the MIME standard allows for several equivalent representations of any given message (think various 8bit encoding schemes). Any body digesting breaks once the MIME structure changes.
I would not attempt to use the Message-Id
if I were you. Its value is user-controlled.