Package org.apache.commons.net.pop3

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


           
            handler.add("valid", new MockMailbox(identifier));
            server = createServer(createProtocol(handler), address);
            server.bind();
           
            POP3Client client =  createClient();
            client.connect(address.getAddress().getHostAddress(), address.getPort());
           
            assertTrue(client.login("valid", "valid"));
            POP3MessageInfo[] info = client.listMessages();
            assertEquals(0, info.length);
           
            info = client.listUniqueIdentifiers();
            assertEquals(0, info.length);
            assertTrue(client.logout());
          
        } finally {
            if (server != null) {
                server.unbind();
            }
View Full Code Here


           
            handler.add("valid", new MockMailbox(identifier, MESSAGE1, MESSAGE2));
            server = createServer(createProtocol(handler), address);
            server.bind();
           
            POP3Client client =  createClient();
            client.connect(address.getAddress().getHostAddress(), address.getPort());
           
            assertTrue(client.login("valid", "valid"));
            POP3MessageInfo[] info = client.listMessages();
            assertEquals(2, info.length);
            assertEquals((int) MESSAGE1.meta.getSize(), info[0].size);
            assertEquals((int) MESSAGE2.meta.getSize(), info[1].size);
            assertEquals(1, info[0].number);
            assertEquals(2, info[1].number);

            POP3MessageInfo mInfo = client.listMessage(1);
            assertEquals((int) MESSAGE1.meta.getSize(), mInfo.size);
            assertEquals(1, mInfo.number);

            // try to retrieve message that not exist
            mInfo = client.listMessage(10);
            assertNull(mInfo);

            info = client.listUniqueIdentifiers();
            assertEquals(2, info.length);
            assertEquals(identifier + "-" + MESSAGE1.meta.getUid(), info[0].identifier);
            assertEquals(identifier + "-" + MESSAGE2.meta.getUid(), info[1].identifier);
            assertEquals(1, info[0].number);
            assertEquals(2, info[1].number);

            mInfo = client.listUniqueIdentifier(1);
            assertEquals(identifier + "-" + MESSAGE1.meta.getUid(), mInfo.identifier);
            assertEquals(1, mInfo.number);

            // try to retrieve message that not exist
            mInfo = client.listUniqueIdentifier(10);
            assertNull(mInfo);
           
            assertTrue(client.logout());
          
        } finally {
            if (server != null) {
                server.unbind();
            }
View Full Code Here

           
            factory.add("valid", new MockMailbox(identifier, MESSAGE1, MESSAGE2));
            server = createServer(createProtocol(factory), address);
            server.bind();
           
            POP3Client client =  createClient();
            client.connect(address.getAddress().getHostAddress(), address.getPort());
           
            assertTrue(client.login("valid", "valid"));
            Reader reader = client.retrieveMessage(1);
            assertNotNull(reader);
            checkMessage(MESSAGE1, reader);
            reader.close();
           
            // does not exist
            reader = client.retrieveMessage(10);
            assertNull(reader);
           
           
            // delete and check for the message again, should now be deleted
            assertTrue(client.deleteMessage(1));
            reader = client.retrieveMessage(1);
            assertNull(reader);

           
            assertTrue(client.logout());
          
        } finally {
            if (server != null) {
                server.unbind();
            }
View Full Code Here

           
            factory.add("valid", new MockMailbox(identifier, MESSAGE1, MESSAGE2));
            server = createServer(createProtocol(factory), address);
            server.bind();
           
            POP3Client client =  createClient();
            client.connect(address.getAddress().getHostAddress(), address.getPort());
           
            assertTrue(client.login("valid", "valid"));
            Reader reader = client.retrieveMessageTop(1, 1000);
            assertNotNull(reader);
            checkMessage(MESSAGE1, reader);
            reader.close();
           
            reader = client.retrieveMessageTop(2, 1);
            assertNotNull(reader);
            checkMessage(MESSAGE2, reader,1);
            reader.close();
           
            // does not exist
            reader = client.retrieveMessageTop(10,100);
            assertNull(reader);
           
            // delete and check for the message again, should now be deleted
            assertTrue(client.deleteMessage(1));
            reader = client.retrieveMessageTop(1, 1000);
            assertNull(reader);

            assertTrue(client.logout());
          
        } finally {
            if (server != null) {
                server.unbind();
            }
View Full Code Here

           
            factory.add("valid", new MockMailbox(identifier, MESSAGE1, MESSAGE2));
            server = createServer(createProtocol(factory), address);
            server.bind();
           
            POP3Client client =  createClient();
            client.connect(address.getAddress().getHostAddress(), address.getPort());
           
            assertTrue(client.login("valid", "valid"));
            POP3MessageInfo[] info = client.listMessages();
            assertEquals(2, info.length);
           
            assertTrue(client.deleteMessage(1));
            info = client.listMessages();
            assertEquals(1, info.length);

           
            assertFalse(client.deleteMessage(1));
            info = client.listMessages();
            assertEquals(1, info.length);
           
           
            assertTrue(client.deleteMessage(2));
            info = client.listMessages();
            assertEquals(0, info.length);
           
            // logout so the messages get expunged
            assertTrue(client.logout());

            client.connect(address.getAddress().getHostAddress(), address.getPort());
 
            assertTrue(client.login("valid", "valid"));
            info = client.listMessages();
            assertEquals(0, info.length);

            assertTrue(client.logout());
          
        } finally {
            if (server != null) {
                server.unbind();
            }
View Full Code Here

        Reader reader;
        POP3MessageInfo[] messages = null;

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

        for (int i = 0; i < 12; i++) {
            pop3.connect(pop3Host);

            if (!pop3.login(pop3User, pop3passwd)) {
                pop3.disconnect();
                AxisFault fault = new AxisFault("POP3", "( Could not login to server.  Check password. )", null, null);
                throw fault;
            }

            messages = pop3.listMessages();
            if (messages != null && messages.length > 0) {
                StringBuffer buffer = null;
                for (int j = 0; j < messages.length; j++) {
                    reader = pop3.retrieveMessage(messages[j].number);
                    if (reader == null) {
                        AxisFault fault = new AxisFault("POP3", "( Could not retrieve message header. )", null, null);
                        throw fault;
                    }

                    buffer = new StringBuffer();
                    BufferedReader bufferedReader = new BufferedReader(reader);
                    int ch;
                    while ((ch = bufferedReader.read()) != -1) {
                        buffer.append((char) ch);
                    }
                    bufferedReader.close();
                    if (buffer.toString().indexOf(id) != -1) {
                        ByteArrayInputStream bais = new ByteArrayInputStream(buffer.toString().getBytes());
                        Properties prop = new Properties();
                        Session session = Session.getDefaultInstance(prop, null);

                        mimeMsg = new MimeMessage(session, bais);
                        pop3.deleteMessage(messages[j].number);
                        break;
                    }
                    buffer = null;
                }
            }
            pop3.logout();
            pop3.disconnect();
            if (mimeMsg == null) {
                Thread.sleep(5000);
            } else {
                break;
            }
        }

        if (mimeMsg == null) {
            pop3.logout();
            pop3.disconnect();
            AxisFault fault = new AxisFault("POP3", "( Could not retrieve message list. )", null, null);
            throw fault;
        }

        String contentType = mimeMsg.getContentType();
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

    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);
View Full Code Here

    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();
View Full Code Here

            assertEquals((int) MESSAGE1.meta.getSize(), info[0].size);
            assertEquals((int) MESSAGE2.meta.getSize(), info[1].size);
            assertEquals(1, info[0].number);
            assertEquals(2, info[1].number);

            POP3MessageInfo mInfo = client.listMessage(1);
            assertEquals((int) MESSAGE1.meta.getSize(), mInfo.size);
            assertEquals(1, mInfo.number);

            // try to retrieve message that not exist
            mInfo = client.listMessage(10);
View Full Code Here

TOP

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

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.