CFImap This operation is not allowed on a closed folder

Description

This error is eating my lunch on a client integration trying to use cfimap. The call is just something like this

cfimap( server="outlook.office365.com", username="xxx@yyy.com", password="zzz", action="GetAll", attachmentpath="#Save_Path#", name="local.qGetMessages", generateuniquefilenames="yes", maxrows="20", port="993", secure="yes", timeout="30" );

Basically, there is some scenario where the imap connection is failing and already closed BEFORE Lucee tries to close it. When Lucee tries to close, this error happens:

lucee.runtime.exp.NativeException: This operation is not allowed on a closed folder at com.sun.mail.imap.IMAPFolder.close(IMAPFolder.java:1510) at com.sun.mail.imap.IMAPFolder.close(IMAPFolder.java:1484) at lucee.runtime.net.mail.MailClient.getMails(MailClient.java:321) at lucee.runtime.tag._Mail.doStartTag(_Mail.java:269) at models.infaximporter_cfc$cf.udfCall(/autotasks/models/InFaxImporter.cfc:26 ...

You can see the folder.close() is happening inside of a finally block with no regard to whether an exception already happened or testing to see if the folder is still open. Right now, that secondary error is completely hiding the “real” error from us.

https://github.com/lucee/Lucee/blob/5.3/core/src/main/java/lucee/runtime/net/mail/MailClient.java#L321

The easiest fix for now is probably to wrap the folder.close() in its own try catch so any exceptions from the outer try will still be seen.

Environment

None

Activity

Show:

Pothys - MitrahSoft 10 October 2022 at 09:58

I've checked this ticket and confirmed the issue happened on the lucee latest version 5.3.10.80-SNAPSHOT. I replicate the issue using the above code.

When using cfimap action="GetAll" if the user has large number of emails in their inbox means it throws an error like This operation is not allowed on a closed folder.

Brad Wood 7 October 2022 at 17:53

FWIW, I tested my suggested workaround and while it avoids blowing up on the stack above, it just threw the same error from another location.

lucee.runtime.exp.NativeException: This operation is not allowed on a closed folder at com.sun.mail.imap.IMAPFolder.checkOpened(IMAPFolder.java:478) at com.sun.mail.imap.IMAPFolder.getUID(IMAPFolder.java:2739) at lucee.runtime.net.imap.ImapClient._getId(ImapClient.java:38) at lucee.runtime.net.mail.MailClient.getId(MailClient.java:437) at lucee.runtime.net.mail.MailClient.getMessages(MailClient.java:423) at lucee.runtime.net.mail.MailClient.getMails(MailClient.java:318) at lucee.runtime.tag._Mail.doStartTag(_Mail.java:269) at models.infaximporter_cfc$cf.udfCall(/autotasks/models/InFaxImporter.cfc:26

Clearly the folder is getting unexpectedly closed in another thread and any further operations by cfimap are going to fail as soon as they try to use it. What I can’t figure out is WHY the folder is closed and what cfimap can do to better message the issue. Based on the time it’s taking, I assume this is a timeout even though I’ve set my timeout attribute on the cfimap tag very high and the error is happening prior to that. This only happens when the imap server is slow and there are a lot of messages after a delay of 30 seconds or so. There must be some additional logging or error handling we can enable in Java to detect what’s really happening and why the folder is getting closed.

Details

Assignee

Reporter

Priority

Labels

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Created 6 October 2022 at 18:16
Updated 10 October 2022 at 09:58

Flag notifications