Getting UID from message
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   venkat_subramanian
Posted On:   Wednesday, May 9, 2001 01:11 PM

How do I get UID from a message? How do I get a message by UID? Any code samples would help

Re: Getting UID from message

Posted By:   Tim_Boudreau  
Posted On:   Thursday, May 10, 2001 09:50 AM

Haven't tested it, but something like this should work (forgive any typos):


public long getUidFromMessage (Message m) {
long result = -1l;
try {
Folder f=getFolderInstancem.getFolder(); //get the folder object owning the message
ensureFolderOpen (f);
if (f instanceof UIDFolder) {
result=((UIDFolder) f).getUID(m);
}
} catch (MessagingException e) {
//if something goes wrong, the returned -1 value will indicate it,
//or you could throw an exception of some sort here,
//or just have this method throw MessagingException
}
return -1;
}

public void ensureFolderOpened (Folder f) {
//(open the folder here if it's not open already)
}



Note when opening the folder, watch out for a NullPointerException if you try to open a non-mailbox file the IMAP server is serving.

Re: Getting UID from message

Posted By:   venkat_subramanian  
Posted On:   Wednesday, May 9, 2001 06:30 PM

Got it, There is a nice example uidmsgshow.java under demo directory of JavaMail 1.2 download
About | Sitemap | Contact