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 Alarm method toZComponent.
public ZComponent toZComponent() throws ServiceException {
ZComponent comp = new ZComponent(ICalTok.VALARM);
ZProperty action = new ZProperty(ICalTok.ACTION, mAction.toString());
comp.addProperty(action);
ZProperty trigger = new ZProperty(ICalTok.TRIGGER);
if (TriggerType.ABSOLUTE.equals(mTriggerType)) {
ZParameter vt = new ZParameter(ICalTok.VALUE, ICalTok.DATE_TIME.toString());
trigger.addParameter(vt);
trigger.setValue(mTriggerAbsolute.getDateTimePartString(false));
} else {
if (mTriggerRelated != null) {
ZParameter related = new ZParameter(ICalTok.RELATED, mTriggerRelated.toString());
trigger.addParameter(related);
}
trigger.setValue(mTriggerRelative.toString());
}
comp.addProperty(trigger);
if (mRepeatDuration != null) {
ZProperty duration = new ZProperty(ICalTok.DURATION, mRepeatDuration.toString());
comp.addProperty(duration);
ZProperty repeat = new ZProperty(ICalTok.REPEAT, mRepeatCount);
comp.addProperty(repeat);
}
if (!Action.AUDIO.equals(mAction)) {
String d = mDescription;
// DESCRIPTION is required in DISPLAY and EMAIL alarms.
if (d == null && !Action.PROCEDURE.equals(mAction))
d = "Reminder";
ZProperty desc = new ZProperty(ICalTok.DESCRIPTION, d);
comp.addProperty(desc);
}
if (mAttach != null)
comp.addProperty(mAttach.toZProperty());
if (Action.EMAIL.equals(mAction) || Action.X_YAHOO_CALENDAR_ACTION_IM.equals(mAction) || Action.X_YAHOO_CALENDAR_ACTION_MOBILE.equals(mAction)) {
String s = mSummary;
if (s == null)
s = "Reminder";
ZProperty summary = new ZProperty(ICalTok.SUMMARY, s);
comp.addProperty(summary);
// if somehow the object didn't have any attendee.
if (mAttendees != null) {
for (ZAttendee attendee : mAttendees) {
comp.addProperty(attendee.toProperty());
}
}
}
// x-prop
for (ZProperty xprop : xProps) {
comp.addProperty(xprop);
}
return comp;
}
use of com.zimbra.common.calendar.ZCalendar.ZComponent in project zm-mailbox by Zimbra.
the class TextCalendarHandler method analyze.
private void analyze(boolean needCal) throws MimeHandlerException {
if (mContent != null)
return;
DataSource source = getDataSource();
if (source == null) {
mContent = "";
return;
}
InputStream is = null;
try {
is = source.getInputStream();
String charset = MimeConstants.P_CHARSET_UTF8;
String ctStr = source.getContentType();
if (ctStr != null) {
String cs = Mime.getCharset(ctStr);
if (cs != null)
charset = cs;
}
if (needCal) {
miCalendar = ZCalendarBuilder.build(is, charset);
StringBuilder buf = new StringBuilder(1024);
int maxLength = MimeHandlerManager.getIndexedTextLimit();
for (Iterator<ZComponent> compIter = miCalendar.getComponentIterator(); compIter.hasNext() && buf.length() < maxLength; ) {
ZComponent comp = compIter.next();
for (Iterator<ZProperty> propIter = comp.getPropertyIterator(); propIter.hasNext(); ) {
ZProperty prop = propIter.next();
if (sIndexedProps.contains(prop.getName())) {
String value = prop.getValue();
if (value != null && value.length() > 0) {
if (buf.length() > 0)
buf.append(' ');
buf.append(value);
}
}
}
}
mContent = buf.toString();
} else {
IcsParseHandler handler = new IcsParseHandler();
ZCalendarBuilder.parse(is, charset, handler);
mContent = handler.getContent();
}
} catch (Exception e) {
mContent = "";
ZimbraLog.index.warn("error reading text/calendar mime part", e);
throw new MimeHandlerException(e);
} finally {
ByteUtil.closeStream(is);
}
}
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 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());
}
}
Aggregations