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

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?


Asked by: Catherine992 | Posted: 23-01-2022






Answer 1

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

Answered by: Elise871 | Posted: 24-02-2022



Answer 2

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

Answered by: Madaline163 | Posted: 24-02-2022



Similar questions

java - Delete Email on Server using javax.mail

I am receiving emails from the server using the IMAP protocol like it is described here. This is working very fine and I can store the emails and attachments on the disk. Question: Do I have the possibility to delete files from the Server, so th...


java - Javax.mail in JNLP

I have a problem with my program. I develop in Netbeans, and when i run the program it is working fine. i built it, created a *.jar file, and updatet it in my JNLP file. here comes the trouble. as i'm using javax.mail.* in my program, the jnlp package just ignores all parts of it. Just to be clear, i'm working on a mail client. now i can check the numbers of the mails in the inbox. that is what the program...


java - Search email inbox using javax.mail

I was trying to see if there was a way to search an email inbox from javax.mail. Say I wanted to send a query and have the it return emails to us. Can we parse returned HTML and extract data. Also, if the above is possible how would I "translate" those messages returned by that server to POP3 messages? E.g. we have extracted: Subject: Foo Body: Bar but to open same message using POP3 I nee...






Still can't find your answer? Check out these amazing Java communities for help...



Java Reddit Community | Java Help Reddit Community | Dev.to Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)



top