2016-09-20 88 views
2

我需要獲取未刪除,但不會發生所有發送的郵件,但只顯示郵件總數,最近在控制檯mail.debug真正取從IMAP適配器Spring集成所有發送的郵件

<int:channel id="receiveChannel" /> 
    <int-mail:imap-idle-channel-adapter id="customAdapter" 
      store-uri="imaps://[email protected]:[email protected]:993/INBOX.Sent" 
      channel="receiveChannel" 
      auto-startup="true" 
      should-delete-messages="false" 
      should-mark-messages-as-read="false" 
      java-mail-properties="javaMailProperties"/> 

<util:properties id="javaMailProperties"> 
    <prop key="mail.imap.socketFactory.class">javax.net.ssl.SSLSocketFactory</prop> 
    <prop key="mail.imap.socketFactory.fallback">false</prop> 
    <prop key="mail.store.protocol">imaps</prop> 
    <prop key="mail.debug">true</prop> 
</util:properties> 




    public static void main (String[] args) throws Exception { 

      ApplicationContext ac = new ClassPathXmlApplicationContext("spring/gmail-imap-idle-config.xml"); 
      DirectChannel inputChannel = ac.getBean("receiveChannel", DirectChannel.class); 
      inputChannel.subscribe(new MessageHandler() { 
       public void handleMessage(Message<?> message) throws MessagingException { 

        MimeMessage mimeMessage = (MimeMessage) message.getPayload(); 



    } 
}); 
} 

回答

1

the documentation ,您需要使用自定義SearchTermStrategy

默認情況下,ImapMailReceiver將基於默認的搜索關鍵詞搜索消息是所有的郵件是近期(如果支持的話),這是沒有回答,也不會被刪除,這是沒有見過,也沒有被由該郵件接收器處理(通過使用自定義USER標記啓用,或者如果不支持,則簡單地不標記)。自定義用戶標誌爲spring-integration-mail-adapter,但可以進行配置。從版本2.2開始,ImapMailReceiver使用的SearchTerm可以通過SearchTermStrategy完全配置,您可以通過search-term-strategy屬性注入。 SearchTermStrategy是一個簡單的策略接口,只有一個方法可以讓你創建一個由ImapMailReceiver使用的SearchTerm實例。

+0

非常感謝您分享您寶貴的信息。 – rupak