Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6210097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:06:02+00:00 2026-05-24T06:06:02+00:00

MY approach is – Get the total mail list – List<Message> totalMessageList = Arrays

  • 0

MY approach is –

  1. Get the total mail list –

    List<Message> totalMessageList = Arrays
                .asList(folder.getMessages());
    
  2. Create a list out of this which has only unread mails. (I had to do this coz I could not find a any direct API to get list of new mails. One question which helped in finding whether a message is unread or not was posted here)

    List<Message> unreadMessageList = new ArrayList<Message>();
    

    For sake of brevity I have not posted entire logic of building the list of unread mail from list of total mails.

  3. Iterate through the list of unread mails > Check if any mail has desired subject then read content of mail > If no such mail found then throw IllegalStateExcepton

Now my question is – Could I improve on this approach?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T06:06:04+00:00Added an answer on May 24, 2026 at 6:06 am

    Can you use

    Folder.search(SearchTerm): Message[]
    

    http://javamail.kenai.com/nonav/javadocs/javax/mail/Folder.html#search%28javax.mail.search.SearchTerm%29

    with the relevant SearchTerm, e.g. FlagTerm for the unread flag

    http://javamail.kenai.com/nonav/javadocs/javax/mail/search/FlagTerm.html

    Quick search on Google found this

    http://www.java2s.com/Code/Java/Email/Searchthegivenfolderformessagesmatchingthegivencriteria.htm

    which might be useful, but I haven’t tried it

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the approach in this article to return a list of objects
Is this good approach to get data from stored procedure? For example procedure is
I'm using an approach for this thread in order to make gallery change one
In my first approach with Rails I have simply create a void SayController and
Using this approach I have made my static method calls an Action in the
For our approach we want to create one of the *.config files from scratch
I know how to approach this problem but i have very little experience dealing
Which approach is better for styling windows: 1. Properties in the elements like this:
I was using this approach to make the background of my OpenGL application transparent
My approach to this question might be completely wrong, so please don't hesitate to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.