不能使用SearchTerm

不能使用SearchTerm

本文介绍了不能使用SearchTerm term = new MessageIDTerm(ID)来按message-ID搜索邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android上开发电子邮件应用程序,我被困在这里.如果我使用Gmail服务器,则可以按ID搜索电子邮件

Iam developing an Email application on Android and I got stuck at here. If I use Gmail server I can search Email by ID

  SearchTerm term = new MessageIDTerm(ID);
  message_s = folder.search(term);

但是使用此代码,我无法使用yahoo,hotmail之类的其他服务器来搜索电子邮件.我尝试通过覆盖此代码来解决此错误

But with this code, I can't search email with some Other server like yahoo,hotmail. And I try solve this bug by override this code

SearchTerm messageIDTerm= new SearchTerm() {
@Override
 public boolean match(Message message) {
 try {
    String   messageID="";
Enumeration headers = message.getAllHeaders();

   while (headers.hasMoreElements()) {
    eader h = (Header) headers.nextElement();
    String mID = h.getName();
    if(mID.contains("Message-ID") || mID.contains("Message-Id")){
    messageID= h.getValue();
    }
    }
    if (messageID.contains(ID)) {
     return true;
    }
    } catch (MessagingException ex) {
    ex.printStackTrace();
    }
    return false;
    }
    };
   message_s = folder.search(messageIDTerm);

搜索邮件成功.但是问题在于此代码通过客户端搜索检查每个Message-ID(下载messeage-ID并进行比较),并且花费大量时间来找到结果.

It's success to search mail. But the problem is this code check every Message-ID by client search(download messeage-ID and compare) and it take a lot of time to find the result.

第一种方法是,服务器对我的请求进行检查,而且速度非常快.

The first way, server make a seach for my request and its very fast.

那么,如果我使用第二种方法,如何使搜索速度与第一种方法一样快?

So how do I make the search as fast as the first way if I use the second way?

推荐答案

某些服务器已损坏.您无法修复它们.

Some servers are broken. You can't fix them.

如果必须在客户端中进行搜索,则最好的方法是使用Folder.fetch方法预取将需要进行搜索的标头.然后,在遍历所有需要检查的消息时,将标准MessageIDTerm与Message.match方法一起使用.

If you have to do the search in the client, the best you can do is use the Folder.fetch method to prefetch the headers you're going to need to do the search. Then use the standard MessageIDTerm with the Message.match method as you iterate over all the messages you need to check.

这篇关于不能使用SearchTerm term = new MessageIDTerm(ID)来按message-ID搜索邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 10:54