Search in sources :

Example 6 with ZEmailAddress

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

the class TestFilter method testNotifyActionUseOrigHeaders.

@Test
public void testNotifyActionUseOrigHeaders() throws Exception {
    if (mAvailableRFCCompliantNotify) {
        fail("Unable to test because 'zimbraSieveNotifyActionRFCCompliant' is set to TRUE");
        return;
    }
    List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
    List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
    List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
    conditions.add(new ZFilterCondition.ZTrueCondition());
    // add an action to notify user2
    // copy headers From,To,Cc,Subject from the original message onto the notification message
    actions.add(new ZFilterAction.ZNotifyAction(TestUtil.getAddress(REMOTE_USER_NAME), null, "${BODY}", -1, "From,To,Cc,Subject"));
    rules.add(new ZFilterRule("testNotifyActionUseOrigHeaders", true, false, conditions, actions));
    saveIncomingRules(mMbox, new ZFilterRules(rules));
    String subject = NAME_PREFIX + " testNotifyActionUseOrigHeaders";
    String body = "Hi, How r u?";
    String msg = new MessageBuilder().withFrom(REMOTE_USER_NAME).withToRecipient(USER_NAME).withCcRecipient(USER_NAME).withSubject(subject).withBody(body).create();
    // send msg to user1
    TestUtil.addMessageLmtp(new String[] { USER_NAME }, REMOTE_USER_NAME, msg);
    // check notification msg from user1 in user2's mailbox
    ZMessage zMessage = TestUtil.waitForMessage(TestUtil.getZMailbox(REMOTE_USER_NAME), "in:inbox subject:\"" + subject + "\"");
    boolean checkedFrom = false, checkedTo = false, checkedCc = false;
    List<ZEmailAddress> msgAddrs = zMessage.getEmailAddresses();
    for (ZEmailAddress addr : msgAddrs) {
        if ("f".equals(addr.getType())) {
            assertEquals(TestUtil.addDomainIfNecessary(REMOTE_USER_NAME), addr.getAddress());
            if (!checkedFrom) {
                checkedFrom = true;
            } else {
                fail("multiple From addresses");
            }
        }
        if ("t".equals(addr.getType())) {
            assertEquals(TestUtil.addDomainIfNecessary(USER_NAME), addr.getAddress());
            if (!checkedTo) {
                checkedTo = true;
            } else {
                fail("multiple To addresses");
            }
        }
        if ("c".equals(addr.getType())) {
            assertEquals(TestUtil.addDomainIfNecessary(USER_NAME), addr.getAddress());
            if (!checkedCc) {
                checkedCc = true;
            } else {
                fail("multiple Cc addresses");
            }
        }
    }
    assertEquals(subject, zMessage.getSubject());
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZFilterCondition(com.zimbra.client.ZFilterCondition) ArrayList(java.util.ArrayList) ZFilterRule(com.zimbra.client.ZFilterRule) ZFilterAction(com.zimbra.client.ZFilterAction) ZEmailAddress(com.zimbra.client.ZEmailAddress) ZFilterRules(com.zimbra.client.ZFilterRules) Test(org.junit.Test)

Example 7 with ZEmailAddress

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

the class TestDraftCount method testSomeDraftsHaveRecipients.

@Test
public void testSomeDraftsHaveRecipients() throws Exception {
    for (int i = 0; i < numMsgs; i++) {
        ZOutgoingMessage msg = new ZOutgoingMessage();
        msg.setMessagePart(new MessagePart("text/plain", "test body " + i));
        msg.setSubject("test message " + i);
        List<ZEmailAddress> addresses = new ArrayList<ZEmailAddress>();
        if (i % 2 == 0) {
            addresses.add(new ZEmailAddress("testuser" + i, null, null, "t"));
            msg.setAddresses(addresses);
        }
        ZMessage saved = mbox.saveDraft(msg, null, "6");
    }
    checkMessageCount("in:drafts", numMsgs);
    deleteFromQuery("in:drafts");
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZOutgoingMessage(com.zimbra.client.ZMailbox.ZOutgoingMessage) ZEmailAddress(com.zimbra.client.ZEmailAddress) MessagePart(com.zimbra.client.ZMailbox.ZOutgoingMessage.MessagePart) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 8 with ZEmailAddress

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

the class TestDraftCount method testAllDraftsHaveRecipients.

@Test
public void testAllDraftsHaveRecipients() throws Exception {
    for (int i = 0; i < numMsgs; i++) {
        ZOutgoingMessage msg = new ZOutgoingMessage();
        msg.setMessagePart(new MessagePart("text/plain", "test body " + i));
        msg.setSubject("test message " + i);
        List<ZEmailAddress> addresses = new ArrayList<ZEmailAddress>();
        addresses.add(new ZEmailAddress("testuser" + i, null, null, "t"));
        msg.setAddresses(addresses);
        ZMessage saved = mbox.saveDraft(msg, null, "6");
    }
    checkMessageCount("in:drafts", numMsgs);
    deleteFromQuery("in:drafts");
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZOutgoingMessage(com.zimbra.client.ZMailbox.ZOutgoingMessage) ZEmailAddress(com.zimbra.client.ZEmailAddress) MessagePart(com.zimbra.client.ZMailbox.ZOutgoingMessage.MessagePart) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 9 with ZEmailAddress

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

the class ZConversationSummaryEvent method toZJSONObject.

public ZJSONObject toZJSONObject() throws JSONException {
    try {
        ZJSONObject zjo = new ZJSONObject();
        zjo.put("id", getId());
        if (getFlags(null) != null)
            zjo.put("flags", getFlags(null));
        if (getTagIds(null) != null)
            zjo.put("tags", getTagIds(null));
        if (getSubject(null) != null)
            zjo.put("subject", getSubject(null));
        if (getFragment(null) != null)
            zjo.put("fragment", getFragment(null));
        if (getMessageCount(-1) != -1)
            zjo.put("messageCount", getMessageCount(-1));
        if (getDate(-1) != -1)
            zjo.put("date", getDate(-1));
        List<ZEmailAddress> addrs = getRecipients(null);
        if (addrs != null)
            zjo.put("recipients", addrs);
        return zjo;
    } catch (ServiceException se) {
        throw new JSONException(se);
    }
}
Also used : ZEmailAddress(com.zimbra.client.ZEmailAddress) ServiceException(com.zimbra.common.service.ServiceException) ZJSONObject(com.zimbra.client.ZJSONObject) ToZJSONObject(com.zimbra.client.ToZJSONObject) JSONException(org.json.JSONException)

Example 10 with ZEmailAddress

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

the class ZCreateMessageEvent method toZJSONObject.

public ZJSONObject toZJSONObject() throws JSONException {
    try {
        ZJSONObject zjo = new ZJSONObject();
        zjo.put("id", getId());
        if (getFolderId(null) != null)
            zjo.put("folderId", getFolderId(null));
        if (getConversationId(null) != null)
            zjo.put("conversationId", getConversationId(null));
        if (getFlags(null) != null)
            zjo.put("flags", getFlags(null));
        if (getTagIds(null) != null)
            zjo.put("tags", getTagIds(null));
        if (getSubject(null) != null)
            zjo.put("subject", getSubject(null));
        if (getFragment(null) != null)
            zjo.put("fragment", getFragment(null));
        if (getSize(-1) != -1)
            zjo.put("size", getSize(-1));
        if (getReceivedDate(-1) != -1)
            zjo.put("receivedDate", getReceivedDate(-1));
        if (getSentDate(-1) != -1)
            zjo.put("sentDate", getSentDate(-1));
        List<ZEmailAddress> addrs = getEmailAddresses(null);
        if (addrs != null)
            zjo.put("addresses", addrs);
        return zjo;
    } catch (ServiceException se) {
        throw new JSONException(se);
    }
}
Also used : ZEmailAddress(com.zimbra.client.ZEmailAddress) ServiceException(com.zimbra.common.service.ServiceException) ZJSONObject(com.zimbra.client.ZJSONObject) ToZJSONObject(com.zimbra.client.ToZJSONObject) JSONException(org.json.JSONException)

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