Reputation: 369
Good morning everybody,
I am using Spring Integration to read incoming emails and parse them.
I would like to implement the following behaviour: move the email to a dedicated folder once it has been processed.
I have a Spring service getting and processing the email.
<!-- Mail listeners -->
<int:channel id="receiveChannel" datatype="javax.mail.internet.MimeMessage"/>
<int-mail:inbound-channel-adapter id="incomingEmailsAdapter"
store-uri="${inboundMail.storeUri}"
channel="receiveChannel"
should-delete-messages="false"
should-mark-messages-as-read="true"
auto-startup="${inboundMail.startup}"
java-mail-properties="javaMailInboundProperties">
<int:poller max-messages-per-poll="${inboundMail.nb.poll}" fixed-rate="${inboundMail.nb.rate}"/>
</int-mail:inbound-channel-adapter>
<int:service-activator id="serviceActivator" input-channel="receiveChannel" ref="mailService" method="handleMail"/>
In the handleMail method, when I am trying to access a folder where I can store the information, I always have an exception saying the folder doesn't exist. The method exists() on the folder always returns false.
public void handleMail(MimeMessage message) {
try {
...
Folder folder = message.getFolder();
folder.open(Folder.READ_WRITE);
Folder test = folder.getFolder("Transmitted");
My root folder is inbox. I have created a "Transmitted" folder. But when I test the "test" folder existence, false is always returned. As a consequence I cannot move my message to the "Transmitted" folder.
I have also tried this:
Store fstore = folder.getStore();
Folder successFolder = fstore.getFolder("Transmitted");
But the result is the same. successFolder.exists() returns false;
How should I access the folder?
Thanks in advance
Gilles
Upvotes: 4
Views: 1715
Reputation: 369
Got it working by using
Folder[] folders = folder.getStore().getDefaultFolder().list("*");
The name of the folder, in this case was: INBOX.Transmitted
Regards
Gilles
Upvotes: 2