Search in sources :

Example 1 with ZSharedFileInputStream

use of com.zimbra.common.zmime.ZSharedFileInputStream 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 ZSharedFileInputStream

use of com.zimbra.common.zmime.ZSharedFileInputStream 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 ZSharedFileInputStream

use of com.zimbra.common.zmime.ZSharedFileInputStream in project zm-mailbox by Zimbra.

the class RemoveAttachments method main.

public static void main(String[] args) throws ServiceException {
    System.out.println(sortPartIds("1"));
    System.out.println(sortPartIds("1,2,3"));
    System.out.println(sortPartIds("1,1,2,1"));
    System.out.println(sortPartIds("1.1,TEXT,1.TEXT,10,2.1"));
    InputStream is = null;
    try {
        java.io.File file = new java.io.File(args[0]);
        MimeMessage mm = new Mime.FixedMimeMessage(JMSession.getSession(), is = new ZSharedFileInputStream(file));
        stripPart(mm, "1.2");
        mm.saveChanges();
        mm.writeTo(System.out);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        ByteUtil.closeStream(is);
    }
}
Also used : ZSharedFileInputStream(com.zimbra.common.zmime.ZSharedFileInputStream) MimeMessage(javax.mail.internet.MimeMessage) ZSharedFileInputStream(com.zimbra.common.zmime.ZSharedFileInputStream) InputStream(java.io.InputStream) MessagingException(javax.mail.MessagingException) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException)

Example 4 with ZSharedFileInputStream

use of com.zimbra.common.zmime.ZSharedFileInputStream 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 5 with ZSharedFileInputStream

use of com.zimbra.common.zmime.ZSharedFileInputStream 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

ZSharedFileInputStream (com.zimbra.common.zmime.ZSharedFileInputStream)9 MimeMessage (javax.mail.internet.MimeMessage)8 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)5 IOException (java.io.IOException)5 MessagingException (javax.mail.MessagingException)5 JavaMailMimeMessage (com.zimbra.common.mime.shim.JavaMailMimeMessage)4 InputStream (java.io.InputStream)4 Test (org.junit.Test)4 ServiceException (com.zimbra.common.service.ServiceException)3 Element (com.zimbra.common.soap.Element)3 ZMimeMessage (com.zimbra.common.zmime.ZMimeMessage)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 File (java.io.File)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 InternetAddress (javax.mail.internet.InternetAddress)2