Search in sources :

Example 36 with ZVCalendar

use of com.zimbra.common.calendar.ZCalendar.ZVCalendar in project zm-mailbox by Zimbra.

the class CalendarMailSender method createCalendarInviteDeniedMessage.

private static MimeMessage createCalendarInviteDeniedMessage(Account fromAccount, Account senderAccount, boolean onBehalfOf, boolean allowPrivateAccess, Address toAddr, Invite inv, MsgKey bodyTextKey) throws ServiceException {
    Locale locale = !onBehalfOf ? fromAccount.getLocale() : senderAccount.getLocale();
    Identity fromIdentity = getTargetedIdentity(fromAccount, inv);
    StringBuilder replyText = new StringBuilder();
    String sigText = getSignatureText(fromAccount, fromIdentity, Provisioning.A_zimbraPrefCalendarAutoDenySignatureId);
    if (sigText == null || sigText.length() < 1)
        sigText = L10nUtil.getMessage(bodyTextKey, locale);
    if (sigText != null && sigText.length() > 0)
        replyText.append(sigText).append("\r\n");
    attachInviteSummary(replyText, inv, null, locale);
    String subject = L10nUtil.getMessage(MsgKey.calendarReplySubjectDecline, locale) + ": " + inv.getName();
    String uid = inv.getUid();
    ParsedDateTime exceptDt = null;
    if (inv.hasRecurId())
        exceptDt = inv.getRecurId().getDt();
    Invite replyInv = replyToInvite(fromAccount, senderAccount, onBehalfOf, allowPrivateAccess, inv, VERB_DECLINE, subject, exceptDt);
    ZVCalendar iCal = replyInv.newToICalendar(true);
    Address fromAddr = fromIdentity.getFriendlyEmailAddress();
    Address senderAddr = null;
    if (onBehalfOf)
        senderAddr = AccountUtil.getFriendlyEmailAddress(senderAccount);
    List<Address> toAddrs = new ArrayList<Address>(1);
    toAddrs.add(toAddr);
    return createCalendarMessage(senderAccount, fromAddr, senderAddr, toAddrs, subject, replyText.toString(), null, uid, iCal);
}
Also used : Locale(java.util.Locale) ZVCalendar(com.zimbra.common.calendar.ZCalendar.ZVCalendar) Address(javax.mail.Address) InternetAddress(javax.mail.internet.InternetAddress) JavaMailInternetAddress(com.zimbra.common.mime.shim.JavaMailInternetAddress) ArrayList(java.util.ArrayList) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime) Identity(com.zimbra.cs.account.Identity)

Example 37 with ZVCalendar

use of com.zimbra.common.calendar.ZCalendar.ZVCalendar in project zm-mailbox by Zimbra.

the class CalendarMailSender method createCalendarMessage.

public static MimeMessage createCalendarMessage(Invite inv) throws ServiceException {
    String subject = inv.getName();
    String desc = inv.getDescription();
    String descHtml = inv.getDescriptionHtml();
    String uid = inv.getUid();
    ZVCalendar cal = inv.newToICalendar(true);
    return createCalendarMessage(null, null, null, null, subject, desc, descHtml, uid, cal, inv.getIcalendarAttaches(), true);
}
Also used : ZVCalendar(com.zimbra.common.calendar.ZCalendar.ZVCalendar)

Example 38 with ZVCalendar

use of com.zimbra.common.calendar.ZCalendar.ZVCalendar in project zm-mailbox by Zimbra.

the class TnefConverter method expandTNEF.

/**
     * Performs the TNEF->MIME conversion on any TNEF body parts that
     * make up the given message.
     * @throws ServiceException
     */
private MimeMultipart expandTNEF(MimeBodyPart bp) throws MessagingException, IOException {
    if (!TNEFUtils.isTNEFMimeType(bp.getContentType()))
        return null;
    MimeMessage converted = null;
    // convert TNEF to a MimeMessage and remove it from the parent
    InputStream is = null;
    try {
        TNEFInputStream tnefis = new TNEFInputStream(is = bp.getInputStream());
        converted = TNEFMime.convert(JMSession.getSession(), tnefis);
    // XXX bburtin: nasty hack.  Don't handle OOME since JTNEF can allocate a huge byte
    // array when the TNEF file is malformed.  See bug 42649.
    // } catch (OutOfMemoryError e) {
    //    Zimbra.halt("Ran out of memory while expanding TNEF attachment", e);
    } catch (Throwable t) {
        ZimbraLog.extensions.warn("Conversion failed.  TNEF attachment will not be expanded.", t);
        return null;
    } finally {
        ByteUtil.closeStream(is);
    }
    Object convertedContent = converted.getContent();
    if (!(convertedContent instanceof MimeMultipart)) {
        ZimbraLog.extensions.debug("TNEF attachment doesn't contain valid MimeMultiPart");
        return null;
    }
    MimeMultipart convertedMulti = (MimeMultipart) convertedContent;
    // make sure that all the attachments are marked as attachments
    for (int i = 0; i < convertedMulti.getCount(); i++) {
        BodyPart subpart = convertedMulti.getBodyPart(i);
        if (subpart.getHeader("Content-Disposition") == null)
            subpart.setHeader("Content-Disposition", Part.ATTACHMENT);
    }
    // Create a MimeBodyPart for the converted data.  Currently we're throwing
    // away the top-level message because its content shows up as blank after
    // the conversion.
    MimeBodyPart convertedPart = new ZMimeBodyPart();
    convertedPart.setContent(convertedMulti);
    // If the TNEF object contains calendar data, create an iCalendar version.
    MimeBodyPart icalPart = null;
    if (DebugConfig.enableTnefToICalendarConversion) {
        try {
            TnefToICalendar calConverter = new DefaultTnefToICalendar();
            ZCalendar.DefaultContentHandler icalHandler = new ZCalendar.DefaultContentHandler();
            if (calConverter.convert(mMimeMessage, bp.getInputStream(), icalHandler)) {
                if (icalHandler.getNumCals() > 0) {
                    List<ZVCalendar> cals = icalHandler.getCals();
                    Writer writer = new StringWriter(1024);
                    ICalTok method = null;
                    for (ZVCalendar cal : cals) {
                        cal.toICalendar(writer);
                        if (method == null)
                            method = cal.getMethod();
                    }
                    writer.close();
                    icalPart = new ZMimeBodyPart();
                    icalPart.setText(writer.toString());
                    ContentType ct = new ContentType(MimeConstants.CT_TEXT_CALENDAR);
                    ct.setCharset(MimeConstants.P_CHARSET_UTF8);
                    if (method != null)
                        ct.setParameter("method", method.toString());
                    icalPart.setHeader("Content-Type", ct.toString());
                }
            }
        } catch (ServiceException e) {
            throw new MessagingException("TNEF to iCalendar conversion failure: " + e.getMessage(), e);
        } catch (Throwable t) {
            //don't allow TNEF errors to crash server
            ZimbraLog.extensions.warn("Failed to convert TNEF to iCal", t);
            throw new MessagingException("TNEF to iCalendar conversion failure");
        }
    }
    // create a multipart/alternative for the TNEF and its MIME version
    MimeMultipart altMulti = new ZMimeMultipart("alternative");
    //        altMulti.addBodyPart(bp);
    altMulti.addBodyPart(convertedPart);
    if (icalPart != null)
        altMulti.addBodyPart(icalPart);
    return altMulti;
}
Also used : ZMimeBodyPart(com.zimbra.common.zmime.ZMimeBodyPart) MimeBodyPart(javax.mail.internet.MimeBodyPart) BodyPart(javax.mail.BodyPart) ContentType(com.zimbra.common.mime.ContentType) ZMimeBodyPart(com.zimbra.common.zmime.ZMimeBodyPart) MessagingException(javax.mail.MessagingException) TNEFInputStream(net.freeutils.tnef.TNEFInputStream) InputStream(java.io.InputStream) TNEFInputStream(net.freeutils.tnef.TNEFInputStream) DefaultTnefToICalendar(com.zimbra.cs.util.tnef.DefaultTnefToICalendar) ICalTok(com.zimbra.common.calendar.ZCalendar.ICalTok) ZCalendar(com.zimbra.common.calendar.ZCalendar) ZVCalendar(com.zimbra.common.calendar.ZCalendar.ZVCalendar) StringWriter(java.io.StringWriter) ServiceException(com.zimbra.common.service.ServiceException) MimeMessage(javax.mail.internet.MimeMessage) ZMimeMultipart(com.zimbra.common.zmime.ZMimeMultipart) MimeMultipart(javax.mail.internet.MimeMultipart) TnefToICalendar(com.zimbra.cs.util.tnef.TnefToICalendar) DefaultTnefToICalendar(com.zimbra.cs.util.tnef.DefaultTnefToICalendar) ZMimeMultipart(com.zimbra.common.zmime.ZMimeMultipart) ZMimeBodyPart(com.zimbra.common.zmime.ZMimeBodyPart) MimeBodyPart(javax.mail.internet.MimeBodyPart) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 39 with ZVCalendar

use of com.zimbra.common.calendar.ZCalendar.ZVCalendar in project zm-mailbox by Zimbra.

the class TestCalDav method testLondonTimeZoneCalledGMTkeepSameName.

@Test
public void testLondonTimeZoneCalledGMTkeepSameName() throws Exception {
    try (ByteArrayInputStream bais = new ByteArrayInputStream(LOTUS_NOTES_WITH_BAD_GMT_TZID.getBytes())) {
        ZVCalendar tzcal = ZCalendar.ZCalendarBuilder.build(bais, MimeConstants.P_CHARSET_UTF8);
        assertNotNull("tzcal", tzcal);
        ZComponent tzcomp = tzcal.getComponent(ICalTok.VTIMEZONE);
        assertNotNull("tzcomp", tzcomp);
        ICalTimeZone tz = ICalTimeZone.fromVTimeZone(tzcomp, false, /* skipLookup */
        ICalTimeZone.TZID_NAME_ASSIGNMENT_BEHAVIOR.ALWAYS_KEEP);
        assertEquals("ID that London Timezone originally with TZID=GMT maps to", "GMT", tz.getID());
        assertEquals("that London Timezone originally with TZID=GMT maps to this daylightTzname", "GMT/BST", tz.getDaylightTzname());
    }
}
Also used : ZComponent(com.zimbra.common.calendar.ZCalendar.ZComponent) ZVCalendar(com.zimbra.common.calendar.ZCalendar.ZVCalendar) ByteArrayInputStream(java.io.ByteArrayInputStream) ICalTimeZone(com.zimbra.common.calendar.ICalTimeZone) Test(org.junit.Test)

Example 40 with ZVCalendar

use of com.zimbra.common.calendar.ZCalendar.ZVCalendar in project zm-mailbox by Zimbra.

the class TestCalDav method testFuzzyTimeZoneMatchGMT_08.

@Test
public void testFuzzyTimeZoneMatchGMT_08() throws Exception {
    try (ByteArrayInputStream bais = new ByteArrayInputStream(VtimeZoneGMT_0800_0700.getBytes())) {
        ZVCalendar tzcal = ZCalendar.ZCalendarBuilder.build(bais, MimeConstants.P_CHARSET_UTF8);
        assertNotNull("tzcal", tzcal);
        ZComponent tzcomp = tzcal.getComponent(ICalTok.VTIMEZONE);
        assertNotNull("tzcomp", tzcomp);
        ICalTimeZone tz = ICalTimeZone.fromVTimeZone(tzcomp, false, /* skipLookup */
        ICalTimeZone.TZID_NAME_ASSIGNMENT_BEHAVIOR.ALWAYS_KEEP);
        ICalTimeZone matchtz = ICalTimeZone.lookupMatchingWellKnownTZ(tz);
        assertEquals("ID of Timezone which fuzzy matches GMT=08.00/-07.00", "America/Los_Angeles", matchtz.getID());
    }
}
Also used : ZComponent(com.zimbra.common.calendar.ZCalendar.ZComponent) ZVCalendar(com.zimbra.common.calendar.ZCalendar.ZVCalendar) ByteArrayInputStream(java.io.ByteArrayInputStream) ICalTimeZone(com.zimbra.common.calendar.ICalTimeZone) Test(org.junit.Test)

Aggregations

ZVCalendar (com.zimbra.common.calendar.ZCalendar.ZVCalendar)47 Invite (com.zimbra.cs.mailbox.calendar.Invite)21 ZComponent (com.zimbra.common.calendar.ZCalendar.ZComponent)16 Account (com.zimbra.cs.account.Account)12 ICalTimeZone (com.zimbra.common.calendar.ICalTimeZone)10 ZProperty (com.zimbra.common.calendar.ZCalendar.ZProperty)10 IOException (java.io.IOException)10 MimeMessage (javax.mail.internet.MimeMessage)10 ParsedDateTime (com.zimbra.common.calendar.ParsedDateTime)9 ItemId (com.zimbra.cs.service.util.ItemId)9 TimeZoneMap (com.zimbra.common.calendar.TimeZoneMap)8 InputStream (java.io.InputStream)8 ArrayList (java.util.ArrayList)8 ServiceException (com.zimbra.common.service.ServiceException)7 Mailbox (com.zimbra.cs.mailbox.Mailbox)7 ByteArrayInputStream (java.io.ByteArrayInputStream)7 Locale (java.util.Locale)7 Test (org.junit.Test)7 Element (com.zimbra.common.soap.Element)6 Date (java.util.Date)6