title: Get UID for message from GMail using javax.mail with IMAP
body: <p>I'm using javax.mail to retrieve mails from GMail using IMAP. I want to also obtain the tags being applied to each mail, so I'm iterating over all the folders in the store (which actually are tags) and downloading mails for each other.</p>
  
  <p>I was using the method <a href="http://java.sun.com/products/javamail/javadocs/javax/mail/UIDFolder.html#getUID(javax.mail.Message)" rel="nofollow noreferrer">getUID</a> of ImapFolder to obtain the UID for each message, and then compare them to recognise the same mail along different folders.</p>
  
  <p>For example, if I had the mail "Hello" tagged with "A" and "B", I would iterate through folders "Inbox", "A" and "B" and get the same mail from each folder; so I could keep a single copy tagged with "Inbox", "A" and "B".</p>
  
  <p>However, the getUID method returns a folder-relative ID, so the same mail may have different IDs in different folders, or different mails may have the same ID in different folders. In the example. "HellO" may appear as mail 1 in "A" and as mail 2 in "B".</p>
  
  <p>Is there a way of obtaining a store-relative id for each mail, independent of the folder? Or a better way to obtain the tags attached to a single mail?</p>