use of com.zimbra.common.calendar.ZCalendar.ZComponent in project zm-mailbox by Zimbra.
the class CalendarRequest method notifyCalendarItem.
// Notify attendees following an update to the series of a recurring appointment. Only the
// added attendees are notified if notifyAllAttendees is false. If it is true all attendees
// for each invite are notified. (Some invites may have more attendees than others.)
protected static void notifyCalendarItem(ZimbraSoapContext zsc, OperationContext octxt, Account acct, Mailbox mbox, CalendarItem calItem, boolean notifyAllAttendees, List<ZAttendee> addedAttendees, boolean ignorePastExceptions, MailSendQueue sendQueue) throws ServiceException {
boolean onBehalfOf = isOnBehalfOfRequest(zsc);
Account authAcct = getAuthenticatedAccount(zsc);
boolean hidePrivate = !calItem.isPublic() && !calItem.allowPrivateAccess(authAcct, zsc.isUsingAdminPrivileges());
Address from = AccountUtil.getFriendlyEmailAddress(acct);
Address sender = null;
if (onBehalfOf)
sender = AccountUtil.getFriendlyEmailAddress(authAcct);
List<Address> addedRcpts = CalendarMailSender.toListFromAttendees(addedAttendees);
long now = octxt != null ? octxt.getTimestamp() : System.currentTimeMillis();
mbox.lock.lock();
try {
// Refresh the cal item so we see the latest blob, whose path may have been changed
// earlier in the current request.
calItem = mbox.getCalendarItemById(octxt, calItem.getId());
Invite[] invites = calItem.getInvites();
// Get exception instances. These will be included in the series update email.
List<Invite> exceptions = new ArrayList<Invite>();
for (Invite inv : invites) {
if (inv.hasRecurId()) {
exceptions.add(inv);
}
}
// Send the update invites.
boolean didExceptions = false;
for (Invite inv : invites) {
if (ignorePastExceptions && inv.hasRecurId() && !inviteIsAfterTime(inv, now)) {
continue;
}
// Make the new iCalendar part to send.
ZVCalendar cal = inv.newToICalendar(!hidePrivate);
// For series invite, append the exception instances.
if (inv.isRecurrence() && !didExceptions) {
// Find the VEVENT/VTODO for the series.
ZComponent seriesComp = null;
for (Iterator<ZComponent> compIter = cal.getComponentIterator(); compIter.hasNext(); ) {
ZComponent comp = compIter.next();
ICalTok compName = comp.getTok();
if (ICalTok.VEVENT.equals(compName) || ICalTok.VTODO.equals(compName)) {
if (comp.getProperty(ICalTok.RRULE) != null) {
seriesComp = comp;
break;
}
}
}
for (Invite except : exceptions) {
if (except.isCancel() && seriesComp != null) {
// Cancels are added as EXDATEs in the series VEVENT/VTODO.
RecurId rid = except.getRecurId();
if (rid != null && rid.getDt() != null) {
ZProperty exdate = rid.getDt().toProperty(ICalTok.EXDATE, false);
seriesComp.addProperty(exdate);
}
} else {
// Exception instances are added as additional VEVENTs/VTODOs.
ZComponent exceptComp = except.newToVComponent(false, !hidePrivate);
cal.addComponent(exceptComp);
}
}
didExceptions = true;
}
// Compose email using the existing MimeMessage as template and send it.
MimeMessage mmInv = calItem.getSubpartMessage(inv.getMailItemId());
List<Address> rcpts;
if (notifyAllAttendees) {
rcpts = CalendarMailSender.toListFromAttendees(inv.getAttendees());
} else {
rcpts = addedRcpts;
}
if (rcpts != null && !rcpts.isEmpty()) {
MimeMessage mmModify = CalendarMailSender.createCalendarMessage(authAcct, from, sender, rcpts, mmInv, inv, cal, true);
CalSendData csd = new CalSendData();
csd.mMm = mmModify;
csd.mOrigId = new ItemId(mbox, inv.getMailItemId());
MailSendQueueEntry entry = new MailSendQueueEntry(octxt, mbox, csd, null);
sendQueue.add(entry);
}
}
} finally {
mbox.lock.release();
}
}
use of com.zimbra.common.calendar.ZCalendar.ZComponent in project zm-mailbox by Zimbra.
the class Mailbox method writeICalendarForCalendarItems.
public void writeICalendarForCalendarItems(Writer writer, OperationContext octxt, Collection<CalendarItem> calItems, Folder f, boolean useOutlookCompatMode, boolean ignoreErrors, boolean needAppleICalHacks, boolean trimCalItemsList, boolean escapeHtmlTags, boolean includeAttaches) throws ServiceException {
lock.lock();
try {
writer.write("BEGIN:VCALENDAR\r\n");
if (f != null) {
writer.write("X-WR-CALNAME:");
writer.write(f.getName());
writer.write("\r\n");
writer.write("X-WR-CALID:");
writer.write(new ItemId(f).toString());
writer.write("\r\n");
}
ZProperty prop;
prop = new ZProperty(ICalTok.PRODID, ZCalendar.sZimbraProdID);
prop.toICalendar(writer, needAppleICalHacks);
prop = new ZProperty(ICalTok.VERSION, ZCalendar.sIcalVersion);
prop.toICalendar(writer, needAppleICalHacks);
prop = new ZProperty(ICalTok.METHOD, ICalTok.PUBLISH.toString());
prop.toICalendar(writer, needAppleICalHacks);
// timezones
ICalTimeZone localTz = Util.getAccountTimeZone(getAccount());
TimeZoneMap tzmap = new TimeZoneMap(localTz);
for (CalendarItem calItem : calItems) {
tzmap.add(calItem.getTimeZoneMap());
}
// iterate the tzmap and add all the VTimeZone's
for (Iterator<ICalTimeZone> iter = tzmap.tzIterator(); iter.hasNext(); ) {
ICalTimeZone tz = iter.next();
tz.newToVTimeZone().toICalendar(writer, needAppleICalHacks);
}
// help keep memory consumption low
tzmap = null;
// build all the event components and add them to the Calendar
for (Iterator<CalendarItem> iter = calItems.iterator(); iter.hasNext(); ) {
CalendarItem calItem = iter.next();
boolean allowPrivateAccess = calItem.isPublic() || calItem.allowPrivateAccess(octxt.getAuthenticatedUser(), octxt.isUsingAdminPrivileges());
if (trimCalItemsList) {
// help keep memory consumption low
iter.remove();
}
Invite[] invites = calItem.getInvites();
if (invites != null && invites.length > 0) {
boolean appleICalExdateHack = LC.calendar_apple_ical_compatible_canceled_instances.booleanValue();
ZComponent[] comps = null;
try {
comps = Invite.toVComponents(invites, allowPrivateAccess, useOutlookCompatMode, appleICalExdateHack, includeAttaches);
} catch (ServiceException e) {
if (ignoreErrors) {
ZimbraLog.calendar.warn("Error retrieving iCalendar data for item %s: %s", calItem.getId(), e.getMessage(), e);
} else {
throw e;
}
}
if (comps != null) {
for (ZComponent comp : comps) {
comp.toICalendar(writer, needAppleICalHacks, escapeHtmlTags);
}
}
}
}
writer.write("END:VCALENDAR\r\n");
} catch (IOException e) {
throw ServiceException.FAILURE("Error writing iCalendar", e);
} finally {
lock.release();
}
}
use of com.zimbra.common.calendar.ZCalendar.ZComponent in project zm-mailbox by Zimbra.
the class TestCalDav method testLondonTimeZoneCalledGMT.
@Test
public void testLondonTimeZoneCalledGMT() 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.KEEP_IF_DOESNT_CLASH);
assertEquals("ID that London Timezone originally with TZID=GMT maps to", "Europe/London", 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 simpleEvent.
public byte[] simpleEvent(Account organizer) 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, 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, "Simple Event"));
vevent.addProperty(new ZProperty(ICalTok.UID, "d1102-42a7-4283-b025-3376dabe53b3"));
vevent.addProperty(new ZProperty(ICalTok.STATUS, ICalTok.CONFIRMED.toString()));
vevent.addProperty(new ZProperty(ICalTok.SEQUENCE, "1"));
// vevent.addProperty(organizer(organizer));
vcal.addComponent(vevent);
return zvcalendarToBytes(vcal);
}
use of com.zimbra.common.calendar.ZCalendar.ZComponent in project zm-mailbox by Zimbra.
the class TestCalDav method testFuzzyTimeZoneMatchGMT_06.
@Test
public void testFuzzyTimeZoneMatchGMT_06() throws Exception {
try (ByteArrayInputStream bais = new ByteArrayInputStream(VtimeZoneGMT_0600_0500.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=06.00/-05.00", "America/Chicago", matchtz.getID());
}
}
Aggregations