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);
}
}
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;
}
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());
}
}
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;
}
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;
}
Aggregations