Accessing the socket used by `IMAPClient`
BoniLindsley opened this issue · comments
To watch a mailbox using IDLE, the current documentation suggests using a busyloop with a relatively small timeout to check for responses. A small timeout because IMAPClient.idle_check
uses a blocking poll with this timeout and handling KeyboardInterrup
is not possible while it blocks. An alternative to the busy loop was suggested in #322, using select.select
to poll both the connecting socket and a separate socket.
However, in order to poll the socket, access to the underlying socket is required, available as IMAPClient._sock
. My understanding is that this attribute is an implementation detail. Can this be relied upon? If not, is it possible to make the socket available as part of the API?
I'd be open to exposing the underlying socket via a socket() method, along with "here be dragons" style documentation :)
Recent versions of imaplib in the standard library already have a socket() method.
That would be great. And indeed, I think it quite common for handles to be exposed, with nasal demons attached!
I will see about making a pull request at some point. I have not looked into how tests are done in this code base, so that should be interesting.