Package com.googlecode.gmail4j.javamail

Examples of com.googlecode.gmail4j.javamail.ImapGmailClient


     * Tests moving a message to the same source folder which will
     * throw {@link GmailException}.
     */
    @Test(expected = GmailException.class)
    public void testMoveTo_GmailException() {
        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 {
            if (connection.isConnected()) {
                connection.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());
View Full Code Here

        }
    }
   
    @Test
    public void testGetPreview() {
        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);
           
            // Send a message so we have one
            GmailMessage msg = new JavaMailGmailMessage();
            msg.setSubject("Test mail subject. Unicode: ąžuolėlį");
            msg.setContentText("Let's try to write a very long message and see" +
                    "if it will get trimmed when preview is called. It has to " +
                    "be over ? chars long so it will get trimmed. Now this text " +
                    "is over ? chars long, it should really get trimmed good.");
            msg.addTo(new EmailAddress(conf.getTestRecipient()));
            client.send(msg);
           
            log.debug("Getting messages");
            final List<GmailMessage> messages = client.getUnreadMessages();
            log.debug("Got " + messages.size() + " messages");
            for (GmailMessage message : messages) {
                String text = message.getPreview();
                log.debug("Got text: " + text);
                assertTrue("Text is not empty", text.length() > 0);
                assertTrue("Text is not too long",
                        text.length() <= Constants.PREVIEW_LENGTH);
            }
            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

        }
    }
   
    @Test
    public void testGetAttachements() {
        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());
            }
            client.setConnection(connection);
           
            // Send a message so we have one
            GmailMessage msg = new JavaMailGmailMessage();
            msg.setSubject(TEST_MAIL_WITH_ATTACHEMENTS_SUBJECT);
            msg.setContentText(TEST_MAIL_WITH_ATTACHEMENT_CONTENT);
            msg.addTo(new EmailAddress(conf.getTestRecipient()));
           
            URL url = this.getClass().getClassLoader().getResource(ATTACHEMENT_1_FILENAME);
            msg.addAttachement(new File(url.toURI()));
            url = this.getClass().getClassLoader().getResource(ATTACHEMENT_2_FILENAME);
            msg.addAttachement(new File(url.toURI()));
            client.send(msg);
           
            final List<GmailMessage> messages = client.getUnreadMessages();
            for (GmailMessage message : messages) {
                if (message.getSubject().equals(TEST_MAIL_WITH_ATTACHEMENTS_SUBJECT)) {
                    /* Try to get attachements. */
                    List<GmailAttachment> attachements = message.getAttachements();
                    assertTrue(attachements.size() > 0);
                    for (GmailAttachment gmailAttachment : attachements) {
                        log.debug(gmailAttachment.toString());
                        byte[] data1 = IOUtils.toByteArray(gmailAttachment.getData());
                        assertTrue(data1.length > 0);
                        byte[] data2 = IOUtils.toByteArray(message.getAttachment(gmailAttachment.getPartIndex()).getData());
                        assertTrue(data2.length > 0);
                    }
                    break;
                }
            }
        } catch (final Exception e) {
            log.error("Test Failed", e);
            fail("Caught exception: " + e.getMessage());
        } finally {
            client.disconnect();
        }
    }
View Full Code Here

    /**
     * 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);
        client.disconnect();
    }
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 {
            client.disconnect();
        }
    }
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) {
            log.error("Test Failed", e);
            fail("Caught exception: " + e.getMessage());
        } finally {
            client.disconnect();
        }
    }
View Full Code Here

    /**
     * Tests retrieval of messages by date
     */
    @Test
    public void testGetMessagesByDateGreaterThan() {
        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());
            }
            Date date = new Date();
            Calendar cal = Calendar.getInstance();
            cal.setTime(date);
            cal.add(Calendar.DATE, -1);
            date = cal.getTime();
            log.debug("Getting messages newer than yesterday" + date.toString());
            client.setConnection(connection);
            final List<GmailMessage> messages = client.getMessagesBy(
                    GmailClient.EmailSearchStrategy.DATE_GT,
                    date.toString());
            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 messages by subject
     */
    @Test
    public void testGetMessagesBySubject() {
        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 messages by subject");
            client.setConnection(connection);
            final List<GmailMessage> messages = client.getMessagesBy(
                    GmailClient.EmailSearchStrategy.SUBJECT,
                    "Test mail subject. Unicode: ąž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 messages by keyword
     */
    @Test
    public void testGetMessagesByKeyword() {
        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 messages by keyword");
            client.setConnection(connection);
            final List<GmailMessage> messages = client.getMessagesBy(
                    GmailClient.EmailSearchStrategy.KEYWORD,"Unicode");
            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

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.