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 696ed10aa2
commit b2385087c9
2 changed files with 29 additions and 3 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");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
package org.springframework.integration.mail;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
@@ -430,8 +431,11 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl
*/
private class IntegrationMimeMessage extends MimeMessage {
private final MimeMessage source;
public IntegrationMimeMessage(MimeMessage source) throws MessagingException {
super(source);
this.source = source;
}
@Override
@@ -444,5 +448,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

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -157,7 +157,12 @@ public class ImapMailReceiverTests {
adapter.setOutputChannel(channel);
adapter.setTaskScheduler(taskScheduler);
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
assertNull(channel.receive(10000)); // no new message after second and third idle
verify(logger).debug("Canceling IDLE");