Search in sources :

Example 61 with ZMessage

use of com.zimbra.client.ZMessage 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 62 with ZMessage

use of com.zimbra.client.ZMessage 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)

Example 63 with ZMessage

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

the class ZMailboxUtil method doGetMessage.

private void doGetMessage(String[] args) throws ServiceException {
    ZGetMessageParams params = new ZGetMessageParams();
    params.setMarkRead(true);
    params.setId(id(args[0]));
    ZMessage msg = mMbox.getMessage(params);
    if (verboseOpt()) {
        stdout.println(msg.dump());
    } else {
        dumpMessage(msg);
    }
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZGetMessageParams(com.zimbra.client.ZGetMessageParams)

Example 64 with ZMessage

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

the class TestFilter method testCurrentDayOfWeekTest.

@Test
public void testCurrentDayOfWeekTest() throws Exception {
    TimeZone userTz = Util.getAccountTimeZone(user1);
    Calendar calendar = Calendar.getInstance(userTz);
    int dayToday = calendar.get(Calendar.DAY_OF_WEEK) - 1;
    int dayYesterday = dayToday == 0 ? 6 : dayToday - 1;
    int dayTomorrow = dayToday == 6 ? 0 : dayToday + 1;
    List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
    List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
    List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
    // Condition true if msg received on the day yesterday or tomorrow
    conditions.add(new ZFilterCondition.ZCurrentDayOfWeekCondition(SimpleOp.IS, dayYesterday + "," + dayTomorrow));
    actions.add(new ZTagAction(mTag1.getName()));
    rules.add(new ZFilterRule("testCurrentDayOfWeekTest day not today", true, false, conditions, actions));
    saveIncomingRules(mMbox, new ZFilterRules(rules));
    String subject = NAME_PREFIX + " testCurrentDayOfWeekTest1";
    TestUtil.addMessageLmtp(subject, USER_NAME, USER_NAME);
    ZMessage msg = TestUtil.getMessage(mMbox, "in:inbox subject:\"" + subject + "\"");
    assertTrue("message should not have been tagged", msg.getTagIds() == null || msg.getTagIds().isEmpty());
    rules = new ArrayList<ZFilterRule>();
    conditions = new ArrayList<ZFilterCondition>();
    // Condition true if msg received on the day today
    conditions.add(new ZFilterCondition.ZCurrentDayOfWeekCondition(SimpleOp.IS, Integer.toString(dayToday)));
    rules.add(new ZFilterRule("testCurrentDayOfWeekTest today", true, false, conditions, actions));
    saveIncomingRules(mMbox, new ZFilterRules(rules));
    subject = NAME_PREFIX + " testCurrentDayOfWeekTest2";
    TestUtil.addMessageLmtp(subject, USER_NAME, USER_NAME);
    msg = TestUtil.getMessage(mMbox, "in:inbox subject:\"" + subject + "\"");
    assertNotNull("message should have been tagged", msg.getTagIds());
    Set<String> tagIds = new HashSet<String>();
    tagIds.addAll(Arrays.asList(msg.getTagIds().split(",")));
    assertTrue("message should have been tagged with tag1", tagIds.contains(mTag1.getId()));
}
Also used : ZMessage(com.zimbra.client.ZMessage) Calendar(java.util.Calendar) ZFilterCondition(com.zimbra.client.ZFilterCondition) ArrayList(java.util.ArrayList) ZFilterRule(com.zimbra.client.ZFilterRule) ZFilterAction(com.zimbra.client.ZFilterAction) TimeZone(java.util.TimeZone) ZTagAction(com.zimbra.client.ZFilterAction.ZTagAction) ZFilterRules(com.zimbra.client.ZFilterRules) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 65 with ZMessage

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

the class TestFilter method doBodyContainsTest.

private void doBodyContainsTest(String substring, boolean contains) throws Exception {
    List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
    List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
    List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
    // If subject matches the first for characters + *, mark as flagged.
    conditions.add(new ZBodyCondition(BodyOp.CONTAINS, substring));
    actions.add(new ZMarkAction(MarkOp.FLAGGED));
    rules.add(new ZFilterRule("testBodyContains", true, false, conditions, actions));
    ZFilterRules zRules = new ZFilterRules(rules);
    saveIncomingRules(mMbox, zRules);
    // Add a message and test the flagged state.
    String address = TestUtil.getAddress(USER_NAME);
    String msgContent = new String(ByteUtil.getContent(new File("/opt/zimbra/unittest/TestFilter-testBodyContains.msg")));
    TestUtil.addMessageLmtp(new String[] { address }, address, msgContent);
    ZMessage msg = TestUtil.getMessage(mMbox, "in:inbox subject:testBodyContains");
    assertEquals("Unexpected message flag state", contains, msg.isFlagged());
    mMbox.deleteMessage(msg.getId());
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZFilterCondition(com.zimbra.client.ZFilterCondition) ArrayList(java.util.ArrayList) ZFilterAction(com.zimbra.client.ZFilterAction) ZFilterRule(com.zimbra.client.ZFilterRule) ZBodyCondition(com.zimbra.client.ZFilterCondition.ZBodyCondition) ZMarkAction(com.zimbra.client.ZFilterAction.ZMarkAction) File(java.io.File) ZFilterRules(com.zimbra.client.ZFilterRules)

Aggregations

ZMessage (com.zimbra.client.ZMessage)101 Test (org.junit.Test)63 ZMailbox (com.zimbra.client.ZMailbox)59 ArrayList (java.util.ArrayList)43 ZFilterRule (com.zimbra.client.ZFilterRule)29 ZFilterAction (com.zimbra.client.ZFilterAction)28 ZFilterCondition (com.zimbra.client.ZFilterCondition)28 ZFilterRules (com.zimbra.client.ZFilterRules)28 ZHeaderCondition (com.zimbra.client.ZFilterCondition.ZHeaderCondition)12 ZOutgoingMessage (com.zimbra.client.ZMailbox.ZOutgoingMessage)12 ZEmailAddress (com.zimbra.client.ZEmailAddress)11 ZTagAction (com.zimbra.client.ZFilterAction.ZTagAction)10 ZFolder (com.zimbra.client.ZFolder)10 ZMarkAction (com.zimbra.client.ZFilterAction.ZMarkAction)8 Account (com.zimbra.cs.account.Account)8 MessagePart (com.zimbra.client.ZMailbox.ZOutgoingMessage.MessagePart)7 Date (java.util.Date)7 ZGetMessageParams (com.zimbra.client.ZGetMessageParams)5 ZMimePart (com.zimbra.client.ZMessage.ZMimePart)5 ZTag (com.zimbra.client.ZTag)5