INT-3744: Fix IMAPMessage receivedDate

JIRA: https://jira.spring.io/browse/INT-3744

MimeMessages are copied to eagerly fetch IMAP messages, this process loses
the `receivedDate` property.

Keep a reference to the source Message and delegate to its `receiveDate()`.

Cover more "void" getters
This commit is contained in:
Gary Russell
2015-06-16 09:29:09 -04:00
committed by Artem Bilan
parent f32fd1967b
commit 58e99b01e1
2 changed files with 30 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
package org.springframework.integration.mail; package org.springframework.integration.mail;
import java.util.Date;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
@@ -434,8 +435,11 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl
*/ */
private class IntegrationMimeMessage extends MimeMessage { private class IntegrationMimeMessage extends MimeMessage {
private final MimeMessage source;
public IntegrationMimeMessage(MimeMessage source) throws MessagingException { public IntegrationMimeMessage(MimeMessage source) throws MessagingException {
super(source); super(source);
this.source = source;
} }
@Override @Override
@@ -448,5 +452,22 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl
} }
} }
@Override
public Date getReceivedDate() throws MessagingException {
/*
* Basic MimeMessage always returns null; delegate to the original.
*/
return this.source.getReceivedDate();
}
@Override
public int getLineCount() throws MessagingException {
/*
* Basic MimeMessage always returns '-1'; delegate to the original.
*/
return this.source.getLineCount();
}
} }
} }

View File

@@ -157,7 +157,12 @@ public class ImapMailReceiverTests {
adapter.setOutputChannel(channel); adapter.setOutputChannel(channel);
adapter.setTaskScheduler(taskScheduler); adapter.setTaskScheduler(taskScheduler);
adapter.start(); adapter.start();
assertNotNull(channel.receive(6000)); @SuppressWarnings("unchecked")
org.springframework.messaging.Message<MimeMessage> received =
(org.springframework.messaging.Message<MimeMessage>) channel.receive(6000);
assertNotNull(received);
assertNotNull(received.getPayload().getReceivedDate());
assertTrue(received.getPayload().getLineCount() > -1);
assertNotNull(channel.receive(6000)); // new message after idle assertNotNull(channel.receive(6000)); // new message after idle
assertNull(channel.receive(10000)); // no new message after second and third idle assertNull(channel.receive(10000)); // no new message after second and third idle
verify(logger).debug("Canceling IDLE"); verify(logger).debug("Canceling IDLE");
@@ -755,9 +760,9 @@ public class ImapMailReceiverTests {
@Override @Override
public void publishEvent(Object event) { public void publishEvent(Object event) {
} }
}); });
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.initialize(); taskScheduler.initialize();