Gmail IMAP: Any way to find all the labels (folders) in which a particular message is located?

So, Gmail IMAP is a bit "weird." They use IMAP folders to represent shortcuts. I usually think that an email in IMAP can belong to only one folder, however with Gmail, an email can belong to many β€œfolders”, which gives us very close functionality for shortcuts.

My question is that I am writing a gmail client (so things like Starring, deleting and archiving work a little more intuitively than the standard imap client), but I would like to be able to display for this letter in which folders (shortcuts ) he is in.

As far as I can tell, this is not easy (I would have to iterate over each message in each folder to see which ones it is in).

Does anyone know which way to do this? Or am I right in assuming there is no easy way?

+7
imap gmail gmail-imap
source share
2 answers

Gmail provides a set of IMAP extensions that allow authors of IMAP clients to provide more Gmail-related features through IMAP. See Gmail Email Extensions (X-GM-EXT-1) .

To get tags for a specific message, you can invoke the IMAP FETCH command using the X-GM-LABELS attribute . See Gmail Tag Access: X-GM-LABELS

+7
source share

The easiest (though not flawless) way is to capture the values ​​of the Message-ID message headers. Then go to the "label" folders and do IMAP SEARCH in the lines

 A001 SEARCH HEADER MESSAGE-ID "your-msgid-value" 

If you get any results in an undisturbed SEARCH response, the message has the selected folder label.

-one
source share

All Articles