Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between IMAPMessage.getUID() and Message-ID header?

What is the difference between these two from java mail perspective? I can see that 2 values are not same for a particular message. So what should I consider an IMAP message's unique id?

If I need to fetch message from an IMAP server corresponding to an unique id, should I use?

MessageIDTerm

or

IMAPFolder.getMessageByUID()
like image 737
Anindya Chatterjee Avatar asked Feb 08 '23 01:02

Anindya Chatterjee


1 Answers

UID is the unique identification number of a email in a IMAP folder. Each mail in a folder is assigned a uid, it is you can say a index maintained by the mail folder. Whereas message-id is a header part of a email.

To understand in a simple term, UID is a unique number which cannot be duplicated within a folder. If I copy same email twice in a folder, each will have same headers having same message-id but will have a different UID.

Other major difference is,

  • UID's are assigned by a imap server
  • MessageId's are set by the email client.

So it is always better to rely on a UID to extract the email.

Refer : RFC - UID

like image 65
Sandeep Sukhija Avatar answered Apr 28 '23 13:04

Sandeep Sukhija