Search in sources :

Example 1 with JavaMailMimeMessage

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");
    }
}
Also used : ZSharedFileInputStream(com.zimbra.common.zmime.ZSharedFileInputStream) Mailbox(com.zimbra.cs.mailbox.Mailbox) MimeMessage(javax.mail.internet.MimeMessage) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) JavaMailMimeMessage(com.zimbra.common.mime.shim.JavaMailMimeMessage) MimeMessage(javax.mail.internet.MimeMessage) JavaMailMimeMessage(com.zimbra.common.mime.shim.JavaMailMimeMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) GetMsg(com.zimbra.cs.service.mail.GetMsg) Element(com.zimbra.common.soap.Element) JavaMailMimeMessage(com.zimbra.common.mime.shim.JavaMailMimeMessage) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Test(org.junit.Test)

Example 2 with JavaMailMimeMessage

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);
}
Also used : ZSharedFileInputStream(com.zimbra.common.zmime.ZSharedFileInputStream) Mailbox(com.zimbra.cs.mailbox.Mailbox) MimeMessage(javax.mail.internet.MimeMessage) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) JavaMailMimeMessage(com.zimbra.common.mime.shim.JavaMailMimeMessage) MimeMessage(javax.mail.internet.MimeMessage) JavaMailMimeMessage(com.zimbra.common.mime.shim.JavaMailMimeMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) GetMsg(com.zimbra.cs.service.mail.GetMsg) Element(com.zimbra.common.soap.Element) JavaMailMimeMessage(com.zimbra.common.mime.shim.JavaMailMimeMessage) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Test(org.junit.Test)

Example 3 with JavaMailMimeMessage

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);
}
Also used : ParsedMessage(com.zimbra.cs.mime.ParsedMessage) Calendar(com.ibm.icu.util.Calendar) GregorianCalendar(com.ibm.icu.util.GregorianCalendar) JavaMailMimeMessage(com.zimbra.common.mime.shim.JavaMailMimeMessage) SetCalendarItemData(com.zimbra.cs.mailbox.Mailbox.SetCalendarItemData) ZSharedFileInputStream(com.zimbra.common.zmime.ZSharedFileInputStream) ServiceException(com.zimbra.common.service.ServiceException) MimeMessage(javax.mail.internet.MimeMessage) JavaMailMimeMessage(com.zimbra.common.mime.shim.JavaMailMimeMessage) TimeZoneMap(com.zimbra.common.calendar.TimeZoneMap) Invite(com.zimbra.cs.mailbox.calendar.Invite) Test(org.junit.Test)

Example 4 with JavaMailMimeMessage

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;
        }
    }
}
Also used : ZSharedFileInputStream(com.zimbra.common.zmime.ZSharedFileInputStream) Mailbox(com.zimbra.cs.mailbox.Mailbox) MimeMessage(javax.mail.internet.MimeMessage) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) JavaMailMimeMessage(com.zimbra.common.mime.shim.JavaMailMimeMessage) MimeMessage(javax.mail.internet.MimeMessage) JavaMailMimeMessage(com.zimbra.common.mime.shim.JavaMailMimeMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) GetMsg(com.zimbra.cs.service.mail.GetMsg) Element(com.zimbra.common.soap.Element) JavaMailMimeMessage(com.zimbra.common.mime.shim.JavaMailMimeMessage) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Test(org.junit.Test)

Aggregations

JavaMailMimeMessage (com.zimbra.common.mime.shim.JavaMailMimeMessage)4 ZSharedFileInputStream (com.zimbra.common.zmime.ZSharedFileInputStream)4 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)4 MimeMessage (javax.mail.internet.MimeMessage)4 Test (org.junit.Test)4 Element (com.zimbra.common.soap.Element)3 DeliveryOptions (com.zimbra.cs.mailbox.DeliveryOptions)3 Mailbox (com.zimbra.cs.mailbox.Mailbox)3 Message (com.zimbra.cs.mailbox.Message)3 GetMsg (com.zimbra.cs.service.mail.GetMsg)3 Calendar (com.ibm.icu.util.Calendar)1 GregorianCalendar (com.ibm.icu.util.GregorianCalendar)1 TimeZoneMap (com.zimbra.common.calendar.TimeZoneMap)1 ServiceException (com.zimbra.common.service.ServiceException)1 SetCalendarItemData (com.zimbra.cs.mailbox.Mailbox.SetCalendarItemData)1 Invite (com.zimbra.cs.mailbox.calendar.Invite)1