简体   繁体   English

使用Javamail从邮件列表中查找特定的未读邮件

[英]Finding a specific unread mail from list of mails using Javamail

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 ) (我不得不这样做,因为我找不到任何直接的API来获取新邮件列表。一个帮助查找邮件是否未读的问题已发布在此处

     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 遍历未读邮件列表>检查是否有邮件主题,然后阅读邮件内容>如果找不到此类邮件,则抛出IllegalStateExcepton

Now my question is - Could I improve on this approach? 现在我的问题是-我可以改进这种方法吗?

Can you use 你能用吗

Folder.search(SearchTerm): Message[]

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

with the relevant SearchTerm, eg FlagTerm for the unread flag 与相关的SearchTerm一起使用,例如,未读标志的FlagTerm

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

Quick search on Google found this 在Google上进行的快速搜索发现了这一点

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

which might be useful, but I haven't tried it 这可能是有用的,但我还没有尝试过

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM