Solved

Java FetchProfile IMAP and UID in JavaMail

Posted on 2010-11-28
8
2,088 Views
Last Modified: 2013-11-19
Hi, I've seen tons of examples online of JavaMail using FetchProfile to get the UID of a message in POP3. The issue is I cannot use the same code (entirely) to get the UID in IMAP. (I understand the UIDs may be different as POP3 stores then as String, while IMAP as int).

So how can I get the UID of a message (with FetchProfile) when using IMAP?
0
Comment
Question by:amirsky
  • 3
  • 3
  • 2
8 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 34225451
0
 

Author Comment

by:amirsky
ID: 34225487
I am aware of that code - it is what I am using. The question is, after fetching how do I then extract the UID form the message?

After doing:

FetchProfile fp = new FetchProfile();
fp.add(UIDFolder.FetchProfileItem.UID);
folder.fetch(msgs, fp);

If I am in POP3 i get then get each message's UID with:

folder.getUID(message);

BUT this method is not available with a Folder of type IMAP (IMAPFolder)
So the question is again, how do I get the UID in such a situation?
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 250 total points
ID: 34225581
>>BUT this method is not available with a Folder of type IMAP (IMAPFolder)

See http://java.sun.com/products/javamail/javadocs/com/sun/mail/imap/IMAPFolder.html#getUID(javax.mail.Message)
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 92

Assisted Solution

by:objects
objects earned 250 total points
ID: 34226910
use something like the following:

if (folder instanceof UIDFolder) {
   uid = ((UIDFolder)folder).getUID(message);
}
0
 

Author Comment

by:amirsky
ID: 34228079
The values for FetchProfile any part of am email's content? I basicallt see the same exmaple over and over again using only 3 values at best (UID, ENVELOPE, Subject).
0
 
LVL 92

Expert Comment

by:objects
ID: 34228108
Really depends on the backend as to what is supported, some may not let you prefetch anything.

0
 
LVL 92

Expert Comment

by:objects
ID: 34228114
purely from a javamail perspective see FetchProfile.Item and its subclasses

http://java.sun.com/products/javamail/javadocs/javax/mail/FetchProfile.Item.html

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 34229397
:)
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question