Search in sources :

Example 11 with ZMessage

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

the class TestOutOfOffice method testPrefFromAddress.

/**
     * Confirms that out-of-office notifications use the user's address preference
     * (bug 40869).
     */
public void testPrefFromAddress() throws Exception {
    String newFromAddress = TestUtil.getAddress("testPrefFromAddress");
    String newFromDisplay = NAME_PREFIX + " testPrefFromAddress";
    String newReplyToAddress = TestUtil.getAddress("testReplyToAddress");
    String newReplyToDisplay = NAME_PREFIX + " testReplyToAddress";
    // Turn on out-of-office.
    Account recipient = TestUtil.getAccount(RECIPIENT_NAME);
    long now = System.currentTimeMillis();
    recipient.setPrefOutOfOfficeFromDate(new Date(now));
    recipient.setPrefOutOfOfficeUntilDate(new Date(now + Constants.MILLIS_PER_DAY));
    recipient.setPrefOutOfOfficeReplyEnabled(true);
    // Don't allow any From address, set display name pref only.
    recipient.setAllowAnyFromAddress(false);
    recipient.setPrefFromDisplay(newFromDisplay);
    recipient.setPrefReplyToAddress(newReplyToAddress);
    recipient.setPrefReplyToDisplay(newReplyToDisplay);
    recipient.setPrefReplyToEnabled(false);
    String subject = NAME_PREFIX + " testPrefFromAddress 1";
    ZMailbox senderMbox = TestUtil.getZMailbox(SENDER_NAME);
    TestUtil.sendMessage(senderMbox, RECIPIENT_NAME, subject);
    ZMessage reply = TestUtil.waitForMessage(senderMbox, "in:inbox subject:\"" + subject + "\"");
    // Validate addresses.
    ZEmailAddress fromAddress = getAddress(reply, ZEmailAddress.EMAIL_TYPE_FROM);
    assertEquals(recipient.getName(), fromAddress.getAddress());
    assertEquals(newFromDisplay, fromAddress.getPersonal());
    assertNull(getAddress(reply, ZEmailAddress.EMAIL_TYPE_REPLY_TO));
    DbOutOfOffice.clear(mConn, mMbox);
    mConn.commit();
    // Don't allow any From address, set display name, from address, and reply-to prefs.
    recipient.setPrefFromAddress(newFromAddress);
    recipient.setAllowAnyFromAddress(false);
    recipient.setPrefReplyToEnabled(true);
    subject = NAME_PREFIX + " testPrefFromAddress 2";
    TestUtil.sendMessage(senderMbox, RECIPIENT_NAME, subject);
    reply = TestUtil.waitForMessage(senderMbox, "in:inbox subject:\"" + subject + "\"");
    // Validate addresses.
    fromAddress = getAddress(reply, ZEmailAddress.EMAIL_TYPE_FROM);
    assertEquals(recipient.getName(), fromAddress.getAddress());
    assertEquals(recipient.getDisplayName(), fromAddress.getPersonal());
    ZEmailAddress replyToAddress = getAddress(reply, ZEmailAddress.EMAIL_TYPE_REPLY_TO);
    assertEquals(newReplyToAddress, replyToAddress.getAddress());
    assertEquals(newReplyToDisplay, replyToAddress.getPersonal());
    DbOutOfOffice.clear(mConn, mMbox);
    mConn.commit();
    // Allow any From address, set display name and address prefs.
    recipient.setAllowAnyFromAddress(true);
    subject = NAME_PREFIX + " testPrefFromAddress 3";
    TestUtil.sendMessage(senderMbox, RECIPIENT_NAME, subject);
    reply = TestUtil.waitForMessage(senderMbox, "in:inbox subject:\"" + subject + "\"");
    ZimbraLog.test.info("Second reply:\n" + TestUtil.getContent(senderMbox, reply.getId()));
    // Validate addresses.
    fromAddress = getAddress(reply, ZEmailAddress.EMAIL_TYPE_FROM);
    assertEquals(newFromAddress, fromAddress.getAddress());
    assertEquals(newFromDisplay, fromAddress.getPersonal());
    replyToAddress = getAddress(reply, ZEmailAddress.EMAIL_TYPE_REPLY_TO);
    assertEquals(newReplyToAddress, replyToAddress.getAddress());
    assertEquals(newReplyToDisplay, replyToAddress.getPersonal());
}
Also used : ZMessage(com.zimbra.client.ZMessage) Account(com.zimbra.cs.account.Account) ZMailbox(com.zimbra.client.ZMailbox) ZEmailAddress(com.zimbra.client.ZEmailAddress) Date(java.util.Date)

Example 12 with ZMessage

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

the class TestMaxMessageSize method testMaxMessageSizeSaveDraft.

/**
     * Confirms that
     * @throws Exception
     */
@Test
public void testMaxMessageSizeSaveDraft() throws Exception {
    setMaxMessageSize(TEST_MAX_MESSAGE_SIZE);
    // Upload attachment whose size is 50% of the threshold.  If this number
    // gets incremented twice, it would exceed the threshold.
    Map<String, byte[]> attachments = new HashMap<String, byte[]>();
    attachments.put("file1.exe", new byte[(int) (TEST_MAX_MESSAGE_SIZE * 0.5)]);
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    String aid = mbox.uploadAttachments(attachments, 5000);
    // Save draft
    ZOutgoingMessage outgoing = new ZOutgoingMessage();
    List<ZEmailAddress> addresses = new ArrayList<ZEmailAddress>();
    addresses.add(new ZEmailAddress(TestUtil.getAddress(USER_NAME), null, null, ZEmailAddress.EMAIL_TYPE_TO));
    outgoing.setAddresses(addresses);
    outgoing.setAttachmentUploadId(aid);
    String subject = NAME_PREFIX + "testMaxMessageSizeSaveDraft";
    outgoing.setSubject(subject);
    ZMessage draft = mbox.saveDraft(outgoing, null, null);
    // Send the draft
    outgoing.setAttachmentUploadId(null);
    List<AttachedMessagePart> attachedParts = new ArrayList<AttachedMessagePart>();
    attachedParts.add(new AttachedMessagePart(draft.getId(), "1", null));
    outgoing.setMessagePartsToAttach(attachedParts);
    mbox.sendMessage(outgoing, null, false);
    TestUtil.waitForMessage(mbox, "in:inbox subject:\"" + subject + "\"");
    // Reduce max message size and confirm that the send fails.
    setMaxMessageSize((int) (TEST_MAX_MESSAGE_SIZE * 0.6));
    try {
        mbox.sendMessage(outgoing, null, false);
        Assert.fail("Message send should not have succeeded.");
    } catch (SoapFaultException e) {
        // Message send was not allowed, as expected.
        validateMessageTooBigFault(e);
    }
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZOutgoingMessage(com.zimbra.client.ZMailbox.ZOutgoingMessage) ZMailbox(com.zimbra.client.ZMailbox) ZEmailAddress(com.zimbra.client.ZEmailAddress) AttachedMessagePart(com.zimbra.client.ZMailbox.ZOutgoingMessage.AttachedMessagePart) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SoapFaultException(com.zimbra.common.soap.SoapFaultException) Test(org.junit.Test)

Example 13 with ZMessage

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

the class TestMessageIntercept method testIntercept.

public void testIntercept() throws Exception {
    // Turn on legal intercept for recipient account
    String interceptorAddress = TestUtil.getAddress(INTERCEPTOR1_NAME);
    String senderAddress = TestUtil.getAddress(SENDER_NAME);
    TestUtil.setAccountAttr(RECIPIENT_NAME, Provisioning.A_zimbraInterceptAddress, interceptorAddress);
    TestUtil.setAccountAttr(RECIPIENT_NAME, Provisioning.A_zimbraInterceptSendHeadersOnly, LdapConstants.LDAP_FALSE);
    // Send message to recipient account and make sure it's intercepted
    ZMailbox interceptorMbox = TestUtil.getZMailbox(INTERCEPTOR1_NAME);
    ZMailbox tappedMbox = TestUtil.getZMailbox(RECIPIENT_NAME);
    String tappedAddress = TestUtil.getAddress(RECIPIENT_NAME);
    String subject = NAME_PREFIX + " testIntercept-receive";
    TestUtil.addMessageLmtp(subject, tappedAddress, senderAddress);
    ZMessage tappedMsg = TestUtil.getMessage(tappedMbox, "subject:\"" + subject + "\"");
    ZMessage interceptMsg = TestUtil.waitForMessage(interceptorMbox, "subject:\"" + subject + "\"");
    verifyInterceptMessage(interceptMsg, "add message", "Inbox", Integer.toString(Mailbox.ID_FOLDER_INBOX));
    compareContent(tappedMbox, tappedMsg, interceptorMbox, interceptMsg);
    // Confirm that saving a draft is intercepted.  The first draft calls Mailbox.addMessage().
    ZOutgoingMessage outgoing = new ZOutgoingMessage();
    List<ZEmailAddress> addresses = new ArrayList<ZEmailAddress>();
    addresses.add(new ZEmailAddress(TestUtil.getAddress(INTERCEPTOR1_NAME), null, null, ZEmailAddress.EMAIL_TYPE_TO));
    outgoing.setAddresses(addresses);
    subject = NAME_PREFIX + " testIntercept-draft-1";
    outgoing.setSubject(subject);
    outgoing.setMessagePart(new MessagePart("text/plain", "I always feel like somebody's watching me."));
    tappedMbox.saveDraft(outgoing, null, Integer.toString(Mailbox.ID_FOLDER_DRAFTS));
    tappedMsg = TestUtil.getMessage(tappedMbox, "in:drafts subject:\"" + subject + "\"");
    interceptMsg = TestUtil.waitForMessage(interceptorMbox, "subject:\"" + subject + "\"");
    verifyInterceptMessage(interceptMsg, "add message", "Drafts", Integer.toString(Mailbox.ID_FOLDER_DRAFTS));
    compareContent(tappedMbox, tappedMsg, interceptorMbox, interceptMsg);
    // Save draft again.  This time Mailbox.saveDraft() gets called.
    ZMessage draft = TestUtil.getMessage(tappedMbox, "in:drafts subject:\"" + subject + "\"");
    subject = NAME_PREFIX + " testIntercept-draft-2";
    outgoing.setSubject(subject);
    tappedMbox.saveDraft(outgoing, draft.getId(), null);
    tappedMsg = TestUtil.getMessage(tappedMbox, "in:drafts subject:\"" + subject + "\"");
    interceptMsg = TestUtil.waitForMessage(interceptorMbox, "subject:\"" + subject + "\"");
    verifyInterceptMessage(interceptMsg, "save draft", "Drafts", Integer.toString(Mailbox.ID_FOLDER_DRAFTS));
    compareContent(tappedMbox, tappedMsg, interceptorMbox, interceptMsg);
    // Send message with save-to-sent turned on.
    TestUtil.setAccountAttr(RECIPIENT_NAME, Provisioning.A_zimbraPrefSaveToSent, LdapConstants.LDAP_TRUE);
    subject = NAME_PREFIX + " testIntercept-send-1";
    TestUtil.sendMessage(tappedMbox, INTERCEPTOR1_NAME, subject);
    tappedMsg = TestUtil.waitForMessage(tappedMbox, "in:sent subject:\"" + subject + "\"");
    interceptMsg = TestUtil.waitForMessage(interceptorMbox, "subject:intercepted subject:\"" + subject + "\"");
    verifyInterceptMessage(interceptMsg, "add message", "Sent", Integer.toString(Mailbox.ID_FOLDER_SENT));
    compareContent(tappedMbox, tappedMsg, interceptorMbox, interceptMsg);
    // Send message with save-to-sent turned off.
    TestUtil.setAccountAttr(RECIPIENT_NAME, Provisioning.A_zimbraPrefSaveToSent, LdapConstants.LDAP_FALSE);
    subject = NAME_PREFIX + " testIntercept-send-2";
    TestUtil.sendMessage(tappedMbox, INTERCEPTOR1_NAME, subject);
    interceptMsg = TestUtil.waitForMessage(interceptorMbox, "subject:intercepted subject:\"" + subject + "\"");
    verifyInterceptMessage(interceptMsg, "send message", "none", "none");
    // Check intercepting headers only.
    TestUtil.setAccountAttr(RECIPIENT_NAME, Provisioning.A_zimbraInterceptSendHeadersOnly, LdapConstants.LDAP_TRUE);
    subject = NAME_PREFIX + " testIntercept-headers-only";
    TestUtil.sendMessage(interceptorMbox, RECIPIENT_NAME, subject);
    tappedMsg = TestUtil.waitForMessage(tappedMbox, "in:inbox subject:\"" + subject + "\"");
    interceptMsg = TestUtil.waitForMessage(interceptorMbox, "subject:intercepted subject:\"" + subject + "\"");
    verifyInterceptMessage(interceptMsg, "add message", "Inbox", Integer.toString(Mailbox.ID_FOLDER_INBOX));
    compareContent(tappedMbox, tappedMsg, interceptorMbox, interceptMsg);
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZOutgoingMessage(com.zimbra.client.ZMailbox.ZOutgoingMessage) ZMailbox(com.zimbra.client.ZMailbox) ZEmailAddress(com.zimbra.client.ZEmailAddress) MessagePart(com.zimbra.client.ZMailbox.ZOutgoingMessage.MessagePart) ArrayList(java.util.ArrayList)

Example 14 with ZMessage

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

the class TestMessageIntercept method testInterceptMultiValue.

/**
     * Confirms that legal intercept works with multiple interceptor addresses (bug 30961).
     */
public void testInterceptMultiValue() throws Exception {
    // Turn on legal intercept for recipient account.
    String interceptor1Address = TestUtil.getAddress(INTERCEPTOR1_NAME);
    String interceptor2Address = TestUtil.getAddress(INTERCEPTOR2_NAME);
    String senderAddress = TestUtil.getAddress(SENDER_NAME);
    String[] interceptorAddresses = new String[] { interceptor1Address, interceptor2Address };
    TestUtil.setAccountAttr(RECIPIENT_NAME, Provisioning.A_zimbraInterceptAddress, interceptorAddresses);
    TestUtil.setAccountAttr(RECIPIENT_NAME, Provisioning.A_zimbraInterceptSendHeadersOnly, LdapConstants.LDAP_FALSE);
    // Send message to recipient account.
    ZMailbox tappedMbox = TestUtil.getZMailbox(RECIPIENT_NAME);
    String tappedAddress = TestUtil.getAddress(RECIPIENT_NAME);
    String subject = NAME_PREFIX + " testIntercept-receive";
    TestUtil.addMessageLmtp(subject, tappedAddress, senderAddress);
    // Make sure both interceptor accounts intercepted it.
    ZMailbox interceptor1Mbox = TestUtil.getZMailbox(INTERCEPTOR1_NAME);
    ZMailbox interceptor2Mbox = TestUtil.getZMailbox(INTERCEPTOR2_NAME);
    ZMessage tappedMsg = TestUtil.getMessage(tappedMbox, "subject:\"" + subject + "\"");
    ZMessage interceptMsg1 = TestUtil.waitForMessage(interceptor1Mbox, "subject:\"" + subject + "\"");
    ZMessage interceptMsg2 = TestUtil.waitForMessage(interceptor2Mbox, "subject:\"" + subject + "\"");
    verifyInterceptMessage(interceptMsg1, "add message", "Inbox", Integer.toString(Mailbox.ID_FOLDER_INBOX));
    verifyInterceptMessage(interceptMsg2, "add message", "Inbox", Integer.toString(Mailbox.ID_FOLDER_INBOX));
    compareContent(tappedMbox, tappedMsg, interceptor1Mbox, interceptMsg1);
    compareContent(tappedMbox, tappedMsg, interceptor2Mbox, interceptMsg2);
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZMailbox(com.zimbra.client.ZMailbox)

Example 15 with ZMessage

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

the class TestFilter method testFullMatchAfterPartialMatch.

/**
     * Tests fix for bug 55927.
     */
@Test
public void testFullMatchAfterPartialMatch() throws Exception {
    List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
    List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
    List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
    conditions.add(new ZBodyCondition(BodyOp.CONTAINS, "MatchThis"));
    actions.add(new ZMarkAction(MarkOp.FLAGGED));
    rules.add(new ZFilterRule("testFullMatchAfterPartialMatch", true, false, conditions, actions));
    ZFilterRules zRules = new ZFilterRules(rules);
    saveIncomingRules(mMbox, zRules);
    // Add a message and test the flagged state.
    String subject = NAME_PREFIX + " testFullMatchAfterPartialMatch";
    String content = new MessageBuilder().withSubject(subject).withBody("MatchMatchThis").create();
    TestUtil.addMessageLmtp(new String[] { USER_NAME }, USER_NAME, content);
    ZMessage msg = TestUtil.getMessage(mMbox, "in:inbox subject:\"" + subject + "\"");
    assertTrue("Unexpected message flag state", msg.isFlagged());
}
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) ZFilterRules(com.zimbra.client.ZFilterRules) 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