Search in sources :

Example 1 with ZEmailAddress

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

the class TestSaveDraft method testDoesntAutoSendDraft.

/**
     * Verifies message sent with no 'timeout' is not sent automatically.
     */
@Test
public void testDoesntAutoSendDraft() throws Exception {
    TestUtil.createAccount(USER_NAME);
    TestUtil.createAccount(REMOTE_USER_NAME);
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    ZMailbox.ZOutgoingMessage outgoingMsg = new ZMailbox.ZOutgoingMessage();
    List<ZEmailAddress> addrs = new LinkedList<ZEmailAddress>();
    String senderAddr = TestUtil.getAddress(USER_NAME);
    addrs.add(new ZEmailAddress(senderAddr, null, null, ZEmailAddress.EMAIL_TYPE_FROM));
    String rcptAddr = TestUtil.getAddress(REMOTE_USER_NAME);
    addrs.add(new ZEmailAddress(rcptAddr, null, null, ZEmailAddress.EMAIL_TYPE_TO));
    outgoingMsg.setAddresses(addrs);
    String subject = NAME_PREFIX + " autoSendDraft";
    outgoingMsg.setSubject(subject);
    mbox.saveDraft(outgoingMsg, null, Integer.toString(Mailbox.ID_FOLDER_DRAFTS), 0);
    // make sure message is still in the Drafts folder
    boolean deletedFromSent = TestUtil.search(mbox, "in:Drafts " + subject).isEmpty();
    Assert.assertFalse("message should still be in the Drafts folder", deletedFromSent);
}
Also used : ZOutgoingMessage(com.zimbra.client.ZMailbox.ZOutgoingMessage) ZMailbox(com.zimbra.client.ZMailbox) ZEmailAddress(com.zimbra.client.ZEmailAddress) ZOutgoingMessage(com.zimbra.client.ZMailbox.ZOutgoingMessage) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 2 with ZEmailAddress

use of com.zimbra.client.ZEmailAddress 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 3 with ZEmailAddress

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

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

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

ZEmailAddress (com.zimbra.client.ZEmailAddress)17 ZOutgoingMessage (com.zimbra.client.ZMailbox.ZOutgoingMessage)11 ZMessage (com.zimbra.client.ZMessage)11 Test (org.junit.Test)11 ZMailbox (com.zimbra.client.ZMailbox)9 ArrayList (java.util.ArrayList)9 MessagePart (com.zimbra.client.ZMailbox.ZOutgoingMessage.MessagePart)8 AttachedMessagePart (com.zimbra.client.ZMailbox.ZOutgoingMessage.AttachedMessagePart)4 LinkedList (java.util.LinkedList)3 ToZJSONObject (com.zimbra.client.ToZJSONObject)2 ZJSONObject (com.zimbra.client.ZJSONObject)2 ZMimePart (com.zimbra.client.ZMessage.ZMimePart)2 ServiceException (com.zimbra.common.service.ServiceException)2 JSONException (org.json.JSONException)2 ZFilterAction (com.zimbra.client.ZFilterAction)1 ZFilterCondition (com.zimbra.client.ZFilterCondition)1 ZFilterRule (com.zimbra.client.ZFilterRule)1 ZFilterRules (com.zimbra.client.ZFilterRules)1 SoapFaultException (com.zimbra.common.soap.SoapFaultException)1 Account (com.zimbra.cs.account.Account)1