2015-09-01 43 views
2

我使用Spring Integration中的Pop3MailReciever連接到POP3郵件服務器。我想在處理它之後刪除該消息。我嘗試設置了ShouldDeleteMessages標誌,但它不會刪除該消息。 這是執行輪詢的代碼:Pop3MailReciever不會刪除郵件

@SpringBootApplication 
public class EmailPollerApplication { 

public static void main(String[] args) { 
    SpringApplication.run(EmailPollerApplication.class, args); 
} 

@Bean 
IntegrationFlow pollingFlow() { 
    return IntegrationFlows 
      .from(mailReceivingMessageSource(), e -> e.poller(Pollers.fixedDelay(60000L))) 
      .transform(mailTransformer()) 
      .transform(requestTransformer()) 
      .handle(wsGateway()) 
      .channel("nullChannel") 
      .get(); 
} 

@Bean 
MailReceivingMessageSource mailReceivingMessageSource(){ 

    Pop3MailReceiver pop3MailReceiver = new Pop3MailReceiver("mailserver.example.com", 110, "username", "password"); 

    pop3MailReceiver.setShouldDeleteMessages(true); 
    pop3MailReceiver.setMaxFetchSize(1); 

    MailReceivingMessageSource mailReceivingMessageSource = new MailReceivingMessageSource(pop3MailReceiver); 
    return mailReceivingMessageSource; 
} 

這是從Pop3MailReciever是應該被刪除消息的代碼:

@Override 
protected void deleteMessages(Message[] messages) throws  MessagingException { 
    super.deleteMessages(messages); 
    // expunge deleted mails, and make sure we've retrieved them before closing the folder 
    for (int i = 0; i < messages.length; i++) { 
     new MimeMessage((MimeMessage) messages[i]); 
    } 
} 

的super.deleteMessages(消息)設置刪除標誌在消息。這一切都很好,但服務器上沒有任何事情發生。我的tcpdump正在運行,而我的應用程序正在運行,並且DELE POP3命令從未運行。

回答

1

mail.debug javamail屬性設置爲true並查看輸出。

我只是跑,沒有任何問題的測試...

DEBUG POP3: connecting to host "localhost", port 52026, isSSL false 
+OK POP3 
CAPA 
+OK 
USER 
. 
DEBUG POP3: server doesn't support TOP, disabling it 
DEBUG POP3: authentication command trace suppressed 
DEBUG POP3: authentication command succeeded 
2015-09-01 08:14:21,913 Pop3MailReceiver [task-scheduler-1] : opening folder [pop3://user:*****@localhost:52026/INBOX] 
STAT 
+OK 1 3 
2015-09-01 08:14:21,914 Pop3MailReceiver [task-scheduler-1] : attempting to receive mail from folder [INBOX] 
NOOP 
+OK 
2015-09-01 08:14:21,927 Pop3MailReceiver [task-scheduler-1] : found 1 new messages 
RETR 1 
+OK 
To: [email protected] 
From: [email protected] 
Subject: Test Email 

foo 
. 
2015-09-01 08:14:21,930 Pop3MailReceiver [task-scheduler-1] : Received 1 messages 
2015-09-01 08:14:21,930 Pop3MailReceiver [task-scheduler-1] : USER flags are not supported by this mail server. Flagging message with system flag 
NOOP 
+OK 
DELE 1 
+OK 
QUIT 
+OK 
+0

我這樣做,輸出功率爲除重要組成部分非常相似。這是會議的尾聲: '測試 。 NOOP + OK QUIT + OK' – Rodjer

+0

嗯 - 什麼版本的Spring集成?什麼版本的javamail?我測試了4.2快照和javamail 1.5.2。 –

+0

即時通訊使用Spring Integration 4.1.5和javamail 1.4.7。儘管我發現了這個問題。 AbstractMailReceiver的folderOpenMode設置爲Folder.READ_ONLY。它設置爲Folder.READ_WRITE的唯一位置是在onInit()方法中,但永遠不會調用它。你知道讓AbstractMailReceiver以讀/寫模式打開文件夾的恰當方法嗎? – Rodjer