Javax Mail getMesseges和Search返回0,而不应该

时间:2013-10-03 16:28:20

标签: java javax.mail

这是我使用的代码:

Session session = Session.getInstance(new Properties(), null);
store = session.getStore("pop3s");
store.connect(host, username, password);
inbox = store.getFolder("INBOX");
inbox.open(Folder.READ_ONLY);
message=inbox.getMessages();
System.out.println(message==null ? "null" : message.length);
final Calendar calender = Calendar.getInstance();
calender.add(Calendar.MONTH, -1);
SearchTerm term = new SearchTerm() {
    public boolean match(Message message) {
        try {
            if (message.getSentDate().getTime()>calender.getTime().getTime()) {
                return true;
            }
        } catch (MessagingException ex) {
            ex.printStackTrace();
        }
        return false;
    }
};
message = inbox.search(term);
System.out.println(message==null ? "null" : message.length);

我也尝试过:

Session session = Session.getInstance(new Properties(), null);
store = session.getStore("pop3s");
store.connect(host, username, password);
inbox = store.getFolder("INBOX");
inbox.open(Folder.READ_WRITE);
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MONTH, -1);
ReceivedDateTerm term  = new ReceivedDateTerm(ComparisonTerm.GT,cal.getTime());
message = inbox.search(term);
System.out.println(message==null ? "null" : message.length);

但我得到的是0个消息,而当我手动登录GMail时,我确实看到了相关的消息,我做错了什么?

0 个答案:

没有答案