Package com.googlecode.gmail4j.javamail

Examples of com.googlecode.gmail4j.javamail.ImapGmailClient


     * Tests retrieval of messages by keyword as well as chained filtering
     * with the GmailMessageList class
     */
    @Test
    public void testGetMessagesByMultipleKeywords() {
        final ImapGmailClient client = new ImapGmailClient(ImapGmailLabel.SENT_MAIL);
        final ImapGmailConnection connection = new ImapGmailConnection();

        try {
            connection.setLoginCredentials(conf.getGmailCredentials());
            if (conf.useProxy()) {
                connection.setProxy(conf.getProxyHost(), conf.getProxyPort());
                connection.setProxyCredentials(conf.getProxyCredentials());
            }
            log.debug("Getting unread messages");
            client.setConnection(connection);
            final List<GmailMessage> messages = client.getMessagesBy(
                    GmailClient.EmailSearchStrategy.KEYWORD,"Unicode")
                    .filterMessagesBy(GmailClient.EmailSearchStrategy.KEYWORD,"ąžuolėlį");
            for (GmailMessage message : messages) {
                log.debug(message);
            }
            assertNotNull("Messages are not null", messages);
        } catch (final Exception e) {
            log.error("Test Failed", e);
            fail("Caught exception: " + e.getMessage());
        } finally {
            client.disconnect();
        }
    }
View Full Code Here


    /**
     * Tests retrieval of unread priority messages
     */
    @Test
    public void testGetPriorityMessagesUnreadOnly() {
        final ImapGmailClient client = new ImapGmailClient();
        final ImapGmailConnection connection = new ImapGmailConnection();

        try {
            connection.setLoginCredentials(conf.getGmailCredentials());
            if (conf.useProxy()) {
                connection.setProxy(conf.getProxyHost(), conf.getProxyPort());
                connection.setProxyCredentials(conf.getProxyCredentials());
            }
            log.debug("Getting unread priority messages");
            client.setConnection(connection);
            final List<GmailMessage> unreadMessages = client.getPriorityMessages(true);
            for (GmailMessage message : unreadMessages) {
                log.debug(message);
            }
            assertNotNull("Unread Priority Messages are not null", unreadMessages);
        } catch (final Exception e) {
            log.error("Test Failed", e);
            fail("Caught exception: " + e.getMessage());
        } finally {
            client.disconnect();
        }
    }
View Full Code Here

    /**
     * Tests retrieval of read priority messages
     */
    @Test
    public void testGetPriorityMessagesReadOnly() {
        final ImapGmailClient client = new ImapGmailClient();
        final ImapGmailConnection connection = new ImapGmailConnection();

        try {
            connection.setLoginCredentials(conf.getGmailCredentials());
            if (conf.useProxy()) {
                connection.setProxy(conf.getProxyHost(), conf.getProxyPort());
                connection.setProxyCredentials(conf.getProxyCredentials());
            }
            log.debug("Getting read priority messages");
            client.setConnection(connection);
            final List<GmailMessage> readMessages = client.getPriorityMessages(false);
            for (GmailMessage message : readMessages) {
                log.debug(message);
            }
            assertNotNull("Read Priority Messages are not null", readMessages);
        } catch (final Exception e) {
            log.error("Test Failed", e);
            fail("Caught exception: " + e.getMessage());
        } finally {
            client.disconnect();
        }
    }
View Full Code Here

    /**
     * Tests flagging a message as starred
     */
    @Test
    public void testAddStar() {
        final ImapGmailClient client = new ImapGmailClient(ImapGmailLabel.SENT_MAIL);
        final ImapGmailConnection connection = new ImapGmailConnection();

        try {
            connection.setLoginCredentials(conf.getGmailCredentials());
            if (conf.useProxy()) {
                connection.setProxy(conf.getProxyHost(), conf.getProxyPort());
                connection.setProxyCredentials(conf.getProxyCredentials());
            }
            client.setConnection(connection);

            final List<GmailMessage> messages = client.getUnreadMessages();
            if (messages.size() > 0) {
                log.debug("Starting to flag message as starred.");
                GmailMessage gmailMessage = messages.get(0);
                log.debug("Msg Subject: " + gmailMessage.getSubject() + " has "
                        + "been flagged as starred.");
                client.addStar(gmailMessage.getMessageNumber());
                log.debug("Finished flagging message as starred.");
            }
        } catch (final Exception e) {
            log.error("Test Failed", e);
            fail("Caught exception: " + e.getMessage());
        } finally {
            client.disconnect();
        }
    }
View Full Code Here

    /**
     * Tests removing star flag from a star flagged message
     */
    @Test
    public void testRemoveStar() {
        final ImapGmailClient client = new ImapGmailClient(ImapGmailLabel.SENT_MAIL);
        final ImapGmailConnection connection = new ImapGmailConnection();

        try {
            connection.setLoginCredentials(conf.getGmailCredentials());
            if (conf.useProxy()) {
                connection.setProxy(conf.getProxyHost(), conf.getProxyPort());
                connection.setProxyCredentials(conf.getProxyCredentials());
            }
            client.setConnection(connection);
            log.debug("Starting to remove star flag from starred message.");
            client.removeStar(1);
            log.debug("Finished removing star flag from starred message.");

        } catch (final Exception e) {
            log.error("Test Failed", e);
            fail("Caught exception: " + e.getMessage());
        } finally {
            client.disconnect();
        }
    }
View Full Code Here

    /**
     * Tests moving of message(s) to [Gmail]/Trash
     */
    @Test
    public void testMoveToTrash() {
        final ImapGmailClient client = new ImapGmailClient(ImapGmailLabel.SENT_MAIL);
        final ImapGmailConnection connection = new ImapGmailConnection();

        try {
            connection.setLoginCredentials(conf.getGmailCredentials());
            if (conf.useProxy()) {
                connection.setProxy(conf.getProxyHost(), conf.getProxyPort());
                connection.setProxyCredentials(conf.getProxyCredentials());
            }
            client.setConnection(connection);

            final List<GmailMessage> messages = client.getUnreadMessages();
            log.debug("Starting to move message(s) to trash folder.");
            // moving single GmailMessage to trash folder
            //GmailMessage[] jmgms = new JavaMailGmailMessage[1];
            //jmgms[0] = messages.get(0);
            //client.moveToTrash(jmgms);
            client.moveToTrash(messages.toArray(new JavaMailGmailMessage[0]));
            log.debug("Finished moving all selected message(s) to trash.");
            assertTrue("All unread messages are moved to trash.",
                    client.getUnreadMessages().isEmpty());
        } catch (final Exception e) {
            log.error("Test Failed", e);
            fail("Caught exception: " + e.getMessage());
        } finally {
            client.disconnect();
        }
    }
View Full Code Here

     * Tests marking all the messages as read
     */
    @Test
    public void testMarkAllAsRead() {
        testSendMessage();
        final ImapGmailClient client = new ImapGmailClient(ImapGmailLabel.SENT_MAIL);
        final ImapGmailConnection connection = new ImapGmailConnection();

        try {
            connection.setLoginCredentials(conf.getGmailCredentials());
            if (conf.useProxy()) {
                connection.setProxy(conf.getProxyHost(), conf.getProxyPort());
                connection.setProxyCredentials(conf.getProxyCredentials());
            }
            client.setConnection(connection);
            client.markAsUnread(1);
            log.debug("Starting to mark all the message's as read.");
            client.markAllAsRead();
            log.debug("Finished marking all the message's as read.");
            List<GmailMessage> unreadMessages = client.getUnreadMessages();
            assertTrue("All messages are marked as read.", unreadMessages.isEmpty());

        } catch (final Exception e) {
            log.error("Test Failed", e);
            fail("Caught exception: " + e.getMessage());
        } finally {
            client.disconnect();
        }
    }
View Full Code Here

    /**
     * Tests marking of a message as read
     */
    @Test
    public void testMarkAsRead() {
        final ImapGmailClient client = new ImapGmailClient(ImapGmailLabel.SENT_MAIL);
        final ImapGmailConnection connection = new ImapGmailConnection();

        try {
            connection.setLoginCredentials(conf.getGmailCredentials());
            if (conf.useProxy()) {
                connection.setProxy(conf.getProxyHost(), conf.getProxyPort());
                connection.setProxyCredentials(conf.getProxyCredentials());
            }
            client.setConnection(connection);
            client.markAsUnread(1);
            final List<GmailMessage> messages = client.getUnreadMessages();
            if (messages.size() > 0) {
                log.debug("Starting to mark message as read.");
                GmailMessage gmailMessage = messages.get(0);
                log.debug("Msg Subject: " + gmailMessage.getSubject() + " has "
                        + "been marked as read.");
                client.markAsRead(gmailMessage.getMessageNumber());
                log.debug("Finished marking message as read.");
            }
        } catch (final Exception e) {
            log.error("Test Failed", e);
            fail("Caught exception: " + e.getMessage());
        } finally {
            client.disconnect();
        }
    }
View Full Code Here

     * Tests moving a message to the same source folder which will
     * throw {@link GmailException}.
     */
    @Test(expected = GmailException.class)
    public void testMoveToGmailException() {
        final ImapGmailClient client = new ImapGmailClient(ImapGmailLabel.SENT_MAIL);
        final ImapGmailConnection connection = new ImapGmailConnection();

        try {
            connection.setLoginCredentials(conf.getGmailCredentials());
            if (conf.useProxy()) {
                connection.setProxy(conf.getProxyHost(), conf.getProxyPort());
                connection.setProxyCredentials(conf.getProxyCredentials());
            }
            client.setConnection(connection);
            log.debug("Starting to move message #1 to same " +
                    ImapGmailLabel.SENT_MAIL.getName());
            client.moveTo(ImapGmailLabel.SENT_MAIL, 1);
            log.debug("Test Passes with expected exception");
        } finally {
            client.disconnect();
        }
    }
View Full Code Here

    /**
     * Tests moving a message to a given destination folder.
     */
    @Test
    public void testMoveTo() {
        final ImapGmailClient client = new ImapGmailClient(ImapGmailLabel.SENT_MAIL);
        final ImapGmailConnection connection = new ImapGmailConnection();

        try {
            connection.setLoginCredentials(conf.getGmailCredentials());
            if (conf.useProxy()) {
                connection.setProxy(conf.getProxyHost(), conf.getProxyPort());
                connection.setProxyCredentials(conf.getProxyCredentials());
            }
            client.setConnection(connection);
            log.debug("Starting to move message #1 from " +
                    ImapGmailLabel.SENT_MAIL.getName());
            client.moveTo(ImapGmailLabel.INBOX, 1);
            log.debug("Finished moving message #1 to " +
                    ImapGmailLabel.INBOX.getName());
        } catch (final Exception e) {
            log.error("Test Failed", e);
            fail("Caught exception: " + e.getMessage());
        } finally {
            client.disconnect();
        }
    }
View Full Code Here

TOP

Related Classes of com.googlecode.gmail4j.javamail.ImapGmailClient

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.