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