使用带有IMAP的javax.mail获取来自GMail的消息的UID

时间:2021-10-07 18:13:45

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.

我正在使用javax.mail使用IMAP从GMail检索邮件。我还希望获得应用于每个邮件的标签,因此我将遍历商店中的所有文件夹(实际上是标签)并为彼此下载邮件。

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.

我使用ImapFolder的getUID方法获取每条消息的UID,然后比较它们以识别不同文件夹中的相同邮件。

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

例如,如果我将邮件“Hello”标记为“A”和“B”,我将遍历文件夹“收件箱”,“A”和“B”,并从每个文件夹中获取相同的邮件;所以我可以保留一个标有“收件箱”,“A”和“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".

但是,getUID方法返回文件夹相对ID,因此相同的邮件可能在不同的文件夹中具有不同的ID,或者不同的邮件可能在不同的文件夹中具有相同的ID。在这个例子中。 “HellO”可能在“A”中显示为邮件1,在“B”中显示为邮件2。

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?

有没有办法获得每个邮件的商店相对ID,独立于文件夹?或者更好的方法来获取附加到单个邮件的标签?

2 个解决方案

#1


3  

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

从gmail论坛得到了答案:有一个“message-id”标题,其中包含我正在寻找的值。

#2


1  

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

我认为唯一的方法是使用您根据邮件头自己计算的哈希值。

#1


3  

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

从gmail论坛得到了答案:有一个“message-id”标题,其中包含我正在寻找的值。

#2


1  

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

我认为唯一的方法是使用您根据邮件头自己计算的哈希值。