Search in sources :

Example 41 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 42 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 43 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 44 with ZMessage

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

the class TestJaxb method acceptInvite.

private ZMessage acceptInvite(ZMailbox attendeeBox, ZMailbox organizerBox, ZMessage inviteMsg, String subject) throws Exception {
    SendInviteReplyRequest sirReq = new SendInviteReplyRequest(inviteMsg.getId(), 0, /* componentNum */
    "ACCEPT");
    sirReq.setIdentityId(attendeeBox.getAccountInfo(false).getId());
    // ZWC 8.6 and earlier used to set this to false.  Now sets it to true.
    sirReq.setUpdateOrganizer(true);
    MimePartInfo mimePart = MimePartInfo.createForContentType("multipart/alternative");
    mimePart.addMimePart(MimePartInfo.createForContentTypeAndContent("text/plain", "Accepting"));
    mimePart.addMimePart(MimePartInfo.createForContentTypeAndContent("text/html", "<html><body><p><b>Accepting</b></p></body></html>"));
    Msg msg = new Msg();
    msg.setReplyType("r");
    msg.setIdentityId(attendeeBox.getAccountInfo(false).getId());
    EmailAddrInfo orgAddr = EmailAddrInfo.createForAddressPersonalAndAddressType(organizerBox.getName(), organizerBox.getName(), "t");
    EmailAddrInfo attendeeAddr = EmailAddrInfo.createForAddressPersonalAndAddressType(attendeeBox.getName(), getCN(attendeeBox), "f");
    msg.addEmailAddress(orgAddr);
    msg.addEmailAddress(attendeeAddr);
    String acceptSubject = "Accept: " + subject;
    msg.setSubject(acceptSubject);
    msg.setMimePart(mimePart);
    sirReq.setMsg(msg);
    SendInviteReplyResponse sirResp = attendeeBox.invokeJaxb(sirReq);
    Assert.assertNotNull("JAXB SendInviteReplyResponse object", sirResp);
    ZMessage inboxMsg = TestUtil.waitForMessage(organizerBox, String.format("subject:\"%s\"", acceptSubject));
    Assert.assertNotNull("ZMessage for accept", inboxMsg);
    return inboxMsg;
}
Also used : SendInviteReplyRequest(com.zimbra.soap.mail.message.SendInviteReplyRequest) Msg(com.zimbra.soap.mail.type.Msg) ZMessage(com.zimbra.client.ZMessage) SendInviteReplyResponse(com.zimbra.soap.mail.message.SendInviteReplyResponse) EmailAddrInfo(com.zimbra.soap.mail.type.EmailAddrInfo) MimePartInfo(com.zimbra.soap.mail.type.MimePartInfo)

Example 45 with ZMessage

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

the class TestIndex method checkQuery.

private void checkQuery(String query, String msgId) throws Exception {
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    List<ZMessage> messages = TestUtil.search(mbox, query);
    if (msgId == null) {
        Assert.assertEquals(0, messages.size());
    } else {
        Assert.assertEquals(1, messages.size());
        Assert.assertEquals(msgId, messages.get(0).getId());
    }
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZMailbox(com.zimbra.client.ZMailbox)

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