Search in sources :

Example 81 with ZMessage

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

the class TestSendAndReceive method testSendDraftNoHeader.

@Test
public void testSendDraftNoHeader() throws Exception {
    TestUtil.createAccount(USER_NAME);
    TestUtil.createAccount(REMOTE_USER_NAME);
    MailSender.registerPreSendMailListener(listener);
    ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
    String subj = "Thorin";
    String body = "far over the misty mountains cold";
    ZOutgoingMessage msg = TestUtil.getOutgoingMessage(REMOTE_USER_NAME, subj, body, null);
    ZMessage draft = zmbox.saveDraft(msg, null, Integer.toString(Mailbox.ID_FOLDER_DRAFTS));
    Element request = new Element.JSONElement(MailConstants.SEND_MSG_REQUEST);
    request.addUniqueElement(MailConstants.E_MSG).addAttribute(MailConstants.A_DRAFT_ID, draft.getId()).addAttribute(MailConstants.A_SEND_FROM_DRAFT, true);
    SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getSoapUrl());
    transport.setAuthToken(zmbox.getAuthToken());
    transport.invoke(request);
    Assert.assertFalse("Listener was not supposed to be triggered", listener.isTriggered());
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZOutgoingMessage(com.zimbra.client.ZMailbox.ZOutgoingMessage) ZMailbox(com.zimbra.client.ZMailbox) Element(com.zimbra.common.soap.Element) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport) Test(org.junit.Test)

Example 82 with ZMessage

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

the class TestSendAndReceive method testInlineAttachment.

/**
     * Test inline attachment. See bug #88933
     */
@Test
public void testInlineAttachment() throws Exception {
    TestUtil.createAccount(USER_NAME);
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    //create inline image attachment
    String imgName = "synacore.jpg";
    String content = "<content><img src=\"cid:" + imgName + "\"></content>";
    List<AttachedMessagePart> inlineAttachments = new ArrayList<AttachedMessagePart>();
    String attachId = mbox.uploadAttachment(imgName, new byte[1024], MimeConstants.CT_IMAGE_JPEG, 5000);
    AttachedMessagePart inlineImg = new AttachedMessagePart(attachId, imgName);
    inlineAttachments.add(inlineImg);
    MessagePart html = new MessagePart(MimeConstants.CT_TEXT_HTML, content, inlineAttachments);
    //create outgoing message
    String subject = NAME_PREFIX + " testInlineAttachment " + MimeConstants.CT_TEXT_PLAIN + " 1";
    ZOutgoingMessage outgoingMsg = new ZOutgoingMessage();
    List<ZEmailAddress> addresses = new ArrayList<ZEmailAddress>();
    addresses.add(new ZEmailAddress(TestUtil.addDomainIfNecessary(USER_NAME), null, null, ZEmailAddress.EMAIL_TYPE_TO));
    outgoingMsg.setAddresses(addresses);
    outgoingMsg.setSubject(subject);
    MessagePart related = new MessagePart(MimeConstants.CT_MULTIPART_RELATED, html);
    outgoingMsg.setMessagePart(related);
    mbox.sendMessage(outgoingMsg, null, false);
    //verify that received message has the attachment
    ZMessage incoming = TestUtil.waitForMessage(mbox, "in:inbox subject:\"" + subject + "\"");
    Assert.assertTrue("this message should have an attachment", incoming.hasAttachment());
    Assert.assertNotNull("this message should have mime parts", incoming.getMimeStructure());
    Assert.assertNotNull("this message should have two subparts", incoming.getMimeStructure().getChildren());
    List<ZMimePart> parts = incoming.getMimeStructure().getChildren();
    Assert.assertEquals("this message should have 2 subparts", 2, parts.size());
    Assert.assertTrue("one of the parts should have a content id", parts.get(0).getContentId() != null || parts.get(1).getContentId() != null);
    Assert.assertTrue("one of the parts should be " + imgName, imgName.equalsIgnoreCase(parts.get(0).getFileName()) || imgName.equalsIgnoreCase(parts.get(1).getFileName()));
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZOutgoingMessage(com.zimbra.client.ZMailbox.ZOutgoingMessage) ZMailbox(com.zimbra.client.ZMailbox) AttachedMessagePart(com.zimbra.client.ZMailbox.ZOutgoingMessage.AttachedMessagePart) ZEmailAddress(com.zimbra.client.ZEmailAddress) MessagePart(com.zimbra.client.ZMailbox.ZOutgoingMessage.MessagePart) AttachedMessagePart(com.zimbra.client.ZMailbox.ZOutgoingMessage.AttachedMessagePart) ArrayList(java.util.ArrayList) ZMimePart(com.zimbra.client.ZMessage.ZMimePart) Test(org.junit.Test)

Example 83 with ZMessage

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

the class TestSendAndReceive method testZimbraReceivedHeader.

/**
     * Confirms that the message received date is set to the value of the
     * <tt>X-Zimbra-Received</tt> header.
     */
@Test
public void testZimbraReceivedHeader() throws Exception {
    Account acct = TestUtil.createAccount(USER_NAME);
    String[] tzs = { "America/Los_Angeles" };
    acct.setPrefTimeZoneId(tzs);
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    // Add message.
    String msgContent = new String(ByteUtil.getContent(new File(LC.zimbra_home.value() + "/unittest/testZimbraReceivedHeader.msg")));
    TestUtil.addMessageLmtp(new String[] { USER_NAME }, USER_NAME, msgContent);
    // Test date.
    List<ZMessage> messages = TestUtil.search(mbox, "subject:testZimbraReceivedHeader");
    Assert.assertEquals("Unexpected message count", 1, messages.size());
    ZMessage msg = messages.get(0);
    TimeZone tz = mbox.getPrefs().getTimeZone();
    ZimbraLog.test.debug("Timezone ID for mbox %s is %s", mbox.getName(), tz.getID());
    Calendar cal = Calendar.getInstance(tz);
    cal.setTimeInMillis(msg.getReceivedDate());
    Assert.assertEquals("Year wrong for received date", 2005, cal.get(Calendar.YEAR));
    Assert.assertEquals("Month wrong for received date", 1, cal.get(Calendar.MONTH));
    Assert.assertEquals("Day wrong for received date", 27, cal.get(Calendar.DAY_OF_MONTH));
}
Also used : ZMessage(com.zimbra.client.ZMessage) Account(com.zimbra.cs.account.Account) TimeZone(java.util.TimeZone) ZMailbox(com.zimbra.client.ZMailbox) Calendar(java.util.Calendar) File(java.io.File) Test(org.junit.Test)

Example 84 with ZMessage

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

the class TestSendAndReceive method testReceivedHeaders.

/**
     * Verifies that we set the Return-Path and Received headers
     * for incoming messages.
     */
@Test
public void testReceivedHeaders() throws Exception {
    TestUtil.createAccount(USER_NAME);
    TestUtil.createAccount(REMOTE_USER_NAME);
    // Send message from user2 to user1
    String sender = TestUtil.getAddress(REMOTE_USER_NAME);
    String recipient = TestUtil.getAddress(USER_NAME);
    TestUtil.addMessageLmtp(NAME_PREFIX + " testReceivedHeaders()", recipient, sender);
    // Search
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    List<ZMessage> messages = TestUtil.search(mbox, NAME_PREFIX);
    Assert.assertEquals("Unexpected message count", 1, messages.size());
    // Get the message content, since a search won't return the content
    ZGetMessageParams params = new ZGetMessageParams();
    params.setId(messages.get(0).getId());
    params.setRawContent(true);
    ZMessage message = mbox.getMessage(params);
    String content = message.getContent();
    // Check headers
    boolean foundReceived = false;
    boolean foundReturnPath = false;
    BufferedReader reader = new BufferedReader(new StringReader(content));
    String line = reader.readLine();
    while (line != null) {
        Matcher matcher = PAT_RECEIVED.matcher(line);
        if (matcher.matches()) {
            ZimbraLog.test.debug("Found " + line);
            foundReceived = true;
        }
        matcher = PAT_RETURN_PATH.matcher(line);
        if (matcher.matches()) {
            foundReturnPath = true;
            Assert.assertEquals("Sender doesn't match", sender, matcher.group(1));
            ZimbraLog.test.debug("Found " + line);
        }
        line = reader.readLine();
    }
    reader.close();
    Assert.assertTrue("Received header not found.  Content=\n" + content, foundReceived);
    Assert.assertTrue("Return-Path header not found.  Content=\n" + content, foundReturnPath);
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZMailbox(com.zimbra.client.ZMailbox) ZGetMessageParams(com.zimbra.client.ZGetMessageParams) Matcher(java.util.regex.Matcher) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 85 with ZMessage

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

the class TestSearchConv method markMessagesUnreadByIndex.

private void markMessagesUnreadByIndex(int[] indexes) throws Exception {
    ArrayList<String> ids = new ArrayList<String>();
    for (int i : indexes) {
        ids.add(msgIds.get(i));
    }
    String commaSeparatedIds = Joiner.on(",").join(ids);
    markAllMessagesRead();
    if (commaSeparatedIds.length() > 0) {
        mbox.markMessageRead(commaSeparatedIds, false);
    }
    //make sure the messages are marked read/unread correctly
    for (String id : msgIds) {
        ZMessage message = mbox.getMessageById(id);
        boolean isUnread = message.isUnread();
        if (ids.contains(id)) {
            assertTrue(isUnread);
        } else {
            assertFalse(isUnread);
        }
    }
}
Also used : ZMessage(com.zimbra.client.ZMessage) ArrayList(java.util.ArrayList)

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