Search in sources :

Example 11 with ZEmailAddress

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

the class ZMailboxUtil method formatEmail.

public static String formatEmail(List<ZEmailAddress> list, String type, int used) {
    if (list == null || list.size() == 0)
        return "";
    StringBuilder sb = new StringBuilder();
    for (ZEmailAddress e : list) {
        if (e.getType().equalsIgnoreCase(type)) {
            String fe = formatEmail(e);
            used = addEmail(sb, fe, used);
        }
    }
    return sb.toString();
}
Also used : ZEmailAddress(com.zimbra.client.ZEmailAddress)

Example 12 with ZEmailAddress

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

the class TestDraftCount method testMixedFolderCount.

@Test
public void testMixedFolderCount() throws Exception {
    //some inbox messages
    for (int i = 0; i < numMsgs; i++) {
        TestUtil.addMessage(mbox, "test content " + i, "2");
    }
    //and some drafts, some of which have no recipients
    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:inbox OR in:drafts", numMsgs * 2);
    deleteFromQuery("in:inbox OR 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 13 with ZEmailAddress

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

the class TestSendAndReceive method testMalformedContentType.

/**
     * Confirms that we can forward attachments with a malformed content type (bug 42452).
     */
@Test
public void testMalformedContentType() throws Exception {
    TestUtil.createAccount(USER_NAME);
    // Generate original message.
    String subject = NAME_PREFIX + " testMalformedContentType";
    MessageBuilder builder = new MessageBuilder().withFrom(USER_NAME).withToRecipient(USER_NAME).withSubject(subject).withAttachment("This is an attachment", "test.txt", MimeConstants.CT_TEXT_PLAIN);
    // Hack Content-Type so that it's invalid.
    BufferedReader reader = new BufferedReader(new StringReader(builder.create()));
    StringBuilder msgBuf = new StringBuilder();
    String line = reader.readLine();
    boolean replaced = false;
    while (line != null) {
        if (line.matches("Content-Type.*test.txt.*")) {
            line = line.replace("Content-Type: text/plain;", "Content-Type: text/plain;;");
            Assert.assertTrue("Unexpected line: " + line, line.contains(";;"));
            replaced = true;
        }
        msgBuf.append(line).append("\r\n");
        line = reader.readLine();
    }
    Assert.assertTrue("Could not find text/plain attachment.", replaced);
    // Add message to the mailbox.
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    TestUtil.addMessageLmtp(new String[] { USER_NAME }, USER_NAME, msgBuf.toString());
    // Forward the attachment in a new message.
    ZMessage srcMsg = TestUtil.getMessage(mbox, "subject:\"" + subject + "\"");
    ZMimePart srcAttachPart = srcMsg.getMimeStructure().getChildren().get(1);
    Assert.assertEquals("test.txt", srcAttachPart.getFileName());
    ZOutgoingMessage outgoing = new ZOutgoingMessage();
    outgoing.setMessagePart(new MessagePart(MimeConstants.CT_TEXT_PLAIN, "Forwarding attachment."));
    outgoing.setMessagePartsToAttach(Arrays.asList(new AttachedMessagePart(srcMsg.getId(), srcAttachPart.getPartName(), null)));
    String address = TestUtil.getAddress(USER_NAME);
    ZEmailAddress sender = new ZEmailAddress(address, null, null, ZEmailAddress.EMAIL_TYPE_FROM);
    ZEmailAddress recipient = new ZEmailAddress(address, null, null, ZEmailAddress.EMAIL_TYPE_TO);
    outgoing.setAddresses(Arrays.asList(sender, recipient));
    String fwdSubject = NAME_PREFIX + " testMalformedContentType forward";
    outgoing.setSubject(fwdSubject);
    mbox.sendMessage(outgoing, null, false);
    // Make sure the forwarded message arrives.
    ZMessage fwd = TestUtil.waitForMessage(mbox, "in:inbox subject:\"" + fwdSubject + "\"");
    ZMimePart fwdAttachPart = fwd.getMimeStructure().getChildren().get(1);
    Assert.assertEquals("test.txt", fwdAttachPart.getFileName());
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZOutgoingMessage(com.zimbra.client.ZMailbox.ZOutgoingMessage) MessagePart(com.zimbra.client.ZMailbox.ZOutgoingMessage.MessagePart) AttachedMessagePart(com.zimbra.client.ZMailbox.ZOutgoingMessage.AttachedMessagePart) ZMimePart(com.zimbra.client.ZMessage.ZMimePart) ZMailbox(com.zimbra.client.ZMailbox) AttachedMessagePart(com.zimbra.client.ZMailbox.ZOutgoingMessage.AttachedMessagePart) ZEmailAddress(com.zimbra.client.ZEmailAddress) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 14 with ZEmailAddress

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

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

the class TestSaveDraft method testAutoSendDraft.

/** Verifies "send-message-later" functionality. */
@Test
public void testAutoSendDraft() 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);
    // auto-send after 0.5 sec
    mbox.saveDraft(outgoingMsg, null, Integer.toString(Mailbox.ID_FOLDER_DRAFTS), System.currentTimeMillis() + 500);
    // make sure message has arrived in the Sent folder
    TestUtil.waitForMessage(mbox, "in:Sent " + subject);
    // make sure message is no longer in the Drafts folder
    //there is a race here since auto send and delete from drafts are two transactions
    //handle the race by sleeping and trying again a few times
    boolean deletedFromSent = false;
    int tries = 0;
    while (!deletedFromSent && tries < 10) {
        deletedFromSent = TestUtil.search(mbox, "in:Drafts " + subject).isEmpty();
        if (!deletedFromSent) {
            Thread.sleep(500);
        }
        tries++;
    }
    Assert.assertTrue("message is still 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)

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