Get UID for message from GMail using javax.mail with IMAP

守給你的承諾、 提交于 2019-12-10 09:59:01

问题


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.

I was using the method getUID of ImapFolder to obtain the UID for each message, and then compare them to recognise the same mail along different folders.

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".

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".

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?


回答1:


Got the answer from gmail forums: there is a "message-id" header that contains the value I was looking for.




回答2:


I think the only way is to use a hash that you calculate yourself based on the message headers.



来源:https://stackoverflow.com/questions/219343/get-uid-for-message-from-gmail-using-javax-mail-with-imap

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!