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

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

Introduction

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

Prototype

public int sendCommand(String command) throws IOException 

Source Link

Document

Sends a command with no arguments to the server and returns the reply code.

Usage

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   w  ww  .j  av a 2 s .  c  o  m
    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();
        }
    }

}