Search in sources :

Example 36 with ZComponent

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

the class ForwardCalendarItem method getSeriesFwdMsgs.

private static Pair<List<MimeMessage>, List<MimeMessage>> getSeriesFwdMsgs(OperationContext octxt, Account senderAcct, CalendarItem calItem, MimeMessage mmFwdWrapper) throws ServiceException {
    // Get plain and html texts entered by the forwarder.
    DescDetectVisitor visitor = new DescDetectVisitor();
    try {
        visitor.accept(mmFwdWrapper);
    } catch (MessagingException e) {
        throw ServiceException.FAILURE("Messaging Exception while retrieving description text", e);
    }
    MimeBodyPart plainDescPart = visitor.getPlainDescPart();
    MimeBodyPart htmlDescPart = visitor.getHtmlDescPart();
    try {
        List<MimeMessage> msgs = new ArrayList<MimeMessage>();
        List<MimeMessage> notifyMsgs = new ArrayList<MimeMessage>();
        long now = octxt != null ? octxt.getTimestamp() : System.currentTimeMillis();
        Invite[] invites = calItem.getInvites();
        // Get canceled instances in the future.  These will be included in the series part.
        List<Invite> cancels = new ArrayList<Invite>();
        for (Invite inv : invites) {
            if (inv.isCancel() && inv.hasRecurId() && inviteIsAfterTime(inv, now))
                cancels.add(inv);
        }
        // Make sure the series invite is the first one in the list.
        LinkedList<Invite> invOrderedList = new LinkedList<Invite>();
        for (Invite inv : invites) {
            // Ignore exceptions in the past.
            if (inv.hasRecurId() && !inviteIsAfterTime(inv, now))
                continue;
            if (!inv.isCancel()) {
                if (inv.isRecurrence())
                    invOrderedList.addFirst(inv);
                else
                    invOrderedList.addLast(inv);
            }
        }
        boolean didCancels = false;
        boolean firstInv = true;
        for (Invite inv : invOrderedList) {
            // Make the new iCalendar part.
            ZVCalendar cal = inv.newToICalendar(true);
            // For series invite, append the canceled instances.
            if (inv.isRecurrence() && !didCancels) {
                didCancels = true;
                for (Invite cancel : cancels) {
                    ZComponent cancelComp = cancel.newToVComponent(true, true);
                    cal.addComponent(cancelComp);
                }
            }
            MimeMessage mmInv = calItem.getSubpartMessage(inv.getMailItemId());
            Pair<MimeMessage, MimeMessage> fwdMsgPair = makeFwdMsg(senderAcct, inv, mmInv, cal, mmFwdWrapper, plainDescPart, htmlDescPart, firstInv);
            if (fwdMsgPair.getFirst() != null) {
                msgs.add(fwdMsgPair.getFirst());
            }
            if (fwdMsgPair.getSecond() != null) {
                notifyMsgs.add(fwdMsgPair.getSecond());
            }
            firstInv = false;
        }
        return new Pair<List<MimeMessage>, List<MimeMessage>>(msgs, notifyMsgs);
    } catch (IOException e) {
        throw ServiceException.FAILURE("error creating forward message", e);
    } catch (MessagingException e) {
        throw ServiceException.FAILURE("error creating forward message", e);
    }
}
Also used : MessagingException(javax.mail.MessagingException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) LinkedList(java.util.LinkedList) ZComponent(com.zimbra.common.calendar.ZCalendar.ZComponent) ZVCalendar(com.zimbra.common.calendar.ZCalendar.ZVCalendar) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) MimeMessage(javax.mail.internet.MimeMessage) ZMimeBodyPart(com.zimbra.common.zmime.ZMimeBodyPart) MimeBodyPart(javax.mail.internet.MimeBodyPart) Invite(com.zimbra.cs.mailbox.calendar.Invite) Pair(com.zimbra.common.util.Pair)

Example 37 with ZComponent

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

the class TestCalDav method exampleCancelIcal.

public String exampleCancelIcal(Account organizer, Account attendee1, Account attendee2) throws IOException {
    ZVCalendar vcal = new ZVCalendar();
    vcal.addVersionAndProdId();
    vcal.addProperty(new ZProperty(ICalTok.METHOD, ICalTok.CANCEL.toString()));
    ICalTimeZone tz = ICalTimeZone.lookupByTZID("Africa/Harare");
    vcal.addComponent(tz.newToVTimeZone());
    ZComponent vevent = new ZComponent(ICalTok.VEVENT);
    ParsedDateTime dtstart = parsedDateTime(2020, java.util.Calendar.APRIL, 1, 9, 0, tz);
    vevent.addProperty(dtstart.toProperty(ICalTok.DTSTART, false));
    ParsedDateTime dtend = parsedDateTime(2020, java.util.Calendar.APRIL, 1, 13, 0, tz);
    vevent.addProperty(dtend.toProperty(ICalTok.DTEND, false));
    vevent.addProperty(new ZProperty(ICalTok.DTSTAMP, "20140108T224700Z"));
    vevent.addProperty(new ZProperty(ICalTok.SUMMARY, "Meeting for fun"));
    vevent.addProperty(new ZProperty(ICalTok.UID, "d123f102-42a7-4283-b025-3376dabe53b3"));
    vevent.addProperty(new ZProperty(ICalTok.STATUS, ICalTok.CANCELLED.toString()));
    vevent.addProperty(new ZProperty(ICalTok.SEQUENCE, "1"));
    vevent.addProperty(organizer(organizer));
    vevent.addProperty(attendee(attendee1, ICalTok.REQ_PARTICIPANT, ICalTok.INDIVIDUAL, ICalTok.NEEDS_ACTION));
    vevent.addProperty(attendee(attendee2, ICalTok.REQ_PARTICIPANT, ICalTok.INDIVIDUAL, ICalTok.NEEDS_ACTION));
    vcal.addComponent(vevent);
    StringWriter calWriter = new StringWriter();
    vcal.toICalendar(calWriter);
    String icalString = calWriter.toString();
    IOUtils.closeQuietly(calWriter);
    return icalString;
}
Also used : ZComponent(com.zimbra.common.calendar.ZCalendar.ZComponent) ZVCalendar(com.zimbra.common.calendar.ZCalendar.ZVCalendar) StringWriter(java.io.StringWriter) ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime) ICalTimeZone(com.zimbra.common.calendar.ICalTimeZone)

Example 38 with ZComponent

use of com.zimbra.common.calendar.ZCalendar.ZComponent 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 39 with ZComponent

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

the class TestCalDav method makeFreeBusyRequestIcal.

public String makeFreeBusyRequestIcal(Account organizer, List<Account> attendees, Date start, Date end) throws IOException {
    ZVCalendar vcal = new ZVCalendar();
    vcal.addVersionAndProdId();
    vcal.addProperty(new ZProperty(ICalTok.METHOD, ICalTok.REQUEST.toString()));
    ZComponent vfreebusy = new ZComponent(ICalTok.VFREEBUSY);
    ParsedDateTime dtstart = ParsedDateTime.fromUTCTime(start.getTime());
    vfreebusy.addProperty(dtstart.toProperty(ICalTok.DTSTART, false));
    ParsedDateTime dtend = ParsedDateTime.fromUTCTime(end.getTime());
    vfreebusy.addProperty(dtend.toProperty(ICalTok.DTEND, false));
    vfreebusy.addProperty(new ZProperty(ICalTok.DTSTAMP, "20140108T224700Z"));
    vfreebusy.addProperty(new ZProperty(ICalTok.UID, "d123f102-42a7-4283-b025-3376dabe53b3"));
    vfreebusy.addProperty(organizer(organizer));
    for (Account attendee : attendees) {
        vfreebusy.addProperty(new ZProperty(ICalTok.ATTENDEE, "mailto:" + attendee.getName()));
    }
    vcal.addComponent(vfreebusy);
    StringWriter calWriter = new StringWriter();
    vcal.toICalendar(calWriter);
    String icalString = calWriter.toString();
    IOUtils.closeQuietly(calWriter);
    return icalString;
}
Also used : ZComponent(com.zimbra.common.calendar.ZCalendar.ZComponent) Account(com.zimbra.cs.account.Account) ZVCalendar(com.zimbra.common.calendar.ZCalendar.ZVCalendar) StringWriter(java.io.StringWriter) ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime)

Example 40 with ZComponent

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

the class TestCalDav method simpleMeeting.

public ZVCalendar simpleMeeting(Account organizer, List<MailTarget> attendees, String uid, String seq, int startHour) throws IOException {
    ZVCalendar vcal = new ZVCalendar();
    vcal.addVersionAndProdId();
    vcal.addProperty(new ZProperty(ICalTok.METHOD, ICalTok.PUBLISH.toString()));
    ICalTimeZone tz = ICalTimeZone.lookupByTZID("Africa/Harare");
    vcal.addComponent(tz.newToVTimeZone());
    ZComponent vevent = new ZComponent(ICalTok.VEVENT);
    ParsedDateTime dtstart = parsedDateTime(2020, java.util.Calendar.APRIL, 1, startHour, 0, tz);
    vevent.addProperty(dtstart.toProperty(ICalTok.DTSTART, false));
    ParsedDateTime dtend = parsedDateTime(2020, java.util.Calendar.APRIL, 1, startHour + 4, 0, tz);
    vevent.addProperty(dtend.toProperty(ICalTok.DTEND, false));
    vevent.addProperty(new ZProperty(ICalTok.DTSTAMP, "20150108T224700Z"));
    vevent.addProperty(new ZProperty(ICalTok.SUMMARY, "Simple Meeting"));
    vevent.addProperty(new ZProperty(ICalTok.UID, uid));
    vevent.addProperty(new ZProperty(ICalTok.STATUS, ICalTok.CONFIRMED.toString()));
    vevent.addProperty(new ZProperty(ICalTok.SEQUENCE, seq));
    vevent.addProperty(organizer(organizer));
    for (MailTarget att : attendees) {
        if (att.getId().equals(organizer.getId())) {
            vevent.addProperty(attendee(att, ICalTok.REQ_PARTICIPANT, ICalTok.INDIVIDUAL, ICalTok.ACCEPTED));
        } else {
            vevent.addProperty(attendee(att, ICalTok.REQ_PARTICIPANT, ICalTok.INDIVIDUAL, ICalTok.NEEDS_ACTION));
        }
    }
    vcal.addComponent(vevent);
    return vcal;
}
Also used : ZComponent(com.zimbra.common.calendar.ZCalendar.ZComponent) ZVCalendar(com.zimbra.common.calendar.ZCalendar.ZVCalendar) ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime) MailTarget(com.zimbra.cs.account.MailTarget) ICalTimeZone(com.zimbra.common.calendar.ICalTimeZone)

Aggregations

ZComponent (com.zimbra.common.calendar.ZCalendar.ZComponent)41 ZProperty (com.zimbra.common.calendar.ZCalendar.ZProperty)22 ZVCalendar (com.zimbra.common.calendar.ZCalendar.ZVCalendar)19 ICalTimeZone (com.zimbra.common.calendar.ICalTimeZone)16 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)10 ICalTok (com.zimbra.common.calendar.ZCalendar.ICalTok)9 ZParameter (com.zimbra.common.calendar.ZCalendar.ZParameter)8 ParsedDateTime (com.zimbra.common.calendar.ParsedDateTime)7 Account (com.zimbra.cs.account.Account)7 Invite (com.zimbra.cs.mailbox.calendar.Invite)7 ByteArrayInputStream (java.io.ByteArrayInputStream)7 IOException (java.io.IOException)7 InputStream (java.io.InputStream)7 TimeZoneMap (com.zimbra.common.calendar.TimeZoneMap)5 ServiceException (com.zimbra.common.service.ServiceException)4 MessagingException (javax.mail.MessagingException)4 MimeMessage (javax.mail.internet.MimeMessage)4 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)3 CalendarPartInfo (com.zimbra.cs.mime.ParsedMessage.CalendarPartInfo)3