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();
}
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");
}
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());
}
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()));
}
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);
}
Aggregations