martinrusev / imbox

Python IMAP for Human beings
MIT License
1.18k stars 188 forks source link

If there is way to specify the connection timeout #216

Open lexabug opened 2 years ago

lexabug commented 2 years ago

Hi there. For the feature I develop I'd like to specify the IMAP connection timeout, so the Imbox fails out after X seconds if it cannot establish connection with the host:port (for instance because of the firewall). How that can be done?

martinrusev commented 2 years ago

Hi @lexabug, Not possible with the current version, but should not be too complicated to implement. The timeout parameter has to be added here: https://github.com/martinrusev/imbox/blob/master/imbox/imap.py#L18

It will work only in Python 3.9 and 3.10 though

https://docs.python.org/3/library/imaplib.html

lexabug commented 2 years ago

In my project I'm bound to python v3.8 (hope we will upgrade soon). Looks like using socket.setdefaulttimeout is the way for me. Going to implement it as a context manger within my imbox wrapper.