The connection socket is initialized before actually creating the connection object. This means that setting the socket timeout after connecting to server could still lead to an endless connection if a timeout is produced while connecting.
To fix this problem, I opened https://bugs.python.org/issue38615 (which explains the problem in `imaplib` itself) and I publish here the workaround.
`poplib` supports setting the timeout before initializing the connection, so it's used instead of the workaround.
@Tecnativa TT20364
closesodoo/odoo#89717
X-original-commit: e0d7dffe167b642f14fdc207ebd80fafb1d82e3d
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>