Search in sources :

Example 71 with ZMailbox

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

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

the class TestOutOfOffice method testOOOWhenForwardNoDelivery.

/**
 * Tests fix for bug 26818 (OOO message does not work when
 * "Don't keep a local copy of messages" is checked)
 *
 * @throws Exception
 */
@Test
public void testOOOWhenForwardNoDelivery() throws Exception {
    Account recipientAcct = TestUtil.getAccount(RECIPIENT_NAME);
    Map<String, Object> attrs = new HashMap<String, Object>();
    attrs.put(Provisioning.A_zimbraPrefOutOfOfficeReplyEnabled, ProvisioningConstants.TRUE);
    attrs.put(Provisioning.A_zimbraPrefOutOfOfficeReply, "I am OOO");
    attrs.put(Provisioning.A_zimbraPrefMailForwardingAddress, "abc@xyz.com");
    attrs.put(Provisioning.A_zimbraPrefMailLocalDeliveryDisabled, ProvisioningConstants.TRUE);
    Provisioning.getInstance().modifyAttrs(recipientAcct, attrs);
    ZMailbox senderMbox = TestUtil.getZMailbox(SENDER_NAME);
    ZMailbox recipMbox = TestUtil.getZMailbox(RECIPIENT_NAME);
    String subject = NAME_PREFIX + " testOOOWhenForwardNoDelivery";
    // Send the message
    TestUtil.sendMessage(senderMbox, RECIPIENT_NAME, subject, "testing");
    // Make sure message was not delivered since local delivery is disabled
    Assert.assertEquals(0, TestUtil.search(recipMbox, "in:inbox subject:'" + subject + "'").size());
    // But check for out-of-office reply
    TestUtil.waitForMessage(senderMbox, "in:inbox subject:'" + subject + "'");
}
Also used : Account(com.zimbra.cs.account.Account) ZMailbox(com.zimbra.client.ZMailbox) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 73 with ZMailbox

use of com.zimbra.client.ZMailbox 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).
 */
@Test
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);
    Assert.assertEquals(recipient.getName(), fromAddress.getAddress());
    Assert.assertEquals(newFromDisplay, fromAddress.getPersonal());
    Assert.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);
    Assert.assertEquals(recipient.getName(), fromAddress.getAddress());
    Assert.assertEquals(recipient.getDisplayName(), fromAddress.getPersonal());
    ZEmailAddress replyToAddress = getAddress(reply, ZEmailAddress.EMAIL_TYPE_REPLY_TO);
    Assert.assertEquals(newReplyToAddress, replyToAddress.getAddress());
    Assert.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);
    Assert.assertEquals(newFromAddress, fromAddress.getAddress());
    Assert.assertEquals(newFromDisplay, fromAddress.getPersonal());
    replyToAddress = getAddress(reply, ZEmailAddress.EMAIL_TYPE_REPLY_TO);
    Assert.assertEquals(newReplyToAddress, replyToAddress.getAddress());
    Assert.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) Test(org.junit.Test)

Example 74 with ZMailbox

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

the class TestPop3Import method getZDataSource.

private ZPop3DataSource getZDataSource() throws Exception {
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    List<ZDataSource> dataSources = mbox.getAllDataSources();
    for (ZDataSource ds : dataSources) {
        if (ds.getName() != null && ds.getName().equals(DATA_SOURCE_NAME)) {
            return (ZPop3DataSource) ds;
        }
    }
    Assert.fail("Could not find data source " + DATA_SOURCE_NAME);
    return null;
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) ZPop3DataSource(com.zimbra.client.ZPop3DataSource) ZDataSource(com.zimbra.client.ZDataSource)

Example 75 with ZMailbox

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

the class TestMaxMessageSize method testMaxMessageSizeAboveThreshold.

@Test
public void testMaxMessageSizeAboveThreshold() throws Exception {
    setMaxMessageSize(TEST_MAX_MESSAGE_SIZE);
    Map<String, byte[]> attachments = new HashMap<String, byte[]>();
    attachments.put("file1.exe", new byte[800]);
    attachments.put("file2.exe", new byte[700]);
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    String aid = mbox.uploadAttachments(attachments, 5000);
    try {
        TestUtil.sendMessage(mbox, USER_NAME, NAME_PREFIX, "Message size above threshold", aid);
        Assert.fail("sendMessage() should not have succeeded");
    } catch (SoapFaultException e) {
        // Message send was not allowed, as expected.
        validateMessageTooBigFault(e);
    }
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) HashMap(java.util.HashMap) SoapFaultException(com.zimbra.common.soap.SoapFaultException) Test(org.junit.Test)

Aggregations

ZMailbox (com.zimbra.client.ZMailbox)383 Test (org.junit.Test)288 ZFolder (com.zimbra.client.ZFolder)90 ZMessage (com.zimbra.client.ZMessage)82 Mailbox (com.zimbra.cs.mailbox.Mailbox)61 Account (com.zimbra.cs.account.Account)60 ServiceException (com.zimbra.common.service.ServiceException)55 ArrayList (java.util.ArrayList)38 IOException (java.io.IOException)35 MessageData (com.zimbra.cs.mailclient.imap.MessageData)28 ZMountpoint (com.zimbra.client.ZMountpoint)26 Message (com.zimbra.cs.mailbox.Message)24 HashMap (java.util.HashMap)23 ZOutgoingMessage (com.zimbra.client.ZMailbox.ZOutgoingMessage)21 ZTag (com.zimbra.client.ZTag)21 SoapFaultException (com.zimbra.common.soap.SoapFaultException)21 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)21 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)20 HttpClient (org.apache.http.client.HttpClient)19 ZSearchParams (com.zimbra.client.ZSearchParams)18