Package org.apache.commons.net.pop3

Examples of org.apache.commons.net.pop3.POP3Client


    messages.put("headers", RestV2IT.addMessage(EMAIL_REGULAR, labelId));
    messages.put("attach", RestV2IT.addMessage(EMAIL_LARGE_ATT, labelId));

    // initialize POP3 client
    POP3Client client = new POP3Client();
    client.connect(POP3_HOST, POP3_PORT);

    // Login
    boolean loginSuccess = client.login(TEST_ACCOUNT, TEST_PASSWORD);
    assertThat(loginSuccess, is(true));

    // LIST all messages
    POP3MessageInfo[] info = client.listMessages();
    assertThat(info.length, equalTo(2));

    // DELE message 1
    boolean deleteResult = client.deleteMessage(1);
    assertThat(deleteResult, is(true));

    // LIST remaining
    info = client.listMessages();
    assertThat(info.length, equalTo(1));

    // DELE message 1 again
    deleteResult = client.deleteMessage(1);
    assertThat(deleteResult, is(false));
   
    // LIST remaining
    info = client.listMessages();
    assertThat(info.length, equalTo(1));

    // DELE message 2
    deleteResult = client.deleteMessage(2);
    assertThat(deleteResult, is(true));

    info = client.listMessages();
    assertThat(info.length, equalTo(0));

    // QUIT so the messages get expunged
    boolean logoutSuccess = client.logout();
    assertThat(logoutSuccess, is(true));

    // reconnect
    client.connect(POP3_HOST, POP3_PORT);

    // Login
    loginSuccess = client.login(TEST_ACCOUNT, TEST_PASSWORD);
    assertThat(loginSuccess, is(true));

    info = client.listMessages();
    assertThat(info.length, equalTo(0));

    logoutSuccess = client.logout();
    assertThat(logoutSuccess, is(true));
  }
View Full Code Here


    Integer labelId = ReservedLabels.POP3.getId();
    RestV2IT.addMessage(EMAIL_REGULAR, labelId);

    // initialize POP3 client
    POP3Client client = new POP3Client();
    client.connect(POP3_HOST, POP3_PORT);

    // Login
    boolean loginSuccess = client.login(TEST_ACCOUNT, TEST_PASSWORD);
    assertThat(loginSuccess, is(true));

    // LIST all messages
    POP3MessageInfo[] info = client.listMessages();
    assertThat(info.length, equalTo(1));

    // DELE message 1
    boolean deleteResult = client.deleteMessage(1);
    assertThat(deleteResult, is(true));

    // LIST remaining
    info = client.listMessages();
    assertThat(info.length, equalTo(0));

    // RSET. After this the deleted mark should be removed again
    boolean resetRestult = client.reset();
    assertThat(resetRestult, is(true));

    // LIST all messages
    info = client.listMessages();
    assertThat(info.length, equalTo(1));

    // Logout
    boolean logoutSuccess = client.logout();
    assertThat(logoutSuccess, is(true));
  }
View Full Code Here

    Integer labelId = ReservedLabels.POP3.getId();
    RestV2IT.addMessage(EMAIL_REGULAR, labelId);
    RestV2IT.addMessage(EMAIL_LARGE_ATT, labelId);

    // initialize POP3 client
    POP3Client client = new POP3Client();
    client.connect(POP3_HOST, POP3_PORT);

    boolean loginSuccess = client.login(TEST_ACCOUNT, TEST_PASSWORD);
    assertThat(loginSuccess, is(true));

    POP3MessageInfo info = client.status();
    assertThat(info.size, equalTo((int) (mailSizeRegular + mailSizeAttach)));
    assertThat(info.number, equalTo(2));

    // Logout
    boolean logoutSuccess = client.logout();
    assertThat(logoutSuccess, is(true));
  }
View Full Code Here

    Integer labelId = ReservedLabels.POP3.getId();
    RestV2IT.addMessage(EMAIL_SIMPLE, labelId);

    // initialize POP3 client
    POP3Client client = new POP3Client();
    client.connect(POP3_HOST, POP3_PORT);

    // Login
    boolean loginSuccess = client.login(TEST_ACCOUNT, TEST_PASSWORD);
    assertThat(loginSuccess, is(true));

    // RETR message
    Reader retrMessage = client.retrieveMessage(1);
    assertThat(retrMessage, notNullValue());

    checkMessage(EMAIL_SIMPLE, retrMessage);
    retrMessage.close();
   
        // RETR non-existing message
    retrMessage = client.retrieveMessage(10);
        assertThat(retrMessage, nullValue());
       
        // Delete and RETR the message again
    boolean deleteResult = client.deleteMessage(1);
    assertThat(deleteResult, is(true));
   
    retrMessage = client.retrieveMessage(1);
        assertThat(retrMessage, nullValue());
  }
View Full Code Here

    Integer labelId = ReservedLabels.POP3.getId();
    RestV2IT.addMessage(EMAIL_SIMPLE, labelId);

    // initialize POP3 client
    POP3Client client = new POP3Client();
    client.connect(POP3_HOST, POP3_PORT);

    // Login
    boolean loginSuccess = client.login(TEST_ACCOUNT, TEST_PASSWORD);
    assertThat(loginSuccess, is(true));

    // TOP message with all lines
    Reader topMessage = client.retrieveMessageTop(1, 1000);
    assertThat(topMessage, notNullValue());
    checkMessage(EMAIL_SIMPLE, topMessage);
    topMessage.close();

    // TOP message with 5 lines
    topMessage = client.retrieveMessageTop(1, 5);
    assertThat(topMessage, notNullValue());
    checkMessage(EMAIL_SIMPLE, topMessage, 5);
    topMessage.close();

    // TOP non-existing message
    topMessage = client.retrieveMessageTop(10, 10);
    assertThat(topMessage, nullValue());

    // Delete and TOP the message again
    boolean deleteResult = client.deleteMessage(1);
    assertThat(deleteResult, is(true));

    topMessage = client.retrieveMessageTop(1, 1000);
    assertThat(topMessage, nullValue());
  }
View Full Code Here

    messages.put("headers", RestV2IT.addMessage(EMAIL_REGULAR, labelId));
    messages.put("attach", RestV2IT.addMessage(EMAIL_LARGE_ATT, labelId));

    // initialize POP3 client
    POP3Client client = new POP3Client();
    client.connect(POP3_HOST, POP3_PORT);

    boolean loginSuccess = client.login(TEST_ACCOUNT, TEST_PASSWORD);
    assertThat(loginSuccess, is(true));

    // LIST all messages
    POP3MessageInfo[] info = client.listMessages();
    assertThat(info.length, equalTo(2));
    assertThat((int) mailSizeAttach, equalTo(info[0].size));
    assertThat((int) mailSizeRegular, equalTo(info[1].size));
    assertThat(info[0].number, equalTo(1));
    assertThat(info[1].number, equalTo(2));

    // LIST one message
    POP3MessageInfo msgInfo = client.listMessage(1);
    assertThat((int) mailSizeAttach, equalTo(msgInfo.size));
    assertThat(msgInfo.number, equalTo(1));

    // LIST message that does not exist
    msgInfo = client.listMessage(10);
    assertThat(msgInfo, nullValue());

    // UIDL all messages
    info = client.listUniqueIdentifiers();
    assertThat(info.length, equalTo(2));
    assertThat(info[0].identifier,
        equalTo(Base64UUIDUtils.encode(messages.get("attach"))));
    assertThat(info[1].identifier,
        equalTo(Base64UUIDUtils.encode(messages.get("headers"))));
    assertThat(info[0].number, equalTo(1));
    assertThat(info[1].number, equalTo(2));

    // UIDL one message
    msgInfo = client.listUniqueIdentifier(1);
    assertThat(msgInfo.identifier,
        equalTo(Base64UUIDUtils.encode(messages.get("attach"))));
    assertThat(msgInfo.number, equalTo(1));

    // UIDL message that does not exist
    msgInfo = client.listUniqueIdentifier(10);
    assertThat(msgInfo, nullValue());

    boolean logoutSuccess = client.logout();
    assertThat(logoutSuccess, is(true));
  }
View Full Code Here

    public static final void main(String[] args)
    {
        int message;
        String server, username, password;
        POP3Client pop3;
        Reader reader;
        POP3MessageInfo[] messages;

        if (args.length < 3)
        {
            System.err.println(
                "Usage: messages <pop3 server hostname> <username> <password>");
            System.exit(1);
        }

        server = args[0];
        username = args[1];
        password = args[2];

        pop3 = new POP3Client();
        // We want to timeout if a response takes longer than 60 seconds
        pop3.setDefaultTimeout(60000);

        try
        {
            pop3.connect(server);
        }
        catch (IOException e)
        {
            System.err.println("Could not connect to server.");
            e.printStackTrace();
            System.exit(1);
        }

        try
        {
            if (!pop3.login(username, password))
            {
                System.err.println("Could not login to server.  Check password.");
                pop3.disconnect();
                System.exit(1);
            }

            messages = pop3.listMessages();

            if (messages == null)
            {
                System.err.println("Could not retrieve message list.");
                pop3.disconnect();
                System.exit(1);
            }
            else if (messages.length == 0)
            {
                System.out.println("No messages");
                pop3.logout();
                pop3.disconnect();
                System.exit(1);
            }

            for (message = 0; message < messages.length; message++)
            {
                reader = pop3.retrieveMessageTop(messages[message].number, 0);

                if (reader == null)
                {
                    System.err.println("Could not retrieve message header.");
                    pop3.disconnect();
                    System.exit(1);
                }

                printMessageInfo(new BufferedReader(reader), messages[message].number);
            }

            pop3.logout();
            pop3.disconnect();
        }
        catch (IOException e)
        {
            e.printStackTrace();
            System.exit(1);
View Full Code Here

    this.host = host;
    this.port = port;
    if (ssl) {
      this.client = new POP3SClient("SSL", true);
    } else {
      this.client = new POP3Client();
    }
    this.client.setDefaultTimeout(300000);
  }
View Full Code Here

        String password = args[2];

        String proto = args.length > 3 ? args[3] : null;
        boolean implicit = args.length > 4 ? Boolean.parseBoolean(args[4]) : false;

        POP3Client pop3;

        if (proto != null) {
            System.out.println("Using secure protocol: "+proto);
            pop3 = new POP3SClient(proto, implicit);
        } else {
            pop3 = new POP3Client();
        }
        System.out.println("Connecting to server "+server+" on "+pop3.getDefaultPort());

        // We want to timeout if a response takes longer than 60 seconds
        pop3.setDefaultTimeout(60000);

        // suppress login details
        pop3.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true));

        try
        {
            pop3.connect(server);
        }
        catch (IOException e)
        {
            System.err.println("Could not connect to server.");
            e.printStackTrace();
            System.exit(1);
        }

        try
        {
            if (!pop3.login(username, password))
            {
                System.err.println("Could not login to server.  Check password.");
                pop3.disconnect();
                System.exit(1);
            }

            POP3MessageInfo[] messages = pop3.listMessages();

            if (messages == null)
            {
                System.err.println("Could not retrieve message list.");
                pop3.disconnect();
                return;
            }
            else if (messages.length == 0)
            {
                System.out.println("No messages");
                pop3.logout();
                pop3.disconnect();
                return;
            }

            for (POP3MessageInfo msginfo : messages) {
                BufferedReader reader = (BufferedReader) pop3.retrieveMessageTop(msginfo.number, 0);

                if (reader == null) {
                    System.err.println("Could not retrieve message header.");
                    pop3.disconnect();
                    System.exit(1);
                }
                printMessageInfo(reader, msginfo.number);
            }

            pop3.logout();
            pop3.disconnect();
        }
        catch (IOException e)
        {
            e.printStackTrace();
            return;
View Full Code Here

    public static final void main(String[] args)
    {
        int message;
        String server, username, password;
        POP3Client pop3;
        Reader reader;
        POP3MessageInfo[] messages;

        if (args.length < 3)
        {
            System.err.println(
                "Usage: messages <pop3 server hostname> <username> <password>");
            System.exit(1);
        }

        server = args[0];
        username = args[1];
        password = args[2];

        pop3 = new POP3Client();
        // We want to timeout if a response takes longer than 60 seconds
        pop3.setDefaultTimeout(60000);

        try
        {
            pop3.connect(server);
        }
        catch (IOException e)
        {
            System.err.println("Could not connect to server.");
            e.printStackTrace();
            System.exit(1);
        }

        try
        {
            if (!pop3.login(username, password))
            {
                System.err.println("Could not login to server.  Check password.");
                pop3.disconnect();
                System.exit(1);
            }

            messages = pop3.listMessages();

            if (messages == null)
            {
                System.err.println("Could not retrieve message list.");
                pop3.disconnect();
                System.exit(1);
            }
            else if (messages.length == 0)
            {
                System.out.println("No messages");
                pop3.logout();
                pop3.disconnect();
                System.exit(1);
            }

            for (message = 0; message < messages.length; message++)
            {
                reader = pop3.retrieveMessageTop(messages[message].number, 0);

                if (reader == null)
                {
                    System.err.println("Could not retrieve message header.");
                    pop3.disconnect();
                    System.exit(1);
                }

                printMessageInfo(new BufferedReader(reader), messages[message].number);
            }

            pop3.logout();
            pop3.disconnect();
        }
        catch (IOException e)
        {
            e.printStackTrace();
            System.exit(1);
View Full Code Here

TOP

Related Classes of org.apache.commons.net.pop3.POP3Client

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.