Search in sources :

Example 1 with ZOutgoingMessage

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

the class TestSaveDraft method testIdentityId.

/**
     * Confirms that we update the identity id during a SaveDraft operation (bug 60066).
     */
@Test
public void testIdentityId() throws Exception {
    TestUtil.createAccount(USER_NAME);
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    // Save initial draft.
    ZOutgoingMessage outgoing = TestUtil.getOutgoingMessage(USER_NAME, NAME_PREFIX + " testIdentityId", "testIdentityId", null);
    ZIdentity ident = TestUtil.getDefaultIdentity(mbox);
    outgoing.setIdentityId(ident.getId());
    ZMessage msg = mbox.saveDraft(outgoing, null, Integer.toString(Mailbox.ID_FOLDER_DRAFTS));
    Assert.assertEquals(ident.getId(), msg.getIdentityId());
    // Save another draft with a new identity id.
    outgoing.setIdentityId("xyz");
    msg = mbox.saveDraft(outgoing, msg.getId(), Integer.toString(Mailbox.ID_FOLDER_DRAFTS));
    Assert.assertEquals("xyz", msg.getIdentityId());
    // Unset identity id.
    outgoing.setIdentityId("");
    msg = mbox.saveDraft(outgoing, msg.getId(), Integer.toString(Mailbox.ID_FOLDER_DRAFTS));
    Assert.assertEquals(null, msg.getIdentityId());
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZOutgoingMessage(com.zimbra.client.ZMailbox.ZOutgoingMessage) ZMailbox(com.zimbra.client.ZMailbox) ZIdentity(com.zimbra.client.ZIdentity) Test(org.junit.Test)

Example 2 with ZOutgoingMessage

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

the class TestMinusOperator method setUp.

@Override
@BeforeClass
public void setUp() throws ServiceException {
    TestUtil.createAccount(USER_NAME);
    TestUtil.createAccount(REMOTE_USER_NAME);
    mbox = TestUtil.getZMailbox(USER_NAME);
    ZOutgoingMessage msg = TestUtil.getOutgoingMessage(REMOTE_USER_NAME, "test message", "far over the misty mountains cold", null);
    mbox.sendMessage(msg, null, false);
}
Also used : ZOutgoingMessage(com.zimbra.client.ZMailbox.ZOutgoingMessage) BeforeClass(org.junit.BeforeClass)

Example 3 with ZOutgoingMessage

use of com.zimbra.client.ZMailbox.ZOutgoingMessage 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 4 with ZOutgoingMessage

use of com.zimbra.client.ZMailbox.ZOutgoingMessage 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 5 with ZOutgoingMessage

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

the class TestUtil method sendMessage.

public static void sendMessage(ZMailbox senderMbox, String recipientName, String subject, String body, String attachmentUploadId) throws Exception {
    ZOutgoingMessage msg = getOutgoingMessage(recipientName, subject, body, attachmentUploadId);
    senderMbox.sendMessage(msg, null, false);
}
Also used : ZOutgoingMessage(com.zimbra.client.ZMailbox.ZOutgoingMessage)

Aggregations

ZOutgoingMessage (com.zimbra.client.ZMailbox.ZOutgoingMessage)19 ZMessage (com.zimbra.client.ZMessage)12 Test (org.junit.Test)10 ZEmailAddress (com.zimbra.client.ZEmailAddress)9 ZMailbox (com.zimbra.client.ZMailbox)8 MessagePart (com.zimbra.client.ZMailbox.ZOutgoingMessage.MessagePart)8 ArrayList (java.util.ArrayList)8 AttachedMessagePart (com.zimbra.client.ZMailbox.ZOutgoingMessage.AttachedMessagePart)5 ZInvite (com.zimbra.client.ZInvite)2 ZComponent (com.zimbra.client.ZInvite.ZComponent)2 ZOrganizer (com.zimbra.client.ZInvite.ZOrganizer)2 ZMimePart (com.zimbra.client.ZMessage.ZMimePart)2 BeforeClass (org.junit.BeforeClass)2 ZDateTime (com.zimbra.client.ZDateTime)1 ZIdentity (com.zimbra.client.ZIdentity)1 ZAttendee (com.zimbra.client.ZInvite.ZAttendee)1 ZAppointmentResult (com.zimbra.client.ZMailbox.ZAppointmentResult)1 ZSendMessageResponse (com.zimbra.client.ZMailbox.ZSendMessageResponse)1 ServiceException (com.zimbra.common.service.ServiceException)1 Element (com.zimbra.common.soap.Element)1