Example usage for org.apache.commons.net.pop3 POP3SClient execTLS

List of usage examples for org.apache.commons.net.pop3 POP3SClient execTLS

Introduction

In this page you can find the example usage for org.apache.commons.net.pop3 POP3SClient execTLS.

Prototype

public boolean execTLS() throws SSLException, IOException 

Source Link

Document

The TLS command execution.

Usage

From source file:com.adaptris.mail.ApachePOP3S.java

@Override
void postConnectAction(POP3SClient client) throws MailException, IOException {
    if (!implicitSSL && !client.execTLS()) {
        throw new MailException("Could not negotiate TLS after connect.");
    }//from  w  w  w.j a  v  a 2s .  c o m
}

From source file:org.apache.james.protocols.pop3.AbstractStartTlsPOP3ServerTest.java

@Test
public void testStartTls() throws Exception {
    InetSocketAddress address = new InetSocketAddress("127.0.0.1", TestUtils.getFreePort());

    ProtocolServer server = null;//from  ww w  .ja  v  a  2s  . c om
    try {
        String identifier = "id";
        TestPassCmdHandler handler = new TestPassCmdHandler();

        handler.add("valid", new MockMailbox(identifier));
        server = createServer(createProtocol(handler), address,
                Encryption.createStartTls(BogusSslContextFactory.getServerContext()));
        server.bind();

        POP3SClient client = createClient();
        client.connect(address.getAddress().getHostAddress(), address.getPort());

        // TODO: Make use of client.capa() once possible
        //       See NET-438
        assertEquals(POP3Reply.OK, client.sendCommand("CAPA"));
        client.getAdditionalReply();

        boolean startTlsCapa = false;
        for (String cap : client.getReplyStrings()) {
            if (cap.equalsIgnoreCase("STLS")) {
                startTlsCapa = true;
                break;
            }
        }
        assertTrue(startTlsCapa);

        assertTrue(client.execTLS());
        // TODO: Reenable when commons-net 3.1.0 was released
        //       See NET-430
        //
        //assertTrue(client.logout());
        client.disconnect();

    } finally {
        if (server != null) {
            server.unbind();
        }
    }

}