2016-11-27 1 views
0

나는 단지 오래된 우편물을 얻는 부호를 달릴 것이다, 그러나 나는 새로운, 읽지 않은 우편물 인 특별한 주제가있는 우편물을 ..... 얻어야한다 ..... 무엇이 문제인가?JavaMail IMAP. 나는 최신 우편물을 얻지 않는다

감사

public static void dumpMail() throws FileNotFoundException, IOException, MessagingException, FolderClosedException, SocketTimeoutException { 

Properties props = new Properties(); 
    String username = "ad\\" + "x"; 
    String password = "y"; 
    props.put("mail.imaps.host", "z"); 
    props.put("mail.imaps.port", "993"); 
    props.put("mail.imaps.connectiontimeout", "10000"); 
    props.put("mail.imaps.timeout", "10000"); 
    props.put("host", "z"); 
    props.put("user", username); 
    props.put("pass", password); 

    Session session = Session.getDefaultInstance(props, null); 

    Store store = session.getStore("imaps"); 
    store.connect("z", username, password); 

    Folder inbox = store.getFolder("inbox"); 
    inbox.open(Folder.READ_ONLY); 

    Flags seen = new Flags(Flags.Flag.SEEN); 
    FlagTerm unseenFlagTerm = new FlagTerm(seen, false); 

    Flags recent = new Flags(Flags.Flag.RECENT); 
    FlagTerm recentFlagTerm = new FlagTerm(recent, true); 

    SearchTerm searchTerm = new AndTerm(unseenFlagTerm, recentFlagTerm); 
    Message[] messages = inbox.search(searchTerm); 

    for (int i = 0; i < 30; i++) { 
     if (messages[i].getSubject().contains("Zeiterfassung")) { 
     System.out.println(messages[i].getContent());   
     } 
     } 
} 

답변

0

다른 응용 프로그램이 동일한받은 편지함에 액세스하는 것이 가능합니까? 이들은 RECENT 플래그를 지우거나 SEEN 플래그를 설정할 수 있습니다.

SEEN == false 또는 RECENT == true 만 검색하십시오. 전자의 경우 다시 검색하기 전에 모든 메시지를 표시해야합니다.

마지막 검색 이후 새로운 메시지 만 검색하려면 더 나은 방법은 이전에 본 마지막 UID를 추적하고 더 큰 UID가있는 메시지 만 고려하는 것입니다.

또한 제목 검색을 SearchTerm에 통합하고 서버가 해당 제목에서 검색 작업을 수행 할 수 있습니다.

관련 문제