use of com.zimbra.common.calendar.TimeZoneMap in project zm-mailbox by Zimbra.
the class ToXML method encodeCalendarItemRecur.
public static void encodeCalendarItemRecur(Element parent, CalendarItem calItem) {
TimeZoneMap tzmap = calItem.getTimeZoneMap();
encodeTimeZoneMap(parent, tzmap);
Invite[] invites = calItem.getInvites();
for (Invite inv : invites) {
String elemName;
if (inv.isCancel()) {
elemName = MailConstants.E_CAL_CANCEL;
} else if (inv.hasRecurId()) {
elemName = MailConstants.E_CAL_EXCEPT;
} else {
elemName = MailConstants.E_INVITE_COMPONENT;
}
Element compElem = parent.addElement(elemName);
boolean allDay = inv.isAllDayEvent();
// RECURRENCE-ID
if (inv.hasRecurId())
encodeRecurId(compElem, inv.getRecurId(), allDay);
if (!inv.isCancel()) {
// DTSTART
ParsedDateTime dtStart = inv.getStartTime();
if (dtStart != null)
encodeDtStart(compElem, dtStart, allDay, false);
// DTEND or DURATION
ParsedDateTime dtEnd = inv.getEndTime();
if (dtEnd != null) {
encodeDtEnd(compElem, dtEnd, allDay, inv.isTodo(), false);
} else {
ParsedDuration dur = inv.getDuration();
if (dur != null)
dur.toXml(compElem);
}
// recurrence definition
IRecurrence recurrence = inv.getRecurrence();
if (recurrence != null) {
Element recurElem = compElem.addElement(MailConstants.E_CAL_RECUR);
recurrence.toXml(recurElem);
}
}
}
}
use of com.zimbra.common.calendar.TimeZoneMap in project zm-mailbox by Zimbra.
the class FreeBusy method parse.
/**
* Create a FreeBusy object from VFREEBUSY ZComponent.
* @param comp
* @return
* @throws ServiceException
*/
public static FreeBusy parse(ZComponent comp) throws ServiceException {
String name = null;
ParsedDateTime dtStart = null;
ParsedDateTime dtEnd = null;
List<Interval> intervals = new ArrayList<Interval>();
TimeZoneMap tzmap = new TimeZoneMap(ICalTimeZone.getUTC());
Iterator<ZProperty> propIter = comp.getPropertyIterator();
while (propIter.hasNext()) {
ZProperty prop = propIter.next();
ICalTok tok = prop.getToken();
if (tok == null)
continue;
switch(tok) {
case DTSTART:
try {
dtStart = ParsedDateTime.parse(prop, tzmap);
} catch (ParseException e) {
throw ServiceException.INVALID_REQUEST("bad DTSTART: " + prop.toString(), e);
}
break;
case DTEND:
try {
dtEnd = ParsedDateTime.parse(prop, tzmap);
} catch (ParseException e) {
throw ServiceException.INVALID_REQUEST("bad DTEND: " + prop.toString(), e);
}
break;
case ORGANIZER:
ZOrganizer att = new ZOrganizer(prop);
name = att.getAddress();
break;
case FREEBUSY:
String fbStatus = IcalXmlStrMap.FBTYPE_FREE;
ZParameter fbType = prop.getParameter(ICalTok.FBTYPE);
if (fbType != null)
fbStatus = IcalXmlStrMap.sFreeBusyMap.toXml(fbType.getValue());
List<String> vals = prop.getValueList();
for (String fbVal : vals) {
Period period;
try {
period = Period.parse(fbVal, ICalTimeZone.getUTC(), tzmap);
} catch (ParseException e) {
throw ServiceException.INVALID_REQUEST("bad period value: " + fbVal, e);
}
intervals.add(new Interval(period.getStart().getUtcTime(), period.getEnd().getUtcTime(), fbStatus));
}
break;
}
}
if (name == null)
throw ServiceException.INVALID_REQUEST("VFREEBUSY missing ORGANIZER", null);
if (dtStart == null || dtEnd == null)
throw ServiceException.INVALID_REQUEST("VFREEBUSY missing DTSTART/DTEND", null);
IntervalList ivalList = new IntervalList(dtStart.getUtcTime(), dtEnd.getUtcTime());
for (Interval ival : intervals) {
ivalList.addInterval(ival);
}
return new FreeBusy(name, ivalList, dtStart.getUtcTime(), dtEnd.getUtcTime());
}
use of com.zimbra.common.calendar.TimeZoneMap 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.TimeZoneMap in project zm-mailbox by Zimbra.
the class SetCalendarItem method deserializeData.
@Override
protected void deserializeData(RedoLogInput in) throws IOException {
mFolderId = in.readInt();
if (getVersion().atLeast(1, 0)) {
in.readShort();
}
mCalendarItemId = in.readInt();
if (getVersion().atLeast(1, 1)) {
mCalendarItemPartStat = in.readUTF();
}
if (getVersion().atLeast(1, 2)) {
mAttachmentIndexingEnabled = in.readBoolean();
} else {
mAttachmentIndexingEnabled = false;
}
if (getVersion().atLeast(1, 11)) {
mFlags = in.readInt();
if (getVersion().atLeast(1, 33)) {
mTags = in.readUTFArray();
} else {
mTagBitmask = in.readLong();
}
}
Invite tzmapInv = null;
boolean hasDefaultInvite = true;
if (getVersion().atLeast(1, 17)) {
hasDefaultInvite = in.readBoolean();
}
try {
if (hasDefaultInvite) {
mDefaultInvite = deserializeSetCalendarItemData(in, mAttachmentIndexingEnabled);
tzmapInv = mDefaultInvite.invite;
}
int numExceptions = in.readInt();
if (numExceptions > 0) {
mExceptions = new Mailbox.SetCalendarItemData[numExceptions];
for (int i = 0; i < numExceptions; i++) {
mExceptions[i] = deserializeSetCalendarItemData(in, mAttachmentIndexingEnabled);
if (tzmapInv == null) {
tzmapInv = mExceptions[i].invite;
}
}
}
} catch (MessagingException ex) {
ex.printStackTrace();
throw new IOException("Cannot read serialized entry for SetCalendarItem" + ex.toString());
}
if (getVersion().atLeast(1, 15)) {
int num = in.readInt();
if (num > 10000 && !getVersion().atLeast(1, 24)) {
// exception.
throw new IOException("Replies count > 10000. Looks like a corrupted pre-v1.24 redo entry. Skipping");
}
if (num < 0) {
// no replies list
mReplies = null;
} else {
mReplies = new ArrayList<ReplyInfo>(num);
TimeZoneMap tzMap = tzmapInv.getTimeZoneMap();
for (int i = 0; i < num; i++) {
String data = in.readUTF();
try {
Metadata md = new Metadata(data);
ReplyInfo reply = ReplyInfo.decodeFromMetadata(md, tzMap);
mReplies.add(reply);
} catch (ServiceException e) {
IOException ioe = new IOException("Cannot read serialized entry for ReplyInfo");
ioe.initCause(e);
throw ioe;
}
}
}
}
if (getVersion().atLeast(1, 21)) {
mNextAlarm = in.readLong();
}
}
use of com.zimbra.common.calendar.TimeZoneMap in project zm-mailbox by Zimbra.
the class ForwardCalendarItem method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Account senderAcct = getZDesktopSafeAuthenticatedAccount(zsc);
Mailbox mbox = getRequestedMailbox(zsc);
OperationContext octxt = getOperationContext(zsc, context);
// proxy handling
ItemId iid = new ItemId(request.getAttribute(MailConstants.A_ID), zsc);
if (!iid.belongsTo(getRequestedAccount(zsc))) {
// Proxy it.
return proxyRequest(request, context, iid.getAccountId());
}
Element msgElem = request.getElement(MailConstants.E_MSG);
ParseMimeMessage.MimeMessageData parsedMessageData = new ParseMimeMessage.MimeMessageData();
MimeMessage mm = ParseMimeMessage.parseMimeMsgSoap(zsc, octxt, mbox, msgElem, null, ParseMimeMessage.NO_INV_ALLOWED_PARSER, parsedMessageData);
Element exc = request.getOptionalElement(MailConstants.E_CAL_EXCEPTION_ID);
Element tzElem = request.getOptionalElement(MailConstants.E_CAL_TZ);
CalendarItem calItem = mbox.getCalendarItemById(octxt, iid.getId());
if (calItem == null) {
throw MailServiceException.NO_SUCH_CALITEM(iid.toString(), "Could not find calendar item");
}
RecurId rid = null;
if (exc != null) {
TimeZoneMap tzmap = calItem.getTimeZoneMap();
ICalTimeZone tz = null;
if (tzElem != null) {
tz = CalendarUtils.parseTzElement(tzElem);
tzmap.add(tz);
}
ParsedDateTime exceptDt = CalendarUtils.parseDateTime(exc, tzmap);
rid = new RecurId(exceptDt, RecurId.RANGE_NONE);
}
Pair<List<MimeMessage>, List<MimeMessage>> mimePair = forwardCalItem(mbox, octxt, calItem, rid, mm, senderAcct);
sendForwardMessages(mbox, octxt, mimePair);
Element response = getResponseElement(zsc);
return response;
}
Aggregations