'Switch to encrypted communication using TLS.
The first step of switching to encrypted communication is obtaining
the server\'s capabilities.  When that is complete, the L{_startTLS}
callback function continues the switching process.
@type contextFactory: L{None} or
L{ClientContextFactory <twisted.internet.ssl.ClientContextFactory>}
@param contextFactory: The context factory with which to negotiate TLS.
If not provided, try to create a new one.
@rtype: L{Deferred <defer.Deferred>} which successfully results in
L{dict} mapping L{bytes} to L{list} of L{bytes} and/or L{bytes} to
L{None} or fails with L{TLSError}
@return: A deferred which fires when the transport has been
secured according to the given context factory with the server
capabilities, or which fails with a TLS error if the transport
cannot be secured.'

def startTLS(self, contextFactory=None):

    tls = interfaces.ITLSTransport(self.transport, None)
    if (tls is None):
        return defer.fail(TLSError('POP3Client    transport    does    not    implement    interfaces.ITLSTransport'))
    if (contextFactory is None):
        contextFactory = self._getContextFactory()
    if (contextFactory is None):
        return defer.fail(TLSError('POP3Client    requires    a    TLS    context    to    initiate    the    STLS    handshake'))
    d = self.capabilities()
    d.addCallback(self._startTLS, contextFactory, tls)
    return d
