jakartaee / mail-api

Jakarta Mail Specification project
https://jakartaee.github.io/mail-api
Other
239 stars 100 forks source link

New API to cancel a running long imap request #581

Open gbulfon opened 2 years ago

gbulfon commented 2 years ago

Description of the problem When a long operation is running on a folder (e.g. search/sort of 100.000 or more msgs with a message body pattern term), I may want to cancel that operation before it's finished. I don't think that a "close" or "forceClose" would do the job. What happens is that if the user (using the GUI) is canceling the search, the code instructs the search thread to cancel everything asap, but that asap will be actually "when the imap server will answer", and this may be many minutes, time when the CPU may be working hard searching for nothing, and the same user may issue another search to try again, driving mad the CPU.

Describe the solution you'd like If not still available, some API call on folder to let it cancel any running protocol operation.

Describe alternatives you've considered Using close would probably hang until end of operations, using forceClose would return but probably not stop the imap operation stealing cpu cycles.

jbescos commented 2 years ago

Did you try this?: https://github.com/eclipse-ee4j/angus-mail/blob/863616735b2f9732b5f32ddae050d5471c2a25d6/providers/imap/src/main/java/com/sun/mail/imap/IMAPFolder.java#L1468

I think socket will be closed, throwing an IOException and stopping current thread execution.