0
votes

I am connecting to a IMAP server with Python.

I have a UID of a special message.

Is there a way to get the folder name which contains this UID?

Or can a UID/message be in more than one folder? Then, I would like to get the list of folders this message belongs to.

Or I misunderstood something. A UID is always local to an IMAP folder. It is only valid in the context of an folder.

I use ImapClient to connect to an IMAP server. But on this level all languages and their bindungs should be same (my guess).

2

2 Answers

2
votes

A uid is not unique between folders. Only the trio of (folder name, uid validity, uid) is guaranteed to be unique.

With most server software (especially traditional UNIX IMAP servers), uids are generated monotonically ascending on each folder, and overlap. That is, the first message in any folder is UID 1, the second is UID 2, and so on. Obviously Sent:UID-1 is not the same message as Inbox:UID-1.

Some servers do actually generate account-unique UIDs (such as yahoo), but that is the exception, not the norm.

Gmail has an additional attribute which is account unique, the X-GM-MSGID, which is described at their IMAP extensions document.

1
votes

I found the answer myself:

http://www.limilabs.com/blog/unique-id-in-imap-protocol

To identify a message across all folders you need 3 variables: UID, folder name and FolderStatus.UIDValidity.

...

In most modern servers FolderStatus.UIDValidity changes rarely. However client that remembers message UIDs between sessions must deal with such change and act accordingly.

The result: You can't get the folder name from an UID.