From 22161b628d547b5f75165eb513a4b4ecac34101c Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Wed, 6 Nov 2024 10:56:06 -0500 Subject: [PATCH] GH-9633: MailReceiver: also set flags into `IntegrationMimeMessage` Fixes: #9633 Issue link: https://github.com/spring-projects/spring-integration/issues/9633 The message flags of the received messages are outdated and don't contain the changes of `AbstractMailReceiver#setMessageFlags`, because the flags are only applied to the original message and not the copy (`AbstractMailReceiver.IntegrationMimeMessage`). * Call `setMessageFlagsAndMaybeDeleteMessages()` for `IntegrationMimeMessage` copies as well (cherry picked from commit 1d85d6b43cdabdc1839543108a7aae2f5a9b47b5) --- .../springframework/integration/mail/AbstractMailReceiver.java | 3 +++ .../integration/mail/ImapMailReceiverTests.java | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) 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 1ba644a2a1..a85c0b51ec 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 @@ -516,6 +516,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 7f6bc7e057..375ae722ba 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 @@ -452,7 +452,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