Search in sources :

Example 1 with ZPop3DataSource

use of com.zimbra.client.ZPop3DataSource in project zm-mailbox by Zimbra.

the class TestPop3ImportServer method getZDataSource.

private ZPop3DataSource getZDataSource() throws Exception {
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    List<ZDataSource> dataSources = mbox.getAllDataSources();
    for (ZDataSource ds : dataSources) {
        if (ds.getName().equals(DATA_SOURCE_NAME)) {
            return (ZPop3DataSource) ds;
        }
    }
    fail("Could not find data source " + DATA_SOURCE_NAME);
    return null;
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) ZPop3DataSource(com.zimbra.client.ZPop3DataSource) ZDataSource(com.zimbra.client.ZDataSource)

Example 2 with ZPop3DataSource

use of com.zimbra.client.ZPop3DataSource in project zm-mailbox by Zimbra.

the class TestPop3Import method getZDataSource.

private ZPop3DataSource getZDataSource() throws Exception {
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    List<ZDataSource> dataSources = mbox.getAllDataSources();
    for (ZDataSource ds : dataSources) {
        if (ds.getName().equals(DATA_SOURCE_NAME)) {
            return (ZPop3DataSource) ds;
        }
    }
    Assert.fail("Could not find data source " + DATA_SOURCE_NAME);
    return null;
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) ZPop3DataSource(com.zimbra.client.ZPop3DataSource) ZDataSource(com.zimbra.client.ZDataSource)

Example 3 with ZPop3DataSource

use of com.zimbra.client.ZPop3DataSource in project zm-mailbox by Zimbra.

the class TestPop3Import method testBogusDate.

/**
     * Tests import of a message with a date in the future (bug 17031).
     */
@Test
public void testBogusDate() throws Exception {
    // Create remote account
    prov.createAccount(TestUtil.getAddress(TEMP_USER_NAME), "test123", null);
    // Add message with bogus date to remote mailbox
    MailDateFormat format = new MailDateFormat();
    Date date = format.parse("Thu, 31  Aug 2039 10:29:46 +0800");
    String message = TestUtil.getTestMessage(NAME_PREFIX + " testBogusDate", null, null, date);
    ZMailbox remoteMbox = TestUtil.getZMailbox(TEMP_USER_NAME);
    String folderId = Integer.toString(Mailbox.ID_FOLDER_INBOX);
    remoteMbox.addMessage(folderId, null, null, 0, message, true);
    // Update the data source, import data
    ZMailbox localMbox = TestUtil.getZMailbox(USER_NAME);
    ZPop3DataSource ds = getZDataSource();
    ds.setUsername(TEMP_USER_NAME);
    ds.setEnabled(true);
    localMbox.modifyDataSource(ds);
    // Import data and make sure the message was imported
    List<ZMessage> messages = TestUtil.search(localMbox, "in:inbox " + NAME_PREFIX);
    Assert.assertEquals("Found unexpected message in local inbox", 0, messages.size());
    TestUtil.importDataSource(ds, localMbox, remoteMbox);
    messages = TestUtil.search(localMbox, "in:inbox " + NAME_PREFIX);
    Assert.assertEquals("Imported message not found", 1, messages.size());
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZMailbox(com.zimbra.client.ZMailbox) ZPop3DataSource(com.zimbra.client.ZPop3DataSource) MailDateFormat(javax.mail.internet.MailDateFormat) Date(java.util.Date) Test(org.junit.Test)

Example 4 with ZPop3DataSource

use of com.zimbra.client.ZPop3DataSource in project zm-mailbox by Zimbra.

the class TestPop3Import method testTestDataSource.

/**
     * Tests {@link ZMailbox#testDataSource}.
     */
@Test
public void testTestDataSource() throws Exception {
    TestUtil.createAccount(USER2_NAME);
    ZMailbox localMbox = TestUtil.getZMailbox(USER_NAME);
    ZPop3DataSource ds = getZDataSource();
    ds.setUsername(USER2_NAME);
    localMbox.modifyDataSource(ds);
    String testVal = localMbox.testDataSource(ds);
    Assert.assertNull(String.format("testDataSource return value '%s' expected to be null (which means success)", testVal), testVal);
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) ZPop3DataSource(com.zimbra.client.ZPop3DataSource) Test(org.junit.Test)

Example 5 with ZPop3DataSource

use of com.zimbra.client.ZPop3DataSource in project zm-mailbox by Zimbra.

the class TestPop3Import method testFiltering.

/**
     * Confirms that messages pulled from a POP3 account are affected by
     * mail filtering (bug 13821).
     */
@Test
public void testFiltering() throws Exception {
    String folderPath = "/" + NAME_PREFIX + "-testFiltering";
    String filteredPath = "/" + NAME_PREFIX + "-testFiltering-filtered";
    // Create remote account
    prov.createAccount(TestUtil.getAddress(TEMP_USER_NAME), "test123", null);
    // Add message to remote mailbox
    ZMailbox remoteMbox = TestUtil.getZMailbox(TEMP_USER_NAME);
    TestUtil.addMessage(remoteMbox, NAME_PREFIX + " testFiltering");
    // Create local folders
    ZMailbox localMbox = TestUtil.getZMailbox(USER_NAME);
    localMbox.getFolderByPath("/Inbox");
    ZFolder dsFolder = TestUtil.createFolder(localMbox, folderPath);
    TestUtil.createFolder(localMbox, filteredPath);
    // Create filter rule that files to the local folder
    List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
    List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
    List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
    conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "testFiltering"));
    actions.add(new ZFileIntoAction(filteredPath));
    rules.add(new ZFilterRule("testFiltering", true, false, conditions, actions));
    localMbox.saveIncomingFilterRules(new ZFilterRules(rules));
    // Set up data source and run import
    ZPop3DataSource ds = getZDataSource();
    ds.setUsername(TEMP_USER_NAME);
    ds.setFolderId(dsFolder.getId());
    ds.setEnabled(true);
    localMbox.modifyDataSource(ds);
    // Import data and make sure the message was filed to the folder
    TestUtil.importDataSource(ds, localMbox, remoteMbox);
    List<ZMessage> messages = TestUtil.search(localMbox, "in:" + folderPath);
    Assert.assertEquals("Found unexpected messages in " + folderPath, 0, messages.size());
    messages = TestUtil.search(localMbox, "in:" + filteredPath);
    Assert.assertEquals("Message not found in " + filteredPath, 1, messages.size());
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZHeaderCondition(com.zimbra.client.ZFilterCondition.ZHeaderCondition) ZFilterCondition(com.zimbra.client.ZFilterCondition) ArrayList(java.util.ArrayList) ZFilterRule(com.zimbra.client.ZFilterRule) ZFilterAction(com.zimbra.client.ZFilterAction) ZMailbox(com.zimbra.client.ZMailbox) ZPop3DataSource(com.zimbra.client.ZPop3DataSource) ZFileIntoAction(com.zimbra.client.ZFilterAction.ZFileIntoAction) ZFolder(com.zimbra.client.ZFolder) ZFilterRules(com.zimbra.client.ZFilterRules) Test(org.junit.Test)

Aggregations

ZPop3DataSource (com.zimbra.client.ZPop3DataSource)7 ZMailbox (com.zimbra.client.ZMailbox)6 Test (org.junit.Test)4 ZDataSource (com.zimbra.client.ZDataSource)3 ZMessage (com.zimbra.client.ZMessage)2 ZFilterAction (com.zimbra.client.ZFilterAction)1 ZFileIntoAction (com.zimbra.client.ZFilterAction.ZFileIntoAction)1 ZFilterCondition (com.zimbra.client.ZFilterCondition)1 ZHeaderCondition (com.zimbra.client.ZFilterCondition.ZHeaderCondition)1 ZFilterRule (com.zimbra.client.ZFilterRule)1 ZFilterRules (com.zimbra.client.ZFilterRules)1 ZFolder (com.zimbra.client.ZFolder)1 DataSource (com.zimbra.cs.account.DataSource)1 Mailbox (com.zimbra.cs.mailbox.Mailbox)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 MailDateFormat (javax.mail.internet.MailDateFormat)1