Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Getting the first new Email out of a folder....

Posted on 2004-04-26
14
Medium Priority
?
356 Views
Last Modified: 2013-11-24
Hi all,
I want to search for the first new (UNSEEN) email in a folder through JavaMail. Am i correct in saying that there is no such method in the API, which is unusual?

So if there's not, whats the best way of getting it? Is it something like this?

Message m = null;
Flags flag[];
int nextNewMessage;

Message[] msgs = folder.getMessages();

for (int i = msgs.length; i == 0; i--) {
   flag[i] = msgs[i].getFlags();
   if (flag[i] == "SEEN") {              << I know its wrong, any help?!
           nextNewMessage = i;
   } // end if  
           
}


Also, i can do this to CREATE a new folder, right?
   folder.getFolder("Trash Can");
   folder.create(Folder.HOLDS_MESSAGES);


Thanks in Advance
0
Comment
Question by:BaconAndCabbage
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
  • +1
14 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 10919154
>>Am i correct in saying that there is no such method in the API, which is unusual?

Yes, if you're using POP (normal). There is no concept of seen/unseen in the protocol. The messages are either on the server or they've been deleted from it
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10919165
...so if you want to only look at new ones, you have to ensure you delete the messages from the server after getting them.
0
 

Author Comment

by:BaconAndCabbage
ID: 10919190
No, i'm actually using IMAP
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 7

Expert Comment

by:maheshexp
ID: 10919319
one such answer is posted in this forum...

http://www.jguru.com/faq/view.jsp?EID=26898
0
 
LVL 7

Expert Comment

by:maheshexp
ID: 10919338
UNSEEN, u mean a new Message....if iam correct,  need the new message, then sort all the messages by date and time, and pick out the recent one....
0
 
LVL 7

Expert Comment

by:maheshexp
ID: 10919343
0
 
LVL 7

Expert Comment

by:maheshexp
ID: 10919371
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10919375
I'm not familiar with IMAP, but i don't think even that has a concept of 'read/unread'. You could probably treat is as above, or move it into a different folder
0
 

Author Comment

by:BaconAndCabbage
ID: 10919514
Thanks for the replies, but i don't think the links help.
          "then sort all the messages by date and time, and pick out the recent one"
That won't work because an unread email need not neccessarily be the most recent one, ie a unread email may be days old.

Ya see, i can check the NUMBER of new Messages in a folder, thats not a problem - what i want to get is the position (ie, msgCount) of any new emails!

Thanks again, any solution would be greatly appreciated
0
 
LVL 14

Accepted Solution

by:
Tommy Braas earned 150 total points
ID: 10919550
The IMAP protocol is defined in http://www.faqs.org/rfcs/rfc3501.html

Change your code to read:
for (int j=0; j<flag[i].length; j++ ) {
   flags = msgs[i].getFlags();
   if ("\\Seen".equals(flag[j])) {
           nextNewMessage = i;
   } // end if  


More to the point is the fact that you can specify that you only want to receive unseen emails etc. Read the above document for more information.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10919556
The thing to do, if no changes are being done on the server, is to save the ids of the messages you HAVE read, and do a set intersection using those, leaving you with unread ones
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10919672
Interesting - so you can flag the message as \Seen. I'm always trying to find an elusive site where they've formatted these rfcs as html, but failing ;-)
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10919781
>>  I'm always trying to find an elusive site where they've formatted these rfcs as html, but failing ;-)
Yes, I haven't found one either...
0
 

Author Comment

by:BaconAndCabbage
ID: 10921006
As always lads, thanks a lot
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

604 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