diff --git a/spring-integration-mail/src/main/java/org/springframework/integration/mail/AbstractMailReceiver.java b/spring-integration-mail/src/main/java/org/springframework/integration/mail/AbstractMailReceiver.java index 36a2aca4b1..2086d930d2 100755 --- a/spring-integration-mail/src/main/java/org/springframework/integration/mail/AbstractMailReceiver.java +++ b/spring-integration-mail/src/main/java/org/springframework/integration/mail/AbstractMailReceiver.java @@ -529,6 +529,9 @@ private void postProcessFilteredMessages(Message[] filteredMessages) throws Mess } setMessageFlagsAndMaybeDeleteMessages(messages); + if (filteredMessages.length > 0 && filteredMessages[0] instanceof IntegrationMimeMessage) { + setMessageFlagsAndMaybeDeleteMessages(filteredMessages); + } } private void setMessageFlagsAndMaybeDeleteMessages(Message[] messages) throws MessagingException { diff --git a/spring-integration-mail/src/test/java/org/springframework/integration/mail/ImapMailReceiverTests.java b/spring-integration-mail/src/test/java/org/springframework/integration/mail/ImapMailReceiverTests.java index 83f7ca8cd0..2b5dba0e47 100644 --- a/spring-integration-mail/src/test/java/org/springframework/integration/mail/ImapMailReceiverTests.java +++ b/spring-integration-mail/src/test/java/org/springframework/integration/mail/ImapMailReceiverTests.java @@ -449,7 +449,7 @@ public void receiveMarkAsReadAndDelete() throws Exception { assertThat(msg1.getFlags().contains(Flag.SEEN)).isTrue(); assertThat(msg2.getFlags().contains(Flag.SEEN)).isTrue(); - verify(receiver, times(1)).deleteMessages(Mockito.any()); + verify(receiver, times(2)).deleteMessages(Mockito.any()); } @Test