Search in sources :

Example 21 with ZMessage

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

the class TestFilterRFCCompliantNotify method cleanUp.

private void cleanUp() throws Exception {
    TestUtil.deleteTestData(USER_NAME, NAME_PREFIX);
    TestUtil.deleteTestData(REMOTE_USER_NAME, NAME_PREFIX);
    // Clean up messages created by testBase64Subject()
    // bug 36705 for (ZMessage msg : TestUtil.search(mMbox, "villanueva")) {
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    for (ZMessage msg : TestUtil.search(mbox, "cortes de luz")) {
        mbox.deleteMessage(msg.getId());
    }
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZMailbox(com.zimbra.client.ZMailbox)

Example 22 with ZMessage

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

the class TestSpam method testSpamHandler.

@Test
public void testSpamHandler() throws Exception {
    TestUtil.createAccount(REMOTE_USER_NAME);
    TestUtil.createAccount(SPAM_NAME);
    TestUtil.createAccount(HAM_NAME);
    //check if AS is installed
    List<String> zimbraServiceInstalled = Arrays.asList(prov.getLocalServer().getServiceInstalled());
    if (zimbraServiceInstalled == null || zimbraServiceInstalled.isEmpty() || !zimbraServiceInstalled.contains("antispam")) {
        return;
    }
    Config config = prov.getConfig();
    config.setSpamIsSpamAccount(TestUtil.getAddress(SPAM_NAME));
    config.setSpamIsNotSpamAccount(TestUtil.getAddress(HAM_NAME));
    // Set filter rule.
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    ZFilterCondition cond = new ZHeaderCondition("Subject", ZFilterCondition.HeaderOp.CONTAINS, NAME_PREFIX);
    ZFolder spamFolder = mbox.getFolderById(Integer.toString(Mailbox.ID_FOLDER_SPAM));
    ZFolder inboxFolder = mbox.getFolderById(Integer.toString(Mailbox.ID_FOLDER_INBOX));
    ZFilterAction action = new ZFileIntoAction(spamFolder.getPath());
    ZFilterRule rule = new ZFilterRule(NAME_PREFIX + " testSpamHandler", true, true, Arrays.asList(cond), Arrays.asList(action));
    ZFilterRules rules = new ZFilterRules(Arrays.asList(rule));
    mbox.saveIncomingFilterRules(rules);
    // Confirm that the message was delivered to the Spam folder and that the report was sent.
    String subject = NAME_PREFIX + " testSpamHandler";
    TestUtil.addMessageLmtp(subject, USER_NAME, USER_NAME);
    ZMessage msg = TestUtil.getMessage(mbox, "in:" + spamFolder.getPath() + " subject:\"" + subject + "\"");
    ZMailbox spamMbox = TestUtil.getZMailbox(SPAM_NAME);
    ZMessage reportMsg = TestUtil.waitForMessage(spamMbox, "zimbra-spam-report spam");
    validateSpamReport(TestUtil.getContent(spamMbox, reportMsg.getId()), TestUtil.getAddress(USER_NAME), "spam", "filter", null, spamFolder.getPath(), null);
    spamMbox.deleteMessage(reportMsg.getId());
    // Move out of spam folder.
    mbox.moveMessage(msg.getId(), Integer.toString(Mailbox.ID_FOLDER_INBOX));
    ZMailbox hamMbox = TestUtil.getZMailbox(HAM_NAME);
    reportMsg = TestUtil.waitForMessage(hamMbox, "zimbra-spam-report ham");
    validateSpamReport(TestUtil.getContent(hamMbox, reportMsg.getId()), TestUtil.getAddress(USER_NAME), "ham", "move", spamFolder.getPath(), inboxFolder.getPath(), null);
    hamMbox.deleteMessage(reportMsg.getId());
    // Move back to spam folder.
    mbox.moveMessage(msg.getId(), Integer.toString(Mailbox.ID_FOLDER_SPAM));
    reportMsg = TestUtil.waitForMessage(spamMbox, "zimbra-spam-report spam");
    validateSpamReport(TestUtil.getContent(spamMbox, reportMsg.getId()), TestUtil.getAddress(USER_NAME), "spam", "move", inboxFolder.getPath(), spamFolder.getPath(), null);
    spamMbox.deleteMessage(reportMsg.getId());
    // Move to remote folder.
    ZMailbox remoteMbox = TestUtil.getZMailbox(REMOTE_USER_NAME);
    String mountpointPath = NAME_PREFIX + " remote";
    TestUtil.createMountpoint(remoteMbox, "/Inbox", mbox, mountpointPath);
    ZFolder mountpoint = mbox.getFolderByPath(mountpointPath);
    mbox.moveMessage(msg.getId(), mountpoint.getId());
    reportMsg = TestUtil.waitForMessage(hamMbox, "zimbra-spam-report ham");
    validateSpamReport(TestUtil.getContent(hamMbox, reportMsg.getId()), TestUtil.getAddress(USER_NAME), "ham", "remote move", spamFolder.getPath(), inboxFolder.getPath(), TestUtil.getAddress(REMOTE_USER_NAME));
    hamMbox.deleteMessage(reportMsg.getId());
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZMailbox(com.zimbra.client.ZMailbox) Config(com.zimbra.cs.account.Config) ZHeaderCondition(com.zimbra.client.ZFilterCondition.ZHeaderCondition) ZFilterCondition(com.zimbra.client.ZFilterCondition) ZFileIntoAction(com.zimbra.client.ZFilterAction.ZFileIntoAction) ZFilterAction(com.zimbra.client.ZFilterAction) ZFilterRule(com.zimbra.client.ZFilterRule) ZFolder(com.zimbra.client.ZFolder) ZFilterRules(com.zimbra.client.ZFilterRules) Test(org.junit.Test)

Example 23 with ZMessage

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

the class TestUtil method getContent.

public static byte[] getContent(ZMailbox mbox, String msgId, String name) throws ServiceException, IOException {
    ZMessage msg = mbox.getMessageById(msgId);
    ZMimePart part = getPart(msg, name);
    if (part == null) {
        return null;
    }
    return ByteUtil.getContent(mbox.getRESTResource("?id=" + msgId + "&part=" + part.getPartName()), 1024);
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZMimePart(com.zimbra.client.ZMessage.ZMimePart)

Example 24 with ZMessage

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

the class TestConversion method downloadAttachmentsFromTNEFmsg.

/**
     * Tests downloading attachments from a TNEF message (bug 44263).
     */
@Test
public void downloadAttachmentsFromTNEFmsg() throws Exception {
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    String msgName = "/unittest/tnef.msg";
    File tnefMsg = new File(LC.zimbra_home.value() + msgName);
    Assert.assertTrue(String.format("To run this test copy data%1$s to /opt/zimbra%1$s", msgName), tnefMsg.exists() && tnefMsg.canRead());
    // Add the TNEF message
    String msgContent = new String(ByteUtil.getContent(tnefMsg));
    TestUtil.addMessageLmtp(new String[] { USER_NAME }, USER_NAME, msgContent);
    // Test downloading attachments.
    ZMessage msg = TestUtil.getMessage(mbox, "in:inbox subject:\"" + NAME_PREFIX + " Rich text (TNEF) test\"");
    byte[] data = TestUtil.getContent(mbox, msg.getId(), "upload.gif");
    Assert.assertEquals(73, data.length);
    data = TestUtil.getContent(mbox, msg.getId(), "upload2.gif");
    Assert.assertEquals(851, data.length);
    ZMimePart part = TestUtil.getPart(msg, "upload.gif");
    checkPartSize(73, part.getSize());
    part = TestUtil.getPart(msg, "upload2.gif");
    checkPartSize(851, part.getSize());
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZMailbox(com.zimbra.client.ZMailbox) ZMimePart(com.zimbra.client.ZMessage.ZMimePart) File(java.io.File) Test(org.junit.Test)

Example 25 with ZMessage

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

the class TestFilter method testOutgoingFiltersWithSendMsg.

/**
     * Confirms that outgoing filters are applied as expected when a message is sent via SendMsgRequest.
     */
@Test
public void testOutgoingFiltersWithSendMsg() throws Exception {
    String sender = TestUtil.getAddress(USER_NAME);
    String recipient = TestUtil.getAddress(REMOTE_USER_NAME);
    String subject = NAME_PREFIX + " outgoing";
    List<ZEmailAddress> addrs = new LinkedList<ZEmailAddress>();
    addrs.add(new ZEmailAddress(sender, null, null, ZEmailAddress.EMAIL_TYPE_FROM));
    addrs.add(new ZEmailAddress(recipient, null, null, ZEmailAddress.EMAIL_TYPE_TO));
    ZMailbox.ZOutgoingMessage outgoingMsg = new ZMailbox.ZOutgoingMessage();
    outgoingMsg.setAddresses(addrs);
    outgoingMsg.setSubject(subject);
    mMbox.sendMessage(outgoingMsg, null, false);
    // make sure that sent message has been correctly tagged and filed into the correct folder
    ZMessage msg = TestUtil.getMessage(mMbox, "in:" + FOLDER1_NAME + " " + subject);
    TestUtil.verifyTag(mMbox, msg, TAG1_NAME);
    //make sure that sent message has not been filed into the (default) Sent folder
    List<ZMessage> msgs = TestUtil.search(mMbox, "in:Sent" + " " + subject);
    assertTrue(msgs.isEmpty());
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZMailbox(com.zimbra.client.ZMailbox) ZEmailAddress(com.zimbra.client.ZEmailAddress) LinkedList(java.util.LinkedList) Test(org.junit.Test)

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