Cannot connect to IMAP server in Python 3.2

Keith Medcalf kmedcalf at dessus.com
Fri Apr 6 22:35:09 EDT 2012


Steve Howell <showell30 at yahoo.com> wrote in news:ae774035-9db0-469d-aa2a-
02f2d25ff7ce at qg3g2000pbc.googlegroups.com:

> Once you are able to import ssl, you should be able to use IMAP4_SSL,
> but that still doesn't entirely explain to me why you got a timeout
> error with plain IMAP4 and the proper port.  (I would have expected a
> failure, but of a different kind.)

Connecting to the SSL socket requires that one initiate the TLS handshake 
forthwith.  Establishing a connection to an "I expect SSL from the get-
go" using a protocol that speaks "I am a normal unencrypted socket but 
you can initiate TLS using the starttls command" is not the same thing.

In other words, you are violating the requirements of the protocol, and 
you are timing out.  This is because the first protocol step in a 
standard connection is to wait for the plain-text greeting, where the 
first step in connecting to the SSL socket is to do a TLS dance, then 
initiate the IMAP protocol by sending the greeting.

If you connect with a non-SSL initiator to an SSL endpoint, you will get 
a timeout.  If you connect with an SSL initiator to a non-SSL endpoint, 
you will timeout.  It is not the connection that is timing out, it is the 
protocol.

> I'd still be curious to see what happens when you try this:
> 
>    import socket, imaplib
>    your_host_name = # ...
>    socket.create_connection((your_host_name, imaplib.IMAP4_SSL_PORT))

This will, of course, work just fine.  You will not see a +Hello however 
until you have completed the TLS negotiation.



More information about the Python-list mailing list