use of com.zimbra.client.ZMailbox.ZOutgoingMessage 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.ZMailbox.ZOutgoingMessage 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());
}
use of com.zimbra.client.ZMailbox.ZOutgoingMessage 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.ZMailbox.ZOutgoingMessage in project zm-mailbox by Zimbra.
the class TestSearchConv method setupConversation.
private static void setupConversation() throws Exception {
ZOutgoingMessage msg;
ZOutgoingMessage reply;
msg = TestUtil.getOutgoingMessage(REMOTE_USER_NAME, subject, "far over the misty mountains cold", null);
ZSendMessageResponse resp = mbox.sendMessage(msg, null, false);
TestUtil.waitForMessage(remote_mbox, "in:inbox misty");
String remoteMsgId = TestUtil.getMessage(remote_mbox, subject).getId();
reply = TestUtil.getOutgoingMessage(USER_NAME, subject, "to dungeons deep and caverns old", null);
reply.setOriginalMessageId(remoteMsgId);
reply.setReplyType("r");
remote_mbox.sendMessage(reply, null, false);
TestUtil.waitForMessage(mbox, "in:inbox dungeons");
reply = TestUtil.getOutgoingMessage(USER_NAME, subject, "we must away ere break of day", null);
reply.setOriginalMessageId(remoteMsgId);
reply.setReplyType("r");
remote_mbox.sendMessage(reply, null, false);
TestUtil.waitForMessage(mbox, "in:inbox must");
reply = TestUtil.getOutgoingMessage(USER_NAME, subject, "to seek the pale enchanted gold", null);
reply.setOriginalMessageId(remoteMsgId);
reply.setReplyType("r");
remote_mbox.sendMessage(reply, null, false);
TestUtil.waitForMessage(mbox, "in:inbox enchanted");
convId = mbox.getMessageById(resp.getId()).getConversationId();
}
use of com.zimbra.client.ZMailbox.ZOutgoingMessage in project zm-mailbox by Zimbra.
the class TestSearchTask method init.
@BeforeClass
public static void init() throws ServiceException {
TestUtil.deleteAccountIfExists(USER_NAME);
TestUtil.createAccount(USER_NAME);
mbox = TestUtil.getZMailbox(USER_NAME);
for (int i = 0; i < numTasks; i++) {
ZOutgoingMessage msg = TestUtil.getOutgoingMessage(USER_NAME, null, String.format("task body %d", i), null);
ZInvite inv = new ZInvite();
ZInvite.ZComponent comp = new ZComponent();
comp.setIsAllDay(true);
comp.setStatus(ZStatus.NEED);
comp.setLocation("mount erebor");
comp.setPercentCompleted("0");
comp.setPriority("0");
comp.setName(String.format("destroy the one ring %d", i));
comp.setOrganizer(new ZOrganizer(mbox.getName()));
inv.getComponents().add(comp);
ZAppointmentResult resp = mbox.createTask("15", null, msg, inv, null);
ids.add(resp.getInviteId());
}
}
Aggregations