use of com.zimbra.common.mime.shim.JavaMailMimeMessage in project zm-mailbox by Zimbra.
the class GetMsgTest method testMsgHeaderN.
@Test
public void testMsgHeaderN() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
MimeMessage message = new JavaMailMimeMessage(JMSession.getSession(), new ZSharedFileInputStream("data/unittest/email/bug_75163.txt"));
ParsedMessage pm = new ParsedMessage(message, false);
DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX);
Message msg = mbox.addMessage(null, pm, dopt, null);
Element request = new Element.XMLElement(MailConstants.GET_MSG_REQUEST);
Element action = request.addElement(MailConstants.E_MSG);
action.addAttribute(MailConstants.A_ID, msg.getId());
action.addElement(MailConstants.A_HEADER).addAttribute(MailConstants.A_ATTRIBUTE_NAME, "Return-Path");
Element response = new GetMsg().handle(request, ServiceTestUtil.getRequestContext(mbox.getAccount())).getElement(MailConstants.E_MSG);
List<Element> headerN = response.listElements(MailConstants.A_HEADER);
for (Element elt : headerN) {
Assert.assertEquals(elt.getText(), "foo@example.com");
}
}
use of com.zimbra.common.mime.shim.JavaMailMimeMessage in project zm-mailbox by Zimbra.
the class GetMsgTest method testMsgMaxAttr.
@Test
public void testMsgMaxAttr() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
MimeMessage message = new JavaMailMimeMessage(JMSession.getSession(), new ZSharedFileInputStream("data/TestMailRaw/1"));
ParsedMessage pm = new ParsedMessage(message, false);
DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX);
Message msg = mbox.addMessage(null, pm, dopt, null);
Element request = new Element.XMLElement(MailConstants.GET_MSG_REQUEST);
Element action = request.addElement(MailConstants.E_MSG);
action.addAttribute(MailConstants.A_ID, msg.getId());
action.addAttribute(MailConstants.A_MAX_INLINED_LENGTH, 10);
Element response = new GetMsg().handle(request, ServiceTestUtil.getRequestContext(mbox.getAccount())).getElement(MailConstants.E_MSG);
Assert.assertEquals(response.getElement(MailConstants.E_MIMEPART).getElement(MailConstants.E_CONTENT).getText().length(), 10);
}
use of com.zimbra.common.mime.shim.JavaMailMimeMessage in project zm-mailbox by Zimbra.
the class MetadataTest method legacyCalendarItem.
@Test
public void legacyCalendarItem() throws ServiceException, MessagingException {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
SetCalendarItemData defaultInv = new SetCalendarItemData();
MimeMessage message = new JavaMailMimeMessage(JMSession.getSession(), new ZSharedFileInputStream("data/TestMailRaw/invite1"));
defaultInv.message = new ParsedMessage(message, Calendar.getInstance().getTimeInMillis(), false);
TimeZoneMap tzMap = new TimeZoneMap(WellKnownTimeZones.getTimeZoneById("EST"));
Invite invite = new Invite("REQUEST", tzMap, false);
invite.setUid("test-uid");
Calendar cal = GregorianCalendar.getInstance();
cal.set(2005, 1, 21);
invite.setDtStart(ParsedDateTime.fromUTCTime(cal.getTimeInMillis()));
cal.set(2005, 2, 21);
invite.setDtEnd(ParsedDateTime.fromUTCTime(cal.getTimeInMillis()));
defaultInv.invite = invite;
CalendarItem calItem = mbox.setCalendarItem(null, Mailbox.ID_FOLDER_CALENDAR, 0, null, defaultInv, null, null, CalendarItem.NEXT_ALARM_KEEP_CURRENT);
calItem.mData.dateChanged = (int) (cal.getTimeInMillis() / 1000L);
Metadata meta = calItem.encodeMetadata();
meta.remove(Metadata.FN_TZMAP);
calItem.decodeMetadata(meta);
Assert.assertEquals(0, calItem.getStartTime());
Assert.assertEquals(0, calItem.getEndTime());
//simulate existence of FN_TZMAP with bad content. In reality the metadata versions 4, 5, 6 had more subtle differences in invite encoding, but this provokes the exception we need
meta.put(Metadata.FN_TZMAP, "foo");
calItem.decodeMetadata(meta);
Assert.assertEquals(0, calItem.getStartTime());
Assert.assertEquals(0, calItem.getEndTime());
cal.set(2007, 2, 21);
calItem.mData.dateChanged = (int) (cal.getTimeInMillis() / 1000L);
boolean caught = false;
try {
calItem.decodeMetadata(meta);
} catch (ServiceException se) {
if (se.getCode().equalsIgnoreCase(ServiceException.INVALID_REQUEST)) {
caught = true;
}
}
Assert.assertTrue("new(er) appointment with bad metadata", caught);
}
use of com.zimbra.common.mime.shim.JavaMailMimeMessage in project zm-mailbox by Zimbra.
the class GetMsgTest method testMsgView.
@Test
public void testMsgView() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
MimeMessage message = new JavaMailMimeMessage(JMSession.getSession(), new ZSharedFileInputStream("data/unittest/email/bug_75163.txt"));
ParsedMessage pm = new ParsedMessage(message, false);
DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX);
Message msg = mbox.addMessage(null, pm, dopt, null);
Element request = new Element.XMLElement(MailConstants.GET_MSG_REQUEST);
Element action = request.addElement(MailConstants.E_MSG);
action.addAttribute(MailConstants.A_ID, msg.getId());
Element response = new GetMsg().handle(request, ServiceTestUtil.getRequestContext(mbox.getAccount())).getElement(MailConstants.E_MSG);
List<Element> mimeParts = response.getElement(MailConstants.E_MIMEPART).listElements();
// test plain text view
for (Element elt : mimeParts) {
if (elt.getAttribute(MailConstants.A_BODY, null) != null) {
Assert.assertEquals(elt.getAttribute(MailConstants.A_CONTENT_TYPE), "text/plain");
break;
}
}
action.addAttribute(MailConstants.A_WANT_HTML, 1);
response = new GetMsg().handle(request, ServiceTestUtil.getRequestContext(mbox.getAccount())).getElement(MailConstants.E_MSG);
mimeParts = response.getElement(MailConstants.E_MIMEPART).listElements();
// test HTML view
for (Element elt : mimeParts) {
if (elt.getAttribute(MailConstants.A_BODY, null) != null) {
Assert.assertEquals(elt.getAttribute(MailConstants.A_CONTENT_TYPE), "text/html");
break;
}
}
}
Aggregations