这是我的代码,它应该收到未读消息。但是,它正在返回我收件箱中的最后一条消息。有什么建议么?
import javax.mail.*;
import javax.mail.internet.*;
import javax.mail.search.*;
import java.util.*;
import com.sun.mail.pop3.POP3SSLStore;
public class MailClient {
public static void main(String[] args) {
try {
Properties props = new Properties();
props.setProperty("mail.pop3.connectionpooltimeout", "3000");
props.setProperty("mail.pop3.connectiontimeout", "3000");
props.setProperty("mail.pop3.timeout", "3000");
Session session;
URLName url = new URLName("pop3","pop.gmail.com",995,"","email@gmail.com","pwd");
session = Session.getInstance(props, null);
Store store = new POP3SSLStore(session,url);
store.connect();
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
Flags seen = new Flags(Flags.Flag.SEEN);
FlagTerm unseenFlagTerm = new FlagTerm(seen,false);
Message message[] = folder.search(unseenFlagTerm);
for (int i=0, n = message.length;i<20;i++) {
System.out.println("Message " + (i + 1));
System.out.println("From : " + message[i].getFrom()[0]);
System.out.println("Subject : " + message[i].getSubject());
System.out.println("Sent Date : " + message[i].getSentDate());
}
folder.close(false);
store.close();
}
catch (MessagingException e) {
System.out.println("Error: " + e);
}
}
}