Package com.googlecode.gmail4j.javamail

Examples of com.googlecode.gmail4j.javamail.ImapGmailClient


    /**
     * Test a sending of a simple message
     */
    @Test
    public void testSendMessage() {
        final GmailClient client = new ImapGmailClient();
        final GmailConnection connection = new ImapGmailConnection();
        connection.setLoginCredentials(conf.getGmailCredentials());
        if (conf.useProxy() && (connection instanceof ProxyAware)) {
            ((ProxyAware) connection).setProxy(
                    conf.getProxyHost(), conf.getProxyPort());
            ((ProxyAware) connection).setProxyCredentials(
                    conf.getProxyCredentials());
        }
        client.setConnection(connection);
        GmailMessage msg = new JavaMailGmailMessage();
        msg.setSubject("Test mail subject. Unicode: ąžuolėlį");
        msg.setContentText("Test mail content. Unicode: ąžuolėlį");
        msg.addTo(new EmailAddress(conf.getTestRecipient()));
        client.send(msg);
    }
View Full Code Here


    /**
     * Tests marking of a message as unread
     */
    @Test
    public void testMarkAsUnread() {
        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 mark message as unread.");
            client.markAsUnread(1);
            log.debug("Finished marking message as unread.");
        } catch (final Exception e) {
            log.error("Test Failed", e);
            fail("Caught exception: " + e.getMessage());
        } finally {
View Full Code Here

    /**
     * Tests retrieval of unread messages
     */
    @Test
    public void testGetUnreadMessages() {
        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.getUnreadMessages();
            for (GmailMessage message : messages) {
                log.debug(message);
            }
            assertNotNull("Messages are not null", messages);
        } catch (final Exception e) {
View Full Code Here

    /**
     * Tests retrieval of unread priority messages
     */
    @Test
    public void testGetPriorityMessages_UnreadOnly() {
        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) {
View Full Code Here

    /**
     * Tests retrieval of read priority messages
     */
    @Test
    public void testGetPriorityMessages_ReadOnly() {
        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) {
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());
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());
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 {
            if (connection.isConnected()) {
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());
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());
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.